开发者

Is there a good DSL for manipulating MySQL scripts independent of any particular web framework?

开发者 https://www.devze.com 2023-04-02 04:28 出处:网络
I have a simple MySQL script that I use in a web application to complete rebuild/reset my DB to a clean initial state. Thus, in this script I define the various tables, stored procs, etc. that I need.

I have a simple MySQL script that I use in a web application to complete rebuild/reset my DB to a clean initial state. Thus, in this script I define the various tables, stored procs, etc. that I need.

This is fairly good initial solution b/c it's simple and does the job without being overkill. However there are some drawbacks. One example is typing. It would be nice to define stored procs with richer types so I don't need to repeat declarations like VARCHAR(64).

Thus, my question is: is there a good DSL for manipulating MySQL scripts? (e.g. it could ultimately generate valid MySQL scripts) that is effectively a nice DSL over MySQL, without trying to do too much and have too many bells and whistles. Would be nice if the language itself had decent support for DSL, but more importantly, it would be nice to find something that wasn't heavily wedded to a particular web framework.

Some cursory searches did not yield anything immediately obvious.

I guess one practical alternative is to just use your favorite ORM as a way of getting at a solution that's effective开发者_高级运维ly nice. So part of the motivation of this question is to see if the DSL approach has been explored to any success.


I'm assuming you mean an Internal DSL (see http://martinfowler.com/bliki/DomainSpecificLanguage.html, and http://en.wikipedia.org/wiki/Domain-specific_language) because SQL is a DSL, i.e. an External DSL (by Martin Fowler's definition, which has gained fairly wide acceptance).

Given that assumption, and not knowing what language you prefer, I was able to find a few Internal DSL's for SQL code generation:

  • Ruby - sqldsl.rubyforge.org/
  • Java - code.google.com/p/sql-dsl/
  • Scala - github.com/p3t0r/scala-sql-dsl

if you google "SQL DSL" there are more, also try googling "SQL DSL [enter your favorite language here]" and you may find something more suitable.

Another approach which has a different set of advantages and disadvantages (than an internal DSL) would be generating the SQL code from a template. Either a template in the form of a string with variable escapes (or concatenation) or in a separate file using a template language.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号