Automate Tasks using Java Groovy Scripts

DbSchema can automate different processes using Java Groovy scripts with direct access to the DbSchema API.

DbSchema API

Groovy is a pure Java language with closures, known for being used by Gradle. The variables in ${...} are evaluated. The scripts can be edited and tested in the SQL Editor.

// Copy code in DbSchema SQL Editor and choose Groovy
sql.eachRow("select * from address") { r ->
    println "Gromit likes ${r.address_id}"
}
String multiline = """I am a multiline
text"""
Automate Database Processes

The following variables are exposed directly to the Groovy script engine :

sql The physical connection to the database.
project The DbSchema project, with schemes, tables, columns, etc..
out The Result Pane print stream.

Run in Headless Mode

DbSchema can start in headless mode (no interface) and execute Groovy scripts using: Dbschema.exe -x <path-to-script>.

To start DbSchema in headless mode use java -cp "lib/*" com.wisecoders.dbs.DbSchema -x path_to_sample_script.

Adding further parameters to the command will pass this variables as an array under the variable parameters.

Groovy Scripts Samples

In the Tools / Automation Scripts you can find different code samples.

Code Samples Dialog

If you wish, our team can help you to write your own script. Please write us using Help / Contact Support.