Creating database structures in a portable way
bdesth.quelquechose at free.quelquepart.fr
Mon Sep 18 23:54:24 CEST 2006
Samuel a écrit :
>>FWIW, there's a Python port of adodb:
>>and parsing XML in Python is quite easy. So you could as well port the
>>AdoDB XML to Python too.
> That is exactly what I am trying to avoid. While implementing the
> parser might be easy, you have to translate things into different
> database flavors, caring about a bunch of things that I'd rather not
> have to think about.
This I can understand pretty well - hence my suggestion of using
>>OTOH, there are other - possibly better (YMMV) - DB abstraction layers
>>in Python, like SQLAlchemy.
> SQLAlchemy looks pretty good, but unfortunately apparently requires
> shell access for installation (or at least, I have not found any other
> solution covered in the docs), which I can not use. I need a solution
> that can be shipped in a software package, and installed by simply
> copying it to the server.
It doesn't use binaries AFAIK, so just copying should work as well.
>>And since the above solution requires
>>(re)writing the xml-parsing part, it might be worth rewriting it so it
>>knows how to generate SQLAlchemy schemas instead.
> Rewriting the schema is possible (I only want to keep it separated from
> the code),
Why ? Isn't your code supposed to use it ?
> so using SQLAlchemy's built in solution for generating
> tables seems just fine. It's only the installation part.
> Anyway, I am wondering; Python seems to include database adapters for
> almost any important database, all with a unified API. Why would you
> need another database abstraction on top of that?
A first point is that the DB-API doesn't hide the differences between
various SQL dialects. A second point is that DB-API requires you to
embed SQL statements as strings, while SQLAlchemy allow you to build
your SQL queries in pure Python. (and FWIW, if using an existing DB, you
don't even have to describe the schema a second time to use it). Well,
just start playing with it, and I really doubt you'll want to come back
to the embedded hand-written SQL !-)
My 2 cents
More information about the Python-list