you asked for it...
> This brings up a question I have and I have not had a decent answer
> to. Other than for accessing legacy databases why would one need
> SQLAlchemy over the web2py DAL?
Without having looked into DAL at all: alone from the description above, it
makes me instantly dislike it. (If you're starting to foam at the mouth
already: jump to the last paragraph and come back here.) I like to control
the database. I know SQL, and when I design my database schema, I do it as
"desigining a db schema". The model in a web application *may* be a good
way to specify it, but ultimately, I want to be in control about what tables
get created, what the columns are, how the primary key is built etc.
Yes, I understand that being able to make assumptions about stuff like
"autoincrement primary key on every table" allows for some beautiful and
quite stunning optimisations/automatisms, and being my own master in terms
of DB layout makes me pay for it by not having these simplifications
available. OTOH with the 'make some assumptions' kinds of frameworks I'm
always afraid that these assumptions will bite me at some point where what I
want suddenyl doesn't match with what the framework designers think how
stuff should be done.
Please take this as what it is: pure opinion. Like: When somebody doesn't
like Pizza it doesn't mean Pizza is bad, but just that he doesn't like it.
cheers
-- vbi
It's not just "legacy" databases. Calling them legacy makes it sound
like only old databases are designed against the wishes of ORMs like
web2py. I know quite a few developers who simply won't tolerate poor
table structure, and too often these ORM's dictate a pattern that is
less than ideal (as I have defined it ;-) ). Disallowing/discouraging
compound primary keys, for example, sacrifices traditional design to
make it easier on ORM developers, or in the case of web2py, to allow it
to be abstracted to even allow non-relational databases.
Anyway, I consider traditional design to be important. I prefer my
model to be proscriptive as well as descriptive. The more I can get my
data model working to define structure, the less pain later. There's a
large class of developers who don't really care. That's fine, and maybe
they won't ever need to use a fuller extent of the database's power
anyway, but I have yet to see this as the "future" of web apps that
throws most databases I've seen into the "legacy" category. Plus it
assumes that I have full control over the database, and that the
database is used for no other purpose or at least mainly used by that DAL.
Does the web2py DAL allow batch updates etc. to occur without recourse
to actual SQL statements? i.e., updating all columns in the database
without making a call per record? If not, functionality like this gives
SQLAlchemy perhaps another benefit.
I'm interested to hear what others think of this. Is the database
structure less important than I'm making it out to be?
Another less common but probably more illustrative scenario is the
"Diamond" relationship, where there's a parent, multiple child tables,
and then a table which references specific combinations of the children:
Parent
- parent_id PK
LeftChild
- leftchild_id PK
- parent_id PK,FK
RightChild
- rightchild_id PK
- parent_id PK,FK
ChildCombo
- childcombo_id PK
- rightchild_id FK
- leftchild_id FK
- parent_id FK
In this scenario, the ChildCombo must reference a left and right child
which share the same parent. My compound FK can do this since the two
child tables have taken on the parent's PK as part of their own.
Now I'll grant that possibly a majority developers aren't going to care
enough to design it out this way. They're happy to allow the "same
parent" constraint to fall by the wayside in order to simplify the
design. But I think it's best to let the database care for this if you
can, and I certainly wouldn't call doing so a mistake. But that for me
is the bigger difference between SQL Alchemy and the simpler ORMs...not
so much the freedom, but the philosophy of SQL Alchemy that wishes to
let the database play its strengths, even if it means less of an
abstraction. The thing about abstractions of course, is that they end
up playing to the "lowest common denominator" of all implementations.
> This buys us a lot of other goodies that other ORMs do not have.
> For example automatic forms and the ability to assign uuids to records
> for import/export/merge of databases (web2py can export an entire
> database in Oracle and reimport it on MSSQL or Google App Engine
> without breaking references even if the autoincrement IDs of the
> source and destination may be different).
>
Here's the great part about the web2py abstraction in my opinion. It
would be very cool to take an app that runs off a database and just drop
it into AppEngine. No way that's going to work with SQL Alchemy. The
philosophy of SA is such that it just wouldn't be done.
> Anyway, I am not comfortable with talking about web2py on this list.
> As I said I very much like TG and its developers. But if you ask me
> questions I feel compelled to answer.
>
I actually appreciate your talking about web2py on this list. I
wouldn't have gotten to know so much about it otherwise, and I am the
better for it. Plus it helps to show what TurboGears is about when this
comparison is made.