Composable, parameterized SQL statements
A sql
function that will automatically create parameterized queries from a kotlin string template
The following are equivalent and both may be composed with other SqlStatement
s in the same way
val sql = "SELECT * FROM foo"
val sqlStatement = sql("SELECT * FROM foo")
val sqlStatement = sql("SELECT * FROM foo WHERE id = ${sqlParameter("myFoo")}")
val sqlStatement = sql("SELECT * FROM foo WHERE bar_id IN (${createIdSelect()})")
fun createIdSelect() = sql("SELECT id from bar WHERE baz > 10")
A programatic way to add multiple WHERE
clauses without having to worry about WHERE
vs AND
val sqlStatement = sql("SELECT * FROM foo ${where("bar > 10", sql("baz = ${SqlParameter("myBaz")}"))}")
A set of functions for converting a SqlStatement into the corresponding sql and parameters for different libraries/drivers
val (sql, parameters) = generateJavaSql(sqlStatement)
val sqlWithParameters = generateTestSql(sqlStatement)
You will need:
- A maven central account (See https://central.sonatype.org/register/central-portal/)
- A verified groupId of "com.urbn.nu" (See https://central.sonatype.org/register/namespace/)
- A GPG Key for signing artifacts (See https://central.sonatype.org/publish/requirements/gpg/)
- A portal token (See https://central.sonatype.org/publish/generate-portal-token/)
- Ensure
version
property in lib/build.gradle ends with "-SNAPSHOT" - Setup credentials in
$HOME/.gradle/gradle.properties
(See below) - Run
./gradlew :lib:publish
# GPG Signing
signing.keyId=12345678 # Last 8 digits of GPG key id
signing.password=<insert gpg key passphrase>
signing.secretKeyRingFile=$HOME/.gnupg/secring.gpg
# Maven Central Auth
mavenCentralUsername=<insert portal token username>
mavenCentralPassword=<insert portal token password>
These are the steps to do an official release to maven central. Please test with SNAPSHOT releases before running these steps
- Ensure
version
property in lib/build.gradle is properly set to next version - Run
./gradlew :lib:publish
- Run
cd lib/build/repos/releases/
- Run
tar -czvf gradle-publish-sqlkraft-<insert_version_number>.tar.gz com
- Upload tar file using publish portal (See https://central.sonatype.org/publish/publish-portal-upload/)
- Tag the current commit and push:
git tag -a v<version> -m "Release <version>"