object-relational mappers

L

Luis M. González

Luis M. González a écrit :
I have come to the same conclusion.
ORMs make easy things easier, but difficult things impossible...

Not my experience with SQLAlchemy. Ok, I still not had an occasion to
test it against stored procedures, but when it comes to complex queries,
it did the trick so far - and (warning: front-end developper
considerations ahead) happened to be much more usable than raw strings
to dynamically *build* the queries.
The best approach I've seen so far is webpy's (if we are talking of
web apps).
It isn't an ORM, it is just a way to make the database api easier to
use.
Queries don't return objects, they return something similar to
dictionaries, which can be used with dot notation ( for example,
result.name is equal to result['name'] ).
A simple select query would be db.select('customers') or
db.select('customers', name='John').
But you can also resort to plain sql as follows: db.query('select *
from customers where name = "John"').
Simple, effective and doesn't get in your way.

Seems nice too in another way. Is that part independant of the rest of
the framework ? If so, I'll have to give it a try at least for admin
scripts.

Yes, webpy's db api can be used in stand-alone scripts if you want.
See below:

import web
db = web.database(dbn='mysql', db='northwind', user='root')
x = db.select('employees')

for i in x:
print i.FirstName, i.LastName
...

Another good thing is that, since queries return Storage objects
(similar to dictionaries), they are much more flexible.
Suppose that you get the results of a form sent via a POST method, and
you want to insert this data into your database.
You would simple write:

i = web.input()
db.insert('orders', **i)


So everything related to CRUD operations are is easy to do, without
having to mess with objects.
I think this sticks strictly to the KISS principle, keeping it simple,
with less overhead, less layers of abstraction and therefore, less
bugs and complications.
And it matchs perfectly webpy's philosofy for creating web apps.

Luis
 
M

M.-A. Lemburg

I've been poking around the world of object-relational
mappers and it inspired me to coin a corellary to the
the famous quote on regular expressions:

"You have objects and a database: that's 2 problems.
So: get an object-relational mapper:
now you have 2**3 problems."

That is to say I feel that they all make me learn
so much about the internals and features of the
O-R mapper itself that I would be better off rolling
my own queries on an as-needed basis without
wasting so many brain cells.

comments?

I fully agree :)

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source (#1, Apr 03 2008)________________________________________________________________________

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::


eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
 
M

Michael Ströder

M.-A. Lemburg said:
I fully agree :)

BTW: Some people implemented O/R mappers above python-ldap. All
implementations I saw up to now are falling short regarding the
complexity of the LDAP attribute sub-types, the syntactical rules for
attribute type descriptive names and attribute name aliasing. So first a
developer has also to evaluate whether a O/R mapper is really complete
before using it.

Ciao, Michael.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top