On Mar 19, 3:57 pm, "Karlo Lozovina" <[EMAIL PROTECTED]> wrote:

> Now, this is very handy because I don't have to do a SELECT prior to
> modifying a table. Is there a way to use this SQLite feature from SA?
> Or somehow simulate it without too much gory details?

To answer my own question, maybe it will be helpfull to others:

1. Use engine.execute("CREATE TABLE ...."), with "ON CONFLICT REPLACE"
clause on every field you need to bypass default constraints.
2. Create table instance: with table = sa.Table('table', metadata....)
construct. It doesn't matter if you use primary_key=True, or not.
3. Just use table.insert().execute() with every object: if your key is
unique or not present it will do an INSERT, otherwise it will be an
UPDATE.

I've tested this, and it seems to work, if I have missed something
please let me know ;).

Btw, is it probable that SA will some day include SQLites' ON CONFLICT
clause (both "CREATE TABLE" and "INSERT OR" forms)? It's rather ugly
to have to specify my tables manually using .execute().

Best regards,
klm.

--
Karlo Lozovina -- Mosor


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to