Gradle
build.gradle
:
sqldelight {
// Database name
MyDatabase {
// Package name used for the generated MyDatabase.kt
packageName = "com.example.db"
// An array of folders where the plugin will read your '.sq' and '.sqm'
// files. The folders are relative to the existing source set so if you
// specify ["db"], the plugin will look into 'src/main/db'.
// Defaults to ["sqldelight"] (src/main/sqldelight)
sourceFolders = ["sqldelight", "resources"]
// Optionally specify schema dependencies on other gradle projects
dependency project(':OtherProject')
// Whether or not to use .sqm files as the source of truth for the schema.
// Defaults to false
deriveSchemaFromMigrations = true
// If set, configures a task to output the .sqm migration files as valid SQL
// Defaults to null
migrationOutputDirectory = file("$buildDir/resources/main/migrations")
// The extension format to use for generated valid SQL migrations.
// Defaults to ".sql"
migrationOutputFileFormat = ".sql"
}
}
If you're using Kotlin for your Gradle files:
build.gradle.kts
sqldelight {
database("MyDatabase") {
packageName = "com.example.db"
sourceFolders = ["sqldelight", "resources"]
dependency project(':OtherProject')
deriveSchemaFromMigrations = true
migrationOutputDirectory = file("$buildDir/resources/main/migrations")
migrationOutputFileFormat = ".sql"
}
}
Dependencies
You can specify schema dependencies on another module:
sqldelight {
MyDatabase {
package = "com.example.projecta"
dependency project(":ProjectB")
}
}
This looks for MyDatabase
in ProjectB
and includes it's schema when compiling. For this to work,
ProjectB must have a database with the same name (MyDatabase
in this case) but generate in a
different package, so here is what ProjectB
's gradle might look like:
sqldelight {
MyDatabase {
package = "com.example.projectb"
}
}