Of course i need to do the usual updates,inserts and delele also.
I was looking for an ORM integrate with my stuff since i am doing lots
of webased front ends recently (currently with Spyce but i may switch
to Turobgears sans SQLlobject)
Firstly, respects to you: qlime seems to be excellent, well, at least,
exactly what I would like :)
Just a question. If I didn't miss something, qlime works with the
tables, which are already in the DB? Is there a way to create table
from within the qlime's DataObject? The point is that seems to be
simple. The simplest way would be to use the docstring of this class,
e.g., like the following:
class aData( DataObject ):
'''CREATE TABLE PHONE (NAME VARCHAR(10), NUMBER VARCHAR(10));'''
pass
with some 'create' classmethod added to DataObject:
def create( cls, cxn ):
if cls.__doc__ != '':
cls._createStmt = cls.__doc__
c = cxn.conn.cursor()
try:
c.execute( cls._createStmt )
except:
cxn.conn.rollback()
cls.__created = False
else:
cxn.conn.commit()
del c
create = classmethod ( create )
This could be used in the way as below:
if __name__ == '__main__':
from qlime import pgsql
conn = pgsql.DSConn(dbname='test', username='tester',
password='guessit' )
class Phones( DataObject ):
'''CREATE TABLE PHONES (NAME VARCHAR(10), NUMBER VARCHAR(10));'''
pass
Phones.create( conn )
This creates Phones table in the DB 'test'. However, the version of
'create' relies on rollback if the table already exists. Probably,
QLime has a way to overcome it.
Greetings,
Giorgi
P.S. DSConn should probably be equiped with 'exec_from_sql_file'
method: just for the seek of convenience...
Thank you for the reply.
>Hmm.. perhaps all you need is an execute() method on the conn object to
>easily call whatever sql you want. Right now the DataObject is
>completely independent of the backend it is loaded from (could be a CSV
>file, or an object database in the future). In this context the SQL
>does not always make sense. Also different databases (Postgres, SQLite)
>have different syntax for some types.
Yes, after the previeous posting, I kept playing with qlime and came to
the conclusion that any data-source-specific stuff should not be part
of core.- and rdb.DataObject. On another hand, there's always a
trade-off: if one sacrifies portability across different platforms,
he'd like to gain something as well. Therefore, pgsql (firebird) might
have pgDataObject (fbDataObject) class with some db-specific methods
and attributes.
>Does this look better to you? Note that the database specific code (the
>pgsql.DSConn class as well as the Postgres-valid SQL) is all in one
>place now.
Yes, that's certainly nice.
> If I add the execute(), you could just do conn.execute(open('test.sql').read()).
Would be nice, again.
Greetings,
Giorgi
P.S. I guess pgsql.DSCOnn should redefine rdb.DSConn's __getitem__ in a
way that one could look up for the ObjectClass without explicit
'public.'
###
def __getitem__(self, obclass):
obclass='public.'+obclass
return self.self.obclasses[obclass]
###
This would increase the code's portability.