[SQLObject] A small patch around features I need
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: G. <fra...@cl...> - 2003-06-27 16:48:55
|
Clarisys patch for SQLOBject 0.3 author : Fran=E7ois Girault - fra...@cl... Updated : 27/06/03 ---------------------------------------------- INSTALL :=20 - download SQLObject 0.3 and untar it in a directory - put the patch file in this dir and then type 'patch -p0 < patch_filename' - enjoy ;-) ---------------------------------------------- 27/06/03 Changes : * id can now be passed at creation time when using db sequence is not appr= opriate myNewEntity =3D Entity.new(id=3D25) if Entity._idName is defined, you can also use this value as key to spe= cify the id : class Entity(SQLObject): _idName =3D 'code' ... myNewEntity =3D Entity.new(code=3D25) will work the same as previous de= claration * object ids can be alphanumerical type. Note that you MUST specify id at = creation time for the moment. Support for stored procedure to generate alph= anumerical ids will come in a close future ;-)=20 * relations between objects can use other fields than id (including alphan= umerical ones). In _join class attribute you can add these parameter to Joi= n children creation : * joinField let you specify the field to join within your class * otherField let you specify the field of the other table Note that the specified fields MUST be declared as alternateID ---------------------------------------------- Short sample .../... class Person(SQLObject): # Person table has a "serial" id field named 'id' in the table, but also a= n alphanumerical code to link to Occupation (in this context you would say = it's stupid but I need that in some cases) _columns =3D [ Col('code', alternateID=3DTrue), Col('firstname'), Col('las= tname') ] _joins =3D [ RelatedJoin('Occupation', joinField=3D'code', joinColumn=3D'p= erson_code', otherColumn=3D'occupation_code', intermediateTable=3D'person_o= ccupation') ] class Occupation(SQLObject): # code is alphanumerical _idName =3D 'code' _columns =3D [Col('label')] _joins =3D [RelatedJoin('Person', joinColumn=3D'person_code', otherColumn= =3D'occupation_code', otherField=3D'code', intermediateTable=3D'person_occu= pation')] occupation =3D Occupation.new(code=3D'WLK', label=3D'Walk in the mountain') # INSERT INTO occupation (label, code) VALUES ('Walk in the mountain', 'WLK= ') pers.addOccupation(occupation) # INSERT INTO person_occupation (person_code, occupation_code) VALUES ('ABC= ', 'WLK') .../... ---------------------------------------------- Limitation : * for Postgresql usage only due to modification in DBConnection, and I ha= ve no time to write & test with other DB (help welcome :) ). |