Skip to main content

Posts

Showing posts with the label DSLs

Defeating the Purpose of a DSL

First, I neglected to mention in my previous post that I found Paul Cowan's blog to be a tremendous help in figuring out how build a DSL with Boo and Rhino DSL . Second, I wanted to point out that, because this is an internal DSL written in Boo, it's still possible to use familiar programming constructs in the DSL scripts. For example, I could dynamically generate the team definitions from some other datasource, like so: stats = GetData() for row as DataRow in stats.Rows: define row["name"]: defense Determine.DefenseFromRanking(cast(int,row["defenseRanking"])) pass_offense Determine.PassOffenseFromRanking(cast(int,row["passOffenseRanking"])), with_qb_type(Determine.QbTypeFromRatingAndExperience(cast(double,row["qbRating"]), cast(int,row["qbExperience"]))) run_offense Determine.RunOffenseFromRanking(cast(int,row["runOffenseRanking"])) where GetData() returns a DataTable with multiple team statistics, and Det...

Building a Simple Data Definition DSL with Boo

In my daily work, I find myself writing a lot of one-off SQL scripts to handle various data issues. In particular, I've had to tweak existing sets of metadata with scripts that look something like the following: DECLARE @SomeId INT DECLARE @SomeOtherId INT SELECT @SomeId = SomeTableId FROM SomeTable WHERE SomeName = 'Something' SELECT @SomeOtherId = SomeOtherTableid FROM SomeOtherTable WHERE SomeOtherName = 'SomethingElse' IF NOT EXISTS( SELECT 1 FROM SomeMetadataTable WHERE Name = 'MetadataName') BEGIN INSERT INTO SomeMetadataTable (Name, Property1, Property2) VALUES ('MetadataName', @SomeId, @SomeOtherId) END ELSE BEGIN UPDATE SomeMetadataTable SET Property1 = @SomeId , Property2 = @SomeOtherId WHERE Name = 'MetadataName' END Just writing a few of these gets to be tedious, and master script...