Quick Start
-
Add Norm’s Gradle plugin to your data-access project in case of a multi-module project, or to the root project
plugins { id 'com.medly.norm' version '0.0.6' }
-
Configure the plugin.
norm { jdbcUrl = "jdbc:postgresql://localhost/postgres" username = "postgres" password = "" inputDir = file("src/main/sql") outDir = file("src/main/gen") basePath = file("src/main/gen") }
The database
jdbcUrl
,username
, andpassword
here refer to local PostgreSQL instance. Also it is highly recommended to use a schema migration utility like Liquibase or Flyway to manage schema versioning. -
Create a sql file in
inputDir
under a directory path which should reflect our package name e.gcom/foo/person-by-age.sql
SELECT * FROM persons WHERE AGE > :age;
-
Generate the kotlin code using the gradle task
$ ./gradlew normCodegen
-
Access the database. we should inject the
datasource
object using IoC framework like Spring or Micronaut.datasource.connection.use { connection -> FindPersonQuery().query(connection, FindPersonParams("28")) }.forEach { println(it.toString()) }