diff --git a/dbt-demo/src/ratpack/Ratpack.groovy b/dbt-demo/src/ratpack/Ratpack.groovy index 82feb99..e60cd44 100644 --- a/dbt-demo/src/ratpack/Ratpack.groovy +++ b/dbt-demo/src/ratpack/Ratpack.groovy @@ -1,42 +1,67 @@ import com.devsoap.dbt.DBTModule -import com.devsoap.dbt.config.DBTConfig -import com.devsoap.dbt.demo.DatabaseService import com.devsoap.dbt.services.TransactionManagerService +import org.flywaydb.core.Flyway import org.h2.jdbcx.JdbcDataSource import ratpack.form.Form import ratpack.handlebars.HandlebarsModule import ratpack.http.Status +import ratpack.service.Service import javax.sql.DataSource import static ratpack.groovy.Groovy.ratpack import static ratpack.handlebars.Template.handlebarsTemplate +/* + * Ratpack main configuration + */ ratpack { - serverConfig { - sysProps() - require('/dbt', DBTConfig) - } - + /* + * Configure application bindings + */ bindings { + + /* + * Render views with Handlebars + */ module HandlebarsModule - module (DBTModule) { - it.ledger.remoteUrl = 'http://localhost:5050/ledger' - it.executor.remoteUrl = 'http://localhost:5050/executor' + /* + * Configure dbt module to point to correct ledger and executor instances + */ + module (DBTModule) { config -> + config.ledger.remoteUrl = 'http://localhost:5050/ledger' + config.executor.remoteUrl = 'http://localhost:5050/executor' } + /* + * Configure data source to use H2 in-memory database + */ bindInstance(DataSource, new JdbcDataSource(url: 'jdbc:h2:mem:dbtdb;DB_CLOSE_DELAY=-1', user: '')) - bind DatabaseService + + /* + * Migrate Flyway migrations at application start + */ + bindInstance { event -> new Flyway(dataSource: event.registry.get(DataSource)).migrate() } as Service } + + /* + * Configure API endpoints + */ handlers { + /* + * Render index.html at root url + */ get { render handlebarsTemplate('index.html') } + /* + * Adds a new query to the current transaction + */ post('addQueryToTransaction') { def transactionManager = get(TransactionManagerService) parse(Form).then { Form form -> @@ -58,6 +83,9 @@ ratpack { } } + /* + * Executes the current transaction by marking the transaction as complete and executing the transaction + */ post('executeTransaction') { def transactionManager = get(TransactionManagerService) parse(Form).then { Form form -> @@ -73,6 +101,9 @@ ratpack { } } + /* + * Adds the query to a new transaction and executes the transaction immediately + */ post('executeQuery') { def transactionManager = get(TransactionManagerService) parse(Form).then { Form form ->