Is there a good DSL for managing MySQL scripts regardless of any particular web infrastructure?

I have a simple MySQL script that I use in a web application to complete the recovery / reset of my database to a clean initial state. So in this script, I define the various tables, stored procedures, etc. that I need.

This is a pretty good initial b / c solution, it is simple and does the job without overflow. However, there are some disadvantages. One example is input. It would be nice to define stored procs with richer types, so I don't need to repeat declarations like VARCHAR (64).

So my question is: is there a good DSL for manipulating MySQL scripts? (for example, it can ultimately generate valid MySQL scripts), which is actually a good DSL over MySQL, without trying to make too many too many bells and whistles. It would be nice if the language itself had decent DSL support, but more importantly, it would be nice to find something that was not tied to a specific web infrastructure.

Some cursory searches yielded nothing obvious.

I suggest that one practical alternative is to simply use your favorite ORM as a way to get an effective solution. Thus, part of the motivation for this question is to see if the DSL approach has been successfully studied.

+6
source share
1 answer

I assume you mean internal DSL (see http://martinfowler.com/bliki/DomainSpecificLanguage.html and http://en.wikipedia.org/wiki/Domain-specific_language ), since SQL is DSL, that is, an external DSL (as defined by Martin Fowler, which has gained widespread acceptance).

Given this assumption and not knowing which language you prefer, I managed to find several internal DSLs for generating SQL code:

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

if you are using Google SQL DSL, there is still, 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 internal DSL), will generate SQL code from the template. Either a template as a string with escapes variables (or concatenation), or in a separate file using the template language.

+2
source

Source: https://habr.com/ru/post/896607/


All Articles