one-time factory in python for an experienced java guy

Jonathan Gardner jgardner at jonathangardner.net
Tue Jul 14 16:05:48 EDT 2009


On Jul 14, 7:03 am, phonky <pho... at europe.com> wrote:
>
> Now, I do not know yet how the account number scheme looks like.

Exactly. The data store knows a lot more than the client (your
program) will ever know.

The correct answer is to do nothing. Use your data store to generate
the IDs for you. The implementations discussed here will not generate
unique IDs across invocations, but the data store will persist the
sequence for you appropriately.

The more correct answer is to abstract away the client to your data
store as well. See SQLAlchemy.

If you're writing a data store, you're doing it wrong. See PostgreSQL,
MySQL, or any other data store out there that are perfectly fine for
development and production use.

I like to use UUIDs for the IDs. Others like big ints that are a
sequence. I've seen people use encrypted big ints, basically random
strings that aren't really random. In the end, you only have to change
the code that talks to the data store, and the rest of your program
only cares about the equality of the id.



More information about the Python-list mailing list