Skip to content

Instantly share code, notes, and snippets.

@johnrengelman
Created February 19, 2014 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnrengelman/9095118 to your computer and use it in GitHub Desktop.
Save johnrengelman/9095118 to your computer and use it in GitHub Desktop.
Groovy SQL DSL
select('foo') {
eq('id', 1)
projections {
property('bar')
}
}
result: 'SELECT bar FROM foo WHERE id = 1;'
@johnrengelman
Copy link
Author

The idea here is for a tool that can randomize information in any DB. So the user provides a config file:

schema('test') {
  foo {
    name = person().name()
  }
}

This would basically create a random String value for name and update the foo table a new random value for each row.
Additionally, I want to add a raw SQL section using a concise DSL.

schema('test') {
  foo {
    name = person().name()
  }
  postProcessing {
    sql(update('foo') {
       set {
         eq('last_name', 'name')
       }
    }
  }
}

The idea here would be that the postProcessing block would contain a SQL string that says UPDATE foo SET last_name = name and that would get executed after the fact.

Since this tool doesn't know the database it will be running against, I can't generate the classes for the tables/columns for something like jOOQ (AFAIK, it doesn't provide an API for interacting through strings, kind of defeats the type safety).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment