From: Tom Sawyer Date: 2002-09-03T15:42:47+09:00 Subject: Re: Idea: Ruby Object Persistence Service --=-hCQNB+lkuR0fTJZxGioA Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Mon, 2002-09-02 at 18:48, Holden Glova wrote: > I have never heard of DBize before, does this maintain mappings of collec= tions=20 > for you as well? The holy grail is to not write SQL (or whatever you need= to=20 > store persistently) for the majority of the cases. well, if i understand you correctly, then yes. DBize includes two mixins actually, DBize::Record and DBize::Subrecords. If you subclass Array and mixin DBize::Subrecords, the you have a means of dealing with a collection of objects mapped to the database. if, like i said, that is what you mean by "mappings of collections" indeed, no sql required, in all cases i think. essentially DBize knows the meta-inforamation of the table your object pertains too. so it uses the dynamicism of ruby to make method calls using #send with the table's attribute (field) names. for instance, here's a mockup: CREATE TABLE mapped_table ( record SERIAL PRIMARY KEY, name text DEFAULT '', value text DEFAULT '' ); class MappedObject include DBize::Record =20 attr_accessor :record =20 attr_accessor :name attr_accessor :value def table 'mapped_table' end =20 end mo =3D MappedObject.new mo.load_from_database(1) mo.name=3D"A New Name" mo.update_database this loads the record for mapped_table where record=3D1 into the object. changes the name attribute and saves it back to the table. notice the database atrributes (fields) and the object accessor attributes have the exact same names. this is really the key to DBizes ease of use. and is not limiting since you can always define accessor methods by hand, even complex ones. the record attribute is required by DBize to get the record's id attribute. if that field isn't called record in the table then simply define record manually to access whatever it is: attr_accessor :myid def record myid end def record=3D(x) myid =3D x end i'll probably improve on this in the future. the method #table is required as well, to tell DBize which table the object is stored in, this i beleive i am in the process of moving to a class method instead. anyway you get the idea. --=20 tom sawyer, aka transami transami@transami.net --=-hCQNB+lkuR0fTJZxGioA Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQA9dFw/ITYvPhXYDikRAiTMAKCzvARk8tA0xRZjOu8/VfoO8Pt5NQCgtXfp 3UT0nf/Wi/fGjdP7VLN1Xpo= =xMqx -----END PGP SIGNATURE----- --=-hCQNB+lkuR0fTJZxGioA--