On Dec 18, 2007, at 10:42 AM, Jonathan Gardner wrote:
>
> Shouldn't SQLAlchemy throw an exception when you try to grab the next
> value of a non-existant sequence?
for a database which supports sequences, it will. It appears that for
DB's which don't, executing a sequence explicitly is silently ignoring
it; I would consider this to be a bug. However, when a Sequence
attached to a Column for the purpose of generating new default values
for that column, during an INSERT, it is ignored for a database that
doesnt support sequences, like sqlite. This is by design and it is so
that a single Table construct can be used with multiple database
backends (this should be in the docs too).
> Should SQLAlchemy implement a crude version of sequences in Python to
> cover up deficient SQL implemetnations? I imagine it is technically
> possible. We can have a table that stores the last value of the
> sequence and its parameters, and then in those databases just go look
> up the last state of the sequence there. But is this in the spirit of
> the SQLAlchemy design?
sure, you can write such a function and attach it as the "default"
generator on any Column. As far as should such an ID generator be
included with SQLAlchemy, I would support having some ID generators
available as optional constructs to use on Tables, and I'd like to see
generators like UUID, hilo, etc. As of yet nobody has contributed
these.
>
> Should sequences be sequences first-class citizens of the schema like
> tables are? That is, why do I have to create them and drop them
> separately?
They are first class citizens. if your Sequence is sitting inside of
a Column as its default generator, it will be created and dropped
along with the Table which its associated with. As far as being
able to associate the Sequence with MetaData directly without the
Table serving as a host, see below, I dont have any issue with such an
enhancement. Nobody has ever asked for this feature before since a
Sequence usually associates with a specific table.
> Why can't we have a "next()" method for sequences and then
> bind sequences to the metadata the same way tables are?
We do have a next(): nextid = engine.execute(Sequence('foo')) .
Sequences are bound to metadata as well, as a little experimentation
will show...the current methodology is that the Sequence is associated
with the MetaData via one or more Tables its associated with:
>>> from sqlalchemy import *
>>> e = create_engine('postgres://scott:[EMAIL PROTECTED]/test')
>>> m = MetaData()
>>> t = Table('foo', m, Column('id', Integer, Sequence('foo_seq')))
>>> m.bind = e
>>> t.create()
>>> t.c.id.default.execute()
1L
Now it may be a nice enhancement to be able to create a Sequence which
binds to a metadata, without the Table part needing to be involved,
such as:
Sequence('foo_id_seq', metadata)
This enhancement is fine with me.
> If you are looking for development help, I have some spare time here
> and there and this is actually interesting. If someone can point the
> way to go, I can take it from there.
if you can produce decent code, and almost more importantly good unit
tests that ensure the decent code always works (else it might as well
be broken), commit access is there for the taking. Start with trac
tickets, i.e. create some and/or fix some, hang out on irc and
sqlalchemy-devel, come up with some patches and we go from there.
We're quite ready for many more developers.
>
>
> Otherwise, I am incredibly surprised at how well SQLAlchemy works in
> allowing me to write truly database independent applications. You have
> done something I don't think anyone else has ever done in the history
> of computing, and for that you should be proud.
thanks for the compliments ! see you at Pycon.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---