[sqlalchemy] Action on object deletion

2007-01-15 Thread aldo
Hi Folks, I have an application that needs to do a certain amount of housekeeping when objects are deleted or edited. Essentially, I need to keep historical data, so under some circumstances "deleted" objects actually need to be "obsoleted", and "edited" objects need to be copied and reference

[sqlalchemy] Re: Constructing where-clauses dynamically

2007-01-15 Thread Jonathan Ellis
On 1/15/07, Michael Bayer <[EMAIL PROTECTED]> wrote: some kind of OQL. nooo --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send emai

[sqlalchemy] Constructing where-clauses dynamically

2007-01-15 Thread Michael Bayer
in continuing http://groups.google.com/group/sqlalchemy/browse_thread/thread/4dab6cfae1f62521/8b66851007c6a652?lnk=gst&q=daniel+miller&rnum=2#8b66851007c6a652 , which bizarrely GG will not let me continue, on a closely related but not exactly the same issue, i broke my limit of people expecting t

[sqlalchemy] Re: portable schema

2007-01-15 Thread Paul Johnston
Manlio, I quite like your idea, although I also agree with Michael's "no magic" philosophy. I identified a similar problem with autoincrementing primary keys, where a model that worked with one db (say sqlite) would not work with another (say oracle). All libraries that try to provide porta

[sqlalchemy] Re: portable schema

2007-01-15 Thread Michael Bayer
its essentially a "framework" feature, you have a certain idea about how a fake "schema" might be implemented for databases that dont explcitly support schemas, such as through table name prefixes or modified sqlite filenames. both of which are entirely reasonable, for an application that choose

[sqlalchemy] Re: portable schema

2007-01-15 Thread Manlio Perillo
Michael Bayer ha scritto: On Jan 15, 2007, at 12:05 PM, Manlio Perillo wrote: My idea is simple. 1) When the database does not support schema, the schema name specified in Table costructor should be prepended to the table name. foo = Table('foo', ..., schema='bar') result in a tab

[sqlalchemy] Re: Questions about polymorphic mappers

2007-01-15 Thread Michael Bayer
at this point the entity_name should get set after your custom create_instance is called (at least thats in the trunk). init_attr is not required, it pre-sets attributes on the object that are otherwise auto-created later (but the autocreation step throws a single AttributeError per attr

[sqlalchemy] Re: portable schema

2007-01-15 Thread Michael Bayer
On Jan 15, 2007, at 12:05 PM, Manlio Perillo wrote: My idea is simple. 1) When the database does not support schema, the schema name specified in Table costructor should be prepended to the table name. foo = Table('foo', ..., schema='bar') result in a table named bar_foo why no

[sqlalchemy] Re: Questions about polymorphic mappers

2007-01-15 Thread King Simon-NFHD78
Michael Bayer wrote: you can still override create_instance() as well and try to spit out subclasses that are otherwise not mapped. This was something I looked at a while ago as well, and I wasn't sure what the requirements on objects returned from create_instance were. If it is not overri

[sqlalchemy] portable schema

2007-01-15 Thread Manlio Perillo
Hi. I don't know if this already implemented or planned. Schemas are supported by SQLAlchemy, but unfortunately not all database supported by SQLAlchemy supports schema. My idea is simple. 1) When the database does not support schema, the schema name specified in Table costructor should b

[sqlalchemy] Re: Questions about polymorphic mappers

2007-01-15 Thread King Simon-NFHD78
Ah, I see what you mean. Yep, that would work perfectly for me. It would mean that I would need to set up a mapper for every subclass, but that is no great hardship (I was half-imagining just mapping the base class, but that probably has other implications) Cheers, Simon Micheal Bayer wrote:

[sqlalchemy] Re: adding a foreign key constraint to an existing table

2007-01-15 Thread Jonathan Ellis
On 1/15/07, Michael Bayer <[EMAIL PROTECTED]> wrote: 2. no support for "CASCADE" in the "DROP" statement right now. someone fill me in, is "DROP CASCADE" part of the sql standard ? yes, at least for tables. --~--~-~--~~~---~--~~ You received this message becau

[sqlalchemy] Re: Questions about polymorphic mappers

2007-01-15 Thread Michael Bayer
you can still override create_instance() as well and try to spit out subclasses that are otherwise not mapped. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email t

[sqlalchemy] Re: adding a foreign key constraint to an existing table

2007-01-15 Thread Michael Bayer
1. again, the "constraints" collection wasnt really designed to be mutable, as other initialization steps are performed when you first specify ForeignKeyConstraint (or ForeignKey) to Table. if you really need to use a builder pattern here, make your own collection of columns and constraints, bu

[sqlalchemy] adding a foreign key constraint to an existing table

2007-01-15 Thread Manlio Perillo
Ok, I'm recidive ;-). I want to add a foreign key constraint to "bind" to tables that came from two separate packages. I have done: calendar.components.append_constraint( sq.ForeignKeyConstraint( [calendar.components.c.organizer], [account.accounts.c.username], ond

[sqlalchemy] Re: pickle and mapped objects

2007-01-15 Thread Michael Bayer
right, or implement __setstate__. On Jan 15, 2007, at 6:07 AM, Manlio Perillo wrote: Michael Bayer ha scritto: if you can pickle the object by itself, then id guess youre using lazy loaders with the query.options(lazyload('something')) call, which places per-object lazy loaders (i.e. call

[sqlalchemy] Re: changine the 'unique' attribute on a column

2007-01-15 Thread Michael Bayer
i dont disagree that the Table being mutable would be handy...but that implies everything else in SA would want to be mutable also. which also technically is fine, and a lot of SA is mutable. but most things have exceptions to their mutability (where in python "exception" means, "it br

[sqlalchemy] Re: Questions about polymorphic mappers

2007-01-15 Thread Michael Bayer
im thinking it would just return the string (or whatever) value that would match the key inside your polymorphic_map. so the polymorphic map would have a 1->1 key->class mapping, but this function would allow you to do translations from whatever is in the result set (like regexps or what

[sqlalchemy] Re: changine the 'unique' attribute on a column

2007-01-15 Thread Manlio Perillo
Michael Bayer ha scritto: you pretty much should construct the Table object the way you want it to be the first time around, Being able to change a table definition later is one of the benefit in using an object oriented database API. I like the idea to design a table in one (indipendent)

[sqlalchemy] Re: pickle and mapped objects

2007-01-15 Thread Manlio Perillo
Michael Bayer ha scritto: if you can pickle the object by itself, then id guess youre using lazy loaders with the query.options(lazyload('something')) call, which places per-object lazy loaders (i.e. callables) on your objects. I'm not sure, since I never use lazy loaders (I use Twisted). e

[sqlalchemy] Re: Questions about polymorphic mappers

2007-01-15 Thread King Simon-NFHD78
Micheal Bayer wrote: id rather just add another plugin point on MapperExtension for this, which takes place before the "polymorphic" decision stage at the top of the _instance method, like get_polymorphic_identity(). that way you could do all of this stuff cleanly in an extension (and id d

[sqlalchemy] Re: Column aliases

2007-01-15 Thread Marco Mariani
Michael Bayer wrote: to have aliases of properties that are usable with get_by(), use the "synonym" function, described in: http://www.sqlalchemy.org/docs/adv_datamapping.myt#advdatamapping_properties_overriding Thank you. Altough the docs are very well done, there are many APIs and that s

[sqlalchemy] Re: count(*) function

2007-01-15 Thread Sébastien LELONG
I have tried select([func.count("*")], from_obj=[table_name]).execute() but it didn't work I think you should try to specify a column in your count or leave it empty (didn't try). If you're using mapped objects, you can use the SelectResults extension: from sqlalchemy.ext.selectresults i

[sqlalchemy] Re: count(*) function

2007-01-15 Thread Marco Mariani
milena wrote: I have tried select([func.count("*")], from_obj=[table_name]).execute() but it didn't work I suppore you're not using mappers, so this is the fastest method: number_of_rows = table.count().execute().fetchone()[0] where table is the table object --~--~-~--~~

[sqlalchemy] Re: count(*) function

2007-01-15 Thread milena
I have tried select([func.count("*")], from_obj=[table_name]).execute() but it didn't work --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googl

[sqlalchemy] count(*) function

2007-01-15 Thread milena
Hi, does anyone know the syntax of SELECT COUNT(*) FROM table_name; for SQLAlchemy? Is there a list of functions (used in SELECT statement) that exist in SQL that I can use in SQLAlchemy? btw, I am using MySQL. I need to see if my table is empty (isemty function doesn't work). Thanks! --~-