[Python-Dev] database APIs

Luke Kenneth Casson Leighton lkcl@samba-tng.org
Sun, 2 Feb 2003 14:20:23 +0000


has anyone considered doing database helper functions based
off of the DB 2.0 api?

the question is inspired by the amount of work that is
needed to create a useable suite of database queries in
the shortest period of time - something that is important
when both developing databases and also when doing lots
of database applications one after the other.

also for some of the background please see the advogato article
http://advogato.org/article/600.html particularly the link to
jmg's code which contains some very simple to use but obscure 
coding methods to wrap SQL databases in objects.

the reason i ask is because the DB 2.0 api is great in
that it makes things easy-ish to add in different databases
(e.g. MySQL, MS-SQL, PostgreSQL) if you can deal with
the syntactical differences, but it doesn't help you
do things like:

- make a query that gets you some results

- modify one of the results

- write the modified results back.

i would _expect_ that the cursor class would have a function
called save() which performed the last of these operations.

e.g. as follows:

cur = db.execute("select name from table where id=20")
cur[0] = "fred's new name"
cur.save()

where the save() will AUTOMATICALLY create a database
statement:

	update table set name="fred's new name" where id=20


now, i realise that the above idea has quite a lot of
SQL-specific dependence: that can be dealt with by
providing base classes where the analysis or creation
of the query and also the save() function can be
over-ridden.

e.g. a class named DBgeneratorBase

and therefore an example class can be created

e.g. DBgeneratorSQL.


i was therefore wondering about two things:

- what do people on the python-dev list think of this concept?

- is it something appropriate to be included in the
  python libs, given that the python db API at present
  is more of a convention than something that is
  enforced as part of the python library suite.


-- 
----------------------------------------------------------
this message is private, confidential, and is intented for
the specified recipients only.  if you received in error,
altered, deleted, modified, destroyed or interfered with
the contents of this message, in whole or in part, please
inform the sender (that's me), immediately.

if you, the recipient, reply to this message, and do not
then receive a response, please consider your reply to have
been lost or deliberately destroyed: i *always* acknowledge
personal email received.  please therefore take appropriate
action and use appropriate protocols to ensure effective
communication.

thank you.