Skip to content

Gradle

For greater customization, you can declare databases explicitly using the Gradle DSL.

SQLDelight Configuration

databases

Container for databases. Configures SQLDelight to create each database with the given name.

sqldelight {
  databases {
    create("MyDatabase") {
      // Database configuration here.
    }
  }
}
sqldelight {
  databases {
    MyDatabase {
      // Database configuration here.
    }
  }
}

linkSqlite

Type: Property<Boolean>

For native targets. Whether sqlite should be automatically linked.

Defaults to true.

linkSqlite.set(true)
linkSqlite = true

Database Configuration

packageName

Type: Property<String>

Package name used for the database class.

packageName.set("com.example.db")
packageName = "com.example.db"

srcDirs

Type: 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.

srcDirs.setFrom("src/main/sqldelight")
srcDirs = ['src/main/sqldelight']

srcDirs(vararg objects: Any)

A collection of objects that the plugin will look in for your .sq and .sqm files.

srcDirs("src/main/sqldelight", "main/sqldelight")
srcDirs('src/main/sqldelight', 'main/sqldelight')

schemaOutputDirectory

Type: 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.

schemaOutputDirectory.set(file("src/main/sqldelight/databases"))
schemaOutputDirectory = file("src/main/sqldelight/databases")

dependency

Type: Project

Optionally specify schema dependencies on other gradle projects (see below).

dependency(project(":other-project"))
dependency project(":other-project")

dialect

Type: 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}:2.0.2. 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: hsql-dialect
  • MySQL: mysql-dialect
  • PostgreSQL: postgresql-dialect
  • SQLite 3.18: sqlite-3-18-dialect
  • SQLite 3.24: sqlite-3-24-dialect
  • SQLite 3.25: sqlite-3-25-dialect
  • SQLite 3.30: sqlite-3-30-dialect
  • SQLite 3.33: sqlite-3-33-dialect
  • SQLite 3.35: sqlite-3-35-dialect
  • SQLite 3.38: sqlite-3-38-dialect
dialect("app.cash.sqldelight:sqlite-3-24-dialect:2.0.2")
dialect 'app.cash.sqldelight:sqlite-3-24-dialect:2.0.2'

verifyMigrations

Type: Property<Boolean>

If set to true, migration files will fail during the build process if there are any errors in them.

Defaults to false.

verifyMigrations.set(true)
verifyMigrations = true

treatNullAsUnknownForEquality

Type: Property<Boolean>

If set to true, SQLDelight will not replace an equality comparison with a nullable typed value when using IS.

Defaults to false.

treatNullAsUnknownForEquality.set(true)
treatNullAsUnknownForEquality = true

generateAsync

Type: Property<Boolean>

If set to true, SQLDelight will generate suspending query methods for us with asynchronous drivers.

Defaults to false.

generateAsync.set(true)
generateAsync = true

deriveSchemaFromMigrations

Type: 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.

deriveSchemaFromMigrations.set(true)
deriveSchemaFromMigrations = true

Schema Dependencies

You can specify schema dependencies on another module:

// project-a/build.gradle.kts

sqldelight {
  databases {
    create("MyDatabase") {
      packageName.set("com.example.projecta")
      dependency(project(":ProjectB"))
    }
  }
}
// project-a/build.gradle

sqldelight {
  databases {
    MyDatabase {
      packageName = "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:

// project-b/build.gradle.kts

sqldelight {
  databases {
    // Same database name
    create("MyDatabase") {
      package = "com.example.projectb"
    }
  }
}
// project-b/build.gradle

sqldelight {
  databases {
    // Same database name
    MyDatabase {
      package = "com.example.projectb"
    }
  }
}

If you use deriveSchemaFromMigrations = true, every module depending on this module must also enable this feature.