--OZkY3AIuv2LYvjdk
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Sep 21, 2002 at 12:04:55AM +0900, David.Stagner / mpls.frb.org wrote:
> One thing i CAN tell you is to write a code generator to read the table=
=20
> DDLs and crank out wrapper classes that way (as the Pragmatic Programmers=
=20
> would tell you, too).  If you want to map better variable names over the=
=20
> original database names, write them up as text metadata and feed that int=
o=20
> your code generator.  [...]

With ruby's reflection you can avoid a code generator but create dynamic
proxys. Pseudo code follows:

class DBObject
	def intialize(table, id_col, id_value)
		stm =3D DB.prepare("select * from #{table} where ? =3D ?")
		row =3D stm.execute(id_col, id_value).fetch
		@data =3D {}
		row.each_pair do |attr, value|
			@data[attr] =3D value
			self.type.module_eval %q{
				def #{attr}
					return @data[:#{attr}]
				end
			end
		end
	end
end

-billy.

--=20
Meisterbohne       S=F6flinger Stra=DFe 100          Tel: +49-731-399 499-0
   eL=F6sungen       89077 Ulm                     Fax: +49-731-399 499-9

--OZkY3AIuv2LYvjdk
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9i3HufBriNoqItSYRAs97AJwPoO0lFJ6ql+tszblDhxKAiIP6hgCbBkEC
DqcvW7Z8XUwrC5AqiJxZJJE=
=j0NB
-----END PGP SIGNATURE-----

--OZkY3AIuv2LYvjdk--
On Sat, Sep 21, 2002 at 12:04:55AM +0900, David.Stagner / mpls.frb.org wrote:
> One thing i CAN tell you is to write a code generator to read the table=
=20
> DDLs and crank out wrapper classes that way (as the Pragmatic Programmers=
=20
> would tell you, too).  If you want to map better variable names over the=
=20
> original database names, write them up as text metadata and feed that int=
o=20
> your code generator.  [...]

With ruby's reflection you can avoid a code generator but create dynamic
proxys. Pseudo code follows:

class DBObject
	def intialize(table, id_col, id_value)
		stm =3D DB.prepare("select * from #{table} where ? =3D ?")
		row =3D stm.execute(id_col, id_value).fetch
		@data =3D {}
		row.each_pair do |attr, value|
			@data[attr] =3D value
			self.type.module_eval %q{
				def #{attr}
					return @data[:#{attr}]
				end
			end
		end
	end
end

-billy.

--=20
Meisterbohne       S=F6flinger Stra=DFe 100          Tel: +49-731-399 499-0
   eL=F6sungen       89077 Ulm                     Fax: +49-731-399 499-9
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9i3HufBriNoqItSYRAs97AJwPoO0lFJ6ql+tszblDhxKAiIP6hgCbBkEC
DqcvW7Z8XUwrC5AqiJxZJJE=
=j0NB
-----END PGP SIGNATURE-----