1

Improve demo documentation

This commit is contained in:
2018-05-05 19:18:13 +03:00
parent 880e159fe8
commit da1564a0cc

View File

@@ -1,42 +1,67 @@
import com.devsoap.dbt.DBTModule import com.devsoap.dbt.DBTModule
import com.devsoap.dbt.config.DBTConfig
import com.devsoap.dbt.demo.DatabaseService
import com.devsoap.dbt.services.TransactionManagerService import com.devsoap.dbt.services.TransactionManagerService
import org.flywaydb.core.Flyway
import org.h2.jdbcx.JdbcDataSource import org.h2.jdbcx.JdbcDataSource
import ratpack.form.Form import ratpack.form.Form
import ratpack.handlebars.HandlebarsModule import ratpack.handlebars.HandlebarsModule
import ratpack.http.Status import ratpack.http.Status
import ratpack.service.Service
import javax.sql.DataSource import javax.sql.DataSource
import static ratpack.groovy.Groovy.ratpack import static ratpack.groovy.Groovy.ratpack
import static ratpack.handlebars.Template.handlebarsTemplate import static ratpack.handlebars.Template.handlebarsTemplate
/*
* Ratpack main configuration
*/
ratpack { ratpack {
serverConfig { /*
sysProps() * Configure application bindings
require('/dbt', DBTConfig) */
}
bindings { bindings {
/*
* Render views with Handlebars
*/
module HandlebarsModule module HandlebarsModule
module (DBTModule) { /*
it.ledger.remoteUrl = 'http://localhost:5050/ledger' * Configure dbt module to point to correct ledger and executor instances
it.executor.remoteUrl = 'http://localhost:5050/executor' */
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: '')) 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 { handlers {
/*
* Render index.html at root url
*/
get { get {
render handlebarsTemplate('index.html') render handlebarsTemplate('index.html')
} }
/*
* Adds a new query to the current transaction
*/
post('addQueryToTransaction') { post('addQueryToTransaction') {
def transactionManager = get(TransactionManagerService) def transactionManager = get(TransactionManagerService)
parse(Form).then { Form form -> 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') { post('executeTransaction') {
def transactionManager = get(TransactionManagerService) def transactionManager = get(TransactionManagerService)
parse(Form).then { Form form -> parse(Form).then { Form form ->
@@ -73,6 +101,9 @@ ratpack {
} }
} }
/*
* Adds the query to a new transaction and executes the transaction immediately
*/
post('executeQuery') { post('executeQuery') {
def transactionManager = get(TransactionManagerService) def transactionManager = get(TransactionManagerService)
parse(Form).then { Form form -> parse(Form).then { Form form ->