SV: SQL2Python

Max Møller Rasmussen maxm at normik.dk
Thu Aug 3 05:50:52 EDT 2000


From: haering at sunhalle3.informatik.tu-muenchen.de

>Like you, I am currently investigating ways to simplify database
>programming via a an object-oriented interface.

I have made a class like that in JScript (Serverside on win32) That I
believe works rather well. To make a new table you just inherit this class
and then describe your table in this new class. It is usually very compact
code that results.

You just define the tables. Yes you need to do it twice in both the database
and the JScript objects. This has both advantages and disadvantages. Ie. if
you have a table with id,name,bigfield1,bigfield2,bigfield3 etc. Then you
can make a "light" object that just uses the id,name part of the table when
you want list overviews of your tables.

Aside from that, all you do when you have a table described is:

// a new instance
var users = new userList();

// A single user by UserID
var user1 = users.getOneByKey(1);

//All users
var allUsers = users.getWhere();
//OutPut
for(i in allUsers){
    Response.Write(allUsers[i].FirstName);
}

//A user where first name = Max
var Max = users.getByVarNameAndID('FirstName', 'Max');

//Output is like this
Response.Write(Max.FirstName);
Response.Write(Max.LasName);
Response.Write(Max.Age);

If it sounds like a reasonable approach to get inspired by just mail and I
can send a copy of the JScript Class. It can be made to work allmost the
same in Pyhton. Just havn't had the time yet.

Regards Max M




More information about the Python-list mailing list