Ann: (manipulation of SQL dbs through python objects)

Fionn Behrens
Fri, 12 Oct 2001 00:04:25 +0200 (CEST)

Hi all!

Ian Bicking's announcement of on the webware-discuss mailing
list a few days ago (very recommandable, btw; it includes a number of great
ideas) reminded me of the fact that I have something slightly similiar on disk
for quite some time now. I managed to motivate myself to write a readme and
prop up a web page for anyone who might be interested.

You can find it at:


    * Are you using a (My)SQL database all day in your programming projects
      and dont want to write SQL statements again and again all over?
    * Would you like to use an SQL database in your project without needing to
      know much about SQL?
    * Interested in making your database access sources a bit more readable
      and easier to grok for other programmers?

If you can answer YES to one of these, pSQL might be of interest to you.


Basically, pSQL wraps all database access and all data you get from your
database into some easy-to-handle and easily usable objects that "feel" like
standard python data structures. So, if you have a pSQL database object called
"myDB" with a table called Address, you can find all people in that table who
are living in Oklahoma by issuing a command like:

      |>>> res = myDB.Address.City["Oklahoma%"]
      |>>> len(res)
      To find out the phone numbers of those two,
      you can use e.g.:
      |>>> res.column("Phone")
      |['0405-12345', '0405-67890']
      |>>> for r in res:
      |...   print "%s: %s"%(r.Name, r.Phone)
      |John Doe: 0405-12345
      |Joe User: 0405-67890
      To change one of those numbers in the database:
      |>>> john = res[0]
      |>>> john.Phone = '0405-54321'      # or: res[0]["Phone"] = '0405-54321'


pSQL currently works with MySQLdb only. This will change in a future version
and an abstraction layer will be added which allows the use of any DB 2.0 API
compliant SQL module, e.g. for postgres.

Visit the web page for more information.