docs/common/gradle.md
For greater customization, you can declare databases explicitly using the Gradle DSL.
databasesContainer for databases. Configures SQLDelight to create each database with the given name.
=== "Kotlin"
kotlin sqldelight { databases { create("MyDatabase") { // Database configuration here. } } }
=== "Groovy"
groovy sqldelight { databases { MyDatabase { // Database configuration here. } } }
linkSqliteType: Property<Boolean>
For native targets. Whether sqlite should be automatically linked. This adds the necessary metadata for linking sqlite when the project is compiled to a dynamic framework (which is the default in recent versions of KMP).
Note that for a static framework, this flag has no effect.
The XCode build that imports the project should add -lsqlite3 to the linker flags.
Alternatively add a project dependency on the sqlite3 pod via the cocoapods plugin.
Another option that may work is adding sqlite3 to the cocoapods spec.libraries setting e.g. in Gradle Kotlin DSL: extraSpecAttributes["libraries"] = "'c++', 'sqlite3'".
Defaults to true.
=== "Kotlin"
kotlin linkSqlite.set(true)
=== "Groovy"
groovy linkSqlite = true
packageNameType: Property<String>
Package name used for the database class.
=== "Kotlin"
kotlin packageName.set("com.example.db")
=== "Groovy"
groovy packageName = "com.example.db"
srcDirsType: ConfigurableFileCollection
A collection of folders that the plugin will look in for your .sq and .sqm files.
Defaults to src/[prefix]main/sqldelight with prefix depending on the applied kotlin plugin eg common for multiplatform.
=== "Kotlin"
kotlin srcDirs.setFrom("src/main/sqldelight")
=== "Groovy"
groovy srcDirs = ['src/main/sqldelight']
srcDirs(vararg objects: Any)A collection of objects that the plugin will look in for your .sq and .sqm files.
=== "Kotlin"
kotlin srcDirs("src/main/sqldelight", "main/sqldelight")
=== "Groovy"
groovy srcDirs('src/main/sqldelight', 'main/sqldelight')
schemaOutputDirectoryType: DirectoryProperty
The directory where .db schema files should be stored, relative to the project root.
These files are used to verify that migrations yield a database with the latest schema.
Defaults to null.
If null, the migration verification tasks will not be created.
=== "Kotlin"
kotlin schemaOutputDirectory.set(file("src/main/sqldelight/databases"))
=== "Groovy"
groovy schemaOutputDirectory = file("src/main/sqldelight/databases")
dependencyType: Project
Optionally specify schema dependencies on other gradle projects (see below).
=== "Kotlin"
kotlin dependency(project(":other-project"))
=== "Groovy"
groovy dependency project(":other-project")
dialectType: String or Provider<MinimalExternalModuleDependency>
The SQL dialect you would like to target. Dialects are selected using a gradle dependency.
These dependencies can be specified as app.cash.sqldelight:{dialect module}:{{ versions.sqldelight }}.
See below for available dialects.
For Android projects, the SQLite version is automatically selected based on your minSdk.
Otherwise defaults to SQLite 3.18.
Available dialects:
hsql-dialectmysql-dialectpostgresql-dialectsqlite-3-18-dialectsqlite-3-24-dialectsqlite-3-25-dialectsqlite-3-30-dialectsqlite-3-33-dialectsqlite-3-35-dialectsqlite-3-38-dialect=== "Kotlin"
kotlin dialect("app.cash.sqldelight:sqlite-3-24-dialect:{{ versions.sqldelight }}")
=== "Groovy"
groovy dialect 'app.cash.sqldelight:sqlite-3-24-dialect:{{ versions.sqldelight }}'
verifyMigrationsType: Property<Boolean>
If set to true, migration files will fail during the build process if there are any errors in them.
Defaults to false.
=== "Kotlin"
kotlin verifyMigrations.set(true)
=== "Groovy"
groovy verifyMigrations = true
treatNullAsUnknownForEqualityType: Property<Boolean>
If set to true, SQLDelight will not replace an equality comparison with a nullable typed value when using IS.
Defaults to false.
=== "Kotlin"
kotlin treatNullAsUnknownForEquality.set(true)
=== "Groovy"
groovy treatNullAsUnknownForEquality = true
generateAsyncType: Property<Boolean>
If set to true, SQLDelight will generate suspending query methods for use with asynchronous drivers.
Defaults to false.
=== "Kotlin"
kotlin generateAsync.set(true)
=== "Groovy"
groovy generateAsync = true
deriveSchemaFromMigrationsType: Property<Boolean>
If set to true, the schema for your database will be derived from your .sqm files as if each migration had been applied.
If false, your schema is defined in .sq files.
Defaults to false.
=== "Kotlin"
kotlin deriveSchemaFromMigrations.set(true)
=== "Groovy"
groovy deriveSchemaFromMigrations = true
expandSelectStarType: Property<Boolean>
If set to true, SQLDelight will rewrite SELECT * statements to explicitly reference each of the actual resulting columns.
For example, the getAll query below
CREATE TABLE hockey_player (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
number INTEGER NOT NULL
);
getAll:
SELECT * FROM hockey_player;
will be rewritten as SELECT hockey_player.id, hockey_player.name, hockey_player.number FROM hockey_player;.
Defaults to true.
=== "Kotlin"
kotlin expandSelectStar.set(true)
=== "Groovy"
groovy expandSelectStar = true
{% include 'common/gradle-dependencies.md' %}