sqldelight
sqldelight copied to clipboard
Facilitate the configuration of an in memory NativeSqliteDrive
Adds extendedConfig parameter to facilitate the configuration of an in memory NativeSqliteDrive, for instance, to enable foreignKeyConstraints.
The value is:
@OptIn(ExperimentalObjCRefinement::class)
@HiddenFromObjC
actual fun databaseDiTestModule(): Module = module {
single { Dao(inMemoryDriver(Database.Schema, extendedConfig = DatabaseConfiguration.Extended(foreignKeyConstraints = true))) }
}
vs
@OptIn(ExperimentalObjCRefinement::class)
@HiddenFromObjC
actual fun databaseDiTestModule(): Module = module {
single {
val schema = Database.Schema
Dao(
NativeSqliteDriver(
DatabaseConfiguration(
name = null,
inMemory = true,
version = if (schema.version > Int.MAX_VALUE) error("Schema version is larger than Int.MAX_VALUE: ${schema.version}.") else schema.version.toInt(),
create = { connection -> wrapConnection(connection) { schema.create(it) } },
upgrade = { connection, oldVersion, newVersion ->
wrapConnection(connection) { schema.migrate(it, oldVersion.toLong(), newVersion.toLong()) }
},
extendedConfig = DatabaseConfiguration.Extended(foreignKeyConstraints = true)
)
)
)
}
}
Not having this method makes me copy paste all the other configurations.