Automation using Scripts

DbSchema you 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. Notice the variables in ${...} are replaced in GStrings. Groovy is known for being used in Gradle. 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
Automate Database Processes

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

sql The physical connection to the database.
project The DbSchema model, with schemes, tables, columns, etc..
out The PrintStream out console output stream, visible in the Script Result Pane.

Headless Mode

DbSchema can start in console mode and execute Groovy script using: Dbschema.exe -x <path-to-script>.

To start DbSchema in headless mode ( no splash screen ) 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.

Automation Scripts Examples

A bunch of Groovy scripts are available in the Code Samples Dialog, which can be found in the SQL Editor under the Help Menu.or Code Samples Dialog

If you wish, we can help you to write your own script. Please contact us from the DbSchema Help menu.