[sqlalchemy] What is the proper way to return the deleted records synchronously?

2013-09-22 Thread herzaso
I need to return the ID's of the deleted records on session.query().delete() I've found this for bulk deletes: def after_bulk_delete(session, query, query_context, result): affected_table = query_context.statement.froms[0] affected_rows = query_context.statement.execute().fetchall()

Re: [sqlalchemy] another postgresql distinct on question

2013-09-22 Thread Jonathan Vanasco
ah ha! yes! that is right. query = select( (these,columns,) ).distinct( this.column ) this was an even tricker problem... and I might have been executing correct queries last night without realizing it. i just noticed that i was getting a correct query in my database, while I was

[sqlalchemy] Re: What is the proper way to return the deleted records synchronously?

2013-09-22 Thread Jonathan Vanasco
Assuming you're in the ORM, there's also a per-instance delete : http://docs.sqlalchemy.org/en/rel_0_8/orm/events.html#sqlalchemy.orm.events.MapperEvents.after_delete but `session.query().delete()` suggests you don't want to load objects into the ORM, and just want to delete things matching a

[sqlalchemy] Automatically create secondary tables for many to many relationship?

2013-09-22 Thread jpeck
Given the arbitrary example below, I can't ever recall actually using the FooKeyword association table other than to set up mappings. I came up with a brute force method to generate the secondary table for me automatically, and I'm hoping someone can show me a better way to do this. My goal

Re: [sqlalchemy] Create Table scripts failing randomly - scripts work from sqlite3 driver but not sqlalchemy

2013-09-22 Thread Simon King
The documentation for the Python sqlite driver specifically says: execute() will only execute a single SQL statement. If you try to execute more than one statement with it, it will raise a Warning. Use executescript() if you want to execute multiple SQL statements with one call.

Re: [sqlalchemy] Automatically create secondary tables for many to many relationship?

2013-09-22 Thread Michael Bayer
On Sep 22, 2013, at 5:24 PM, jpeck peck.j...@gmail.com wrote: And replace it with something like this: class Keyword(Base): snip (same as before) class Foo(Base): snip keywords = generate_many_to_many_for_me('Foo', 'Keyword')

RE: [sqlalchemy] Automatically create secondary tables for many to many relationship?

2013-09-22 Thread Jeff Peck
And replace it with something like this: class Keyword(Base): snip (same as before) class Foo(Base): snip keywords = generate_many_to_many_for_me('Foo', 'Keyword') there's a recipe for this at this blog post, you might consider

[sqlalchemy] Create Table without Metadata and pass it in later?

2013-09-22 Thread Donald Stufft
So all of the examples i've seen either explicitly pass in a schema or do it implicitly via the declartive_base. My question is can I create a table and associate it with a metadata at a later point? -- You received this message because you are subscribed to the Google Groups sqlalchemy

Re: [sqlalchemy] Automatically create secondary tables for many to many relationship?

2013-09-22 Thread Michael Bayer
On Sep 22, 2013, at 10:11 PM, Jeff Peck peck.j...@gmail.com wrote: And replace it with something like this: class Keyword(Base): snip (same as before) class Foo(Base): snip keywords = generate_many_to_many_for_me('Foo', 'Keyword')

Re: [sqlalchemy] Create Table without Metadata and pass it in later?

2013-09-22 Thread Michael Bayer
this is one of those, why do you want to do that kinds of questions.You probably have a tometadata() use case of some kind, see http://docs.sqlalchemy.org/en/rel_0_8/core/metadata.html?highlight=tometadata#sqlalchemy.schema.Table.tometadata On Sep 22, 2013, at 10:30 PM, Donald Stufft

Re: [sqlalchemy] Create Table without Metadata and pass it in later?

2013-09-22 Thread Donald Stufft
Mostly I'm trying to avoid global state like metadata. The Tables themselves are global, but I feel like the metatdata maybe shouldn't be? I'm not a SQL alchemy expert so maybe what I'm trying to do is crazy and the answer is don't do that. Mostly I'm trying to figure out what patterns are

Re: [sqlalchemy] Create Table scripts failing randomly - scripts work from sqlite3 driver but not sqlalchemy

2013-09-22 Thread monosij . forums
Hi Simon - Great! The executescript from sqlite worked great. I had not seen that. I was able to execute indices and fks as well. Is the same not possible from SQLAlchemy then? Would version 0.9 have it? I don't know if Michael is planning on having this feature. Meaning even for PostgreSQL