I''ve been frustrated with writing database definitions and somehow in the past few hours out of this has grown a tiny DSL for making this task easier. It''s not polished or anything and I don''t like all those @@ variables (how can this be done better?). I hope it''s useful to anyone beside me. See http://wiki.rubyonrails.com/rails/show/DefSQL As an appetizer, below are a few examples. Michael include DefSQL create_table ''dummies'' do [ ''lastname varchar(255)'', :other >> ''more_dummies'', :even_other >> [''more_dummies'', {:primary_key => ''pk'', :mandatory => true }], ] end # write out the recorded foreign key constraints foreign_key_constraints create_join_table ''employees'', ''tasks'', :field2 => ''projekt_id'' create_enum_table ''enumeration'' insert_enums ''enumeration'' do [ ''value 1'', ''value 2'', ] end -- Michael Schuerig Airtight arguments have mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org vacuous conclusions. http://www.schuerig.de/michael/ --A.O. Rorty, Explaining Emotions
On Aug 15, 2005, at 9:12 PM, Michael Schuerig wrote:> > I''ve been frustrated with writing database definitions and somehow in > the past few hours out of this has grown a tiny DSL for making this > task easier. It''s not polished or anything and I don''t like all those > @@ variables (how can this be done better?). I hope it''s useful to > anyone beside me. See > > http://wiki.rubyonrails.com/rails/show/DefSQL > > As an appetizer, below are a few examples. > > Michael > > > include DefSQL > > create_table ''dummies'' do > [ > ''lastname varchar(255)'', > :other >> ''more_dummies'', > :even_other >> [''more_dummies'', {:primary_key => ''pk'', :mandatory > => true }], > ] > end > > # write out the recorded foreign key constraints > foreign_key_constraints > > create_join_table ''employees'', ''tasks'', :field2 => ''projekt_id'' > > create_enum_table ''enumeration'' > > insert_enums ''enumeration'' do > [ > ''value 1'', > ''value 2'', > ] > end >ActiveRecord already has at least basic functionality like this (enough to support Migrations, anyway). It might be nice if you could bring some of your extras into that. -Scott
Great thinking Michael! I second the suggestion about integrating with migrations if possible - one syntax to rule them all ;) I''d be thrilled the day I can ship some generic DDL with my app for people to deploy. -San Michael Schuerig wrote:> I''ve been frustrated with writing database definitions and somehow in > the past few hours out of this has grown a tiny DSL for making this > task easier. It''s not polished or anything and I don''t like all those > @@ variables (how can this be done better?). I hope it''s useful to > anyone beside me. See > > http://wiki.rubyonrails.com/rails/show/DefSQL > > As an appetizer, below are a few examples. > > Michael > > > include DefSQL > > create_table ''dummies'' do > [ > ''lastname varchar(255)'', > :other >> ''more_dummies'', > :even_other >> [''more_dummies'', {:primary_key => ''pk'', :mandatory > => true }], > ] > end > > # write out the recorded foreign key constraints > foreign_key_constraints > > create_join_table ''employees'', ''tasks'', :field2 => ''projekt_id'' > > create_enum_table ''enumeration'' > > insert_enums ''enumeration'' do > [ > ''value 1'', > ''value 2'', > ] > end >
On Tuesday 16 August 2005 03:49, Scott Barron wrote:> On Aug 15, 2005, at 9:12 PM, Michael Schuerig wrote: > > I''ve been frustrated with writing database definitions and somehow > > in the past few hours out of this has grown a tiny DSL for making > > this task easier. It''s not polished or anything and I don''t like > > all those @@ variables (how can this be done better?). I hope it''s > > useful to anyone beside me. See > > > > http://wiki.rubyonrails.com/rails/show/DefSQL[snip]> ActiveRecord already has at least basic functionality like this > (enough to > support Migrations, anyway). It might be nice if you could bring > some of > your extras into that.The point of the "little language" is not the functionality per se, but the functionality paired with a palatable syntax. I know Migrations, haven''t used them yet, though. It seems to me, that DefSQL and Migrations have different niches. The former is for bulk definition the latter for surgery. Also, I doubt DHH would allow the overwritten Symbol#>> into Rails. Michael -- Michael Schuerig Life is just as deadly mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org As it looks http://www.schuerig.de/michael/ --Richard Thompson, Sibella
On Tuesday 16 August 2005 07:52, San wrote:> Great thinking Michael! I second the suggestion about integrating > with migrations if possible - one syntax to rule them all ;) > > I''d be thrilled the day I can ship some generic DDL with my app for > people to deploy.Well, go ahead with a suggestion on how you would want this to look. Michael -- Michael Schuerig Those people who smile a lot mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org Watch the eyes http://www.schuerig.de/michael/ --Ani DiFranco, Outta Me, Onto You
On Aug 16, 2005, at 4:50 AM, Michael Schuerig wrote:> On Tuesday 16 August 2005 03:49, Scott Barron wrote: >> On Aug 15, 2005, at 9:12 PM, Michael Schuerig wrote: >>> I''ve been frustrated with writing database definitions and somehow >>> in the past few hours out of this has grown a tiny DSL for making >>> this task easier. It''s not polished or anything and I don''t like >>> all those @@ variables (how can this be done better?). I hope it''s >>> useful to anyone beside me. See >>> >>> http://wiki.rubyonrails.com/rails/show/DefSQL > [snip] > >> ActiveRecord already has at least basic functionality like this >> (enough to >> support Migrations, anyway). It might be nice if you could bring >> some of >> your extras into that. > > The point of the "little language" is not the functionality per se, but > the functionality paired with a palatable syntax. I know Migrations, > haven''t used them yet, though. It seems to me, that DefSQL and > Migrations have different niches. The former is for bulk definition the > latter for surgery.Don''t let the name fool you. Try actually using them before jumping to any conclusions.> > Also, I doubt DHH would allow the overwritten Symbol#>> into Rails. >Probably for good reason. -Scott