Re: [sqlalchemy] short question on Table

2011-04-16 Thread Michael Trier
>
>
> Does anyone know how I can add a Column to an existing not yet mapped
> Table?
>
> To add a column use append_column:

http://www.sqlalchemy.org/docs/core/schema.html#sqlalchemy.schema.Table.append_column


Note that doesn't do anything database schema wise for you.
-- 
Michael Trier
http://michaeltrier.com/

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Facing problem with aliasing while using union_all

2011-04-16 Thread Michael Bayer

On Apr 16, 2011, at 3:57 AM, monster jacker wrote:

> query.union_all(query1, query2) is producing below select statement.As
> i added label method to change labels of columns to refer in the code.
> anonimous column names are giving reference errors while accesing
> result set.
> 
> SELECT
>   anon_1.anon_2_row_num AS anon_1_anon_2_row_num,
> anon_1.anon_2_test_msg AS anon_1_anon_2_test_msg,
> anon_1.anon_2_date_created AS anon_1_anon_2_date_created,
> anon_1.anon_2_name_file AS anon_1_anon_2_name_file
> 
> 
> Here we  don't want to have top level select column name with alias
> since i am refering in the code as row_num.
> 
> Can any one suggest what changes to be made in the query.

I'm assuming by "reference error" you're trying to say:

for row in query:
row.row_num

this exact issue is resolved in 0.7 and is introduced at 
http://www.sqlalchemy.org/trac/wiki/07Migration#TuplelabelnamesinQueryImproved 
.   The actual query will still have the "anon" stuff going on, since it 
generates subqueries with names like "anon_1" and "anon_2" and then always uses 
the convention _ in order to identify columns, but 
the original name should be transferred up to the top.






-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Avoiding spaghetti inheritance

2011-04-16 Thread Michael Bayer

On Apr 7, 2011, at 4:36 PM, Luca Lesinigo wrote:

> Hello there. I'm using SA-0.7 to develop an application that should
> help me manage my company's services.
> 
> A central concept here is the order, it could be a service (like one
> year of web hosting) or a physical item (like a pc we sell). So far I
> generalized them in two classes: the Order and the ServiceOrder - the
> latter simply inherits the former and adds start and end dates.
> 
> Now I need to add all various kinds of metadata to orders, for
> example:
> - a ServiceOrder for a domain hosting should contain the domain name
> - a ServiceOrder for a maintenance service should contain the service
> level for that service (say, basic or advanced)
> - an Order for a PC we delivered should contain its serial number
> - and so on...
> 
> I could easily add child classes, but that would mean to keep and
> maintain that code forever even after we stop using it (ie, next year
> we stop doing hosting) or when it's not really useful (many things
> will just have some 'metadata' in them like a serial number or similar
> things). I'd also like to avoid having to add code every time we just
> hit something slightly different to manage, when we just have some
> additional data to keep track of.
> I wonder what could be an intelligent approach to such a situation.

why not separate the product from the fact of its being ordered ?  compose 
Order->Product instead of inherit.

As far as variable attributes which you only need to retrieve, never to query 
on, there are many recipes for a "bag" of attributes.By far the easiest is 
a recipe like JSON type: 
http://www.sqlalchemy.org/docs/core/types.html#marshal-json-strings

More broken out are key/value tables, this is more like your ordertags idea.   
recipes: 
http://www.sqlalchemy.org/docs/orm/examples.html#vertical-attribute-mapping  
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/VersionedMap

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Facing problem with aliasing while using union_all

2011-04-16 Thread monster jacker
Hi all,
  I am facing the problem with aliasing when i try to do union of
SA queries.

Following three SA queries
--

query = self.session.query(Table1.row_num.label('row_num'),
   Table.test_msg.label('test_msg'),
 
Table.date_created.label('date_created'),
 
Table2.name_file.label('name_file')).join(
(Table2, Table2.some_idn == Table.some_idn))

query1 = self.session.query(Table3.row_num.label('row_num'),
   Table.test_msg.label('test_msg'),
 
Table.date_created.label('date_created'),
 
Table2.name_file.label('name_file')).join(
(Table2, Table2.some_idn == Table.some_idn))
query2 = self.session.query(Table4.row_num.label('row_num'),
   Table.test_msg.label('test_msg'),
 
Table.date_created.label('date_created'),
 
Table2.name_file.label('name_file')).join(
(Table2, Table2.some_idn == Table.some_idn))


We got the following sql statements for above three queries.
--

SELECT dbo.table1.row_num AS row_num, dbo.table1.test_msg AS test_msg,
dbo.table1.date_created AS date_created, table2.name_file AS
name_file
FROM dbo.table1 JOIN table2 ON table2.some_idn = dbo.table1.some_idn
WHERE table2.some_idn = :some_idn_1 AND dbo.table1.date_created
BETWEEN :date_created_1 AND :date_created_2


SELECT dbo.table3.row_num AS row_num, dbo.table3.test_msg AS test_msg,
dbo.table3.date_created AS date_created, table2.name_file AS
name_file
FROM dbo.table3 JOIN table2 ON table2.some_idn = dbo.table3.some_idn
WHERE table2.some_idn = :some_idn_2 AND dbo.table3.date_created
BETWEEN :date_created_3 AND :date_created_4


SELECT dbo.table4.row_num AS row_num, dbo.table4.test_msg AS test_msg,
dbo.table4.date_created AS date_created, table2.name_file AS
name_file
FROM dbo.table4 JOIN table2 ON table2.some_idn = dbo.table4.some_idn
WHERE table2.some_idn = :some_idn_3 AND dbo.table4.date_created
BETWEEN :date_created_5 AND :date_created_6

when i do the union(used union_all) of all the above three queries
---

query.union_all(query1, query2) is producing below select statement.As
i added label method to change labels of columns to refer in the code.
anonimous column names are giving reference errors while accesing
result set.

SELECT
anon_1.anon_2_row_num AS anon_1_anon_2_row_num,
anon_1.anon_2_test_msg AS anon_1_anon_2_test_msg,
anon_1.anon_2_date_created AS anon_1_anon_2_date_created,
anon_1.anon_2_name_file AS anon_1_anon_2_name_file
FROM
(SELECT anon_2.row_num AS anon_2_row_num, anon_2.test_msg AS
anon_2_test_msg, anon_2.date_created AS anon_2_date_created,
anon_2.name_file AS anon_2_name_file
FROM
(SELECT dbo.table1.row_num AS row_num, dbo.table1.test_msg AS
test_msg, dbo.table1.date_created AS date_created,  
table2.name_file
AS name_file
FROM
dbo.table1 JOIN table2 ON table2.some_idn = dbo.table1.some_idn
WHERE
table2.some_idn = :some_idn_1 AND dbo.table1.date_created
BETWEEN :date_created_1 AND :date_created_2
UNION ALL
SELECT
dbo.table3.row_num AS row_num, dbo.table3.test_msg AS test_msg,

dbo.table3.date_created AS date_created,
table2.name_file AS name_file
FROM
dbo.table3 JOIN table2 ON table2.some_idn = dbo.table3.some_idn
WHERE
table2.some_idn = :some_idn_2 AND dbo.table3.date_created
BETWEEN :date_created_3 AND :date_created_4) AS anon_2
UNION ALL
SELECT
dbo.table4.row_num AS row_num, dbo.table4.test_msg AS test_msg,
dbo.table4.date_created 
AS date_created, table2.name_file
AS name_file
FROM
dbo.table4 JOIN table2 ON table2.some_idn = dbo.table4.some_idn
WHERE
table2.some_idn = :some_idn_3 AND dbo.table4.date_created
BETWEEN :date_created_5 AND :date_created_6) AS anon_1


Here we  don't want to have top level select column name with alias
since i am refering in the code as row_num.

Can any one suggest what changes to be made in the query.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] short question on Table

2011-04-16 Thread Lars
Hi all,

Does anyone know how I can add a Column to an existing not yet mapped
Table?

Cheers, Lars

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] short question on Table

2011-04-16 Thread Lars
Hi all,

Does anyone know how I can add a Column to an existing not yet mapped
Table?

Cheers, Lars

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.