Skip to content

Conversation

@GuilhE
Copy link

@GuilhE GuilhE commented Oct 31, 2024

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.

GuilhE added 3 commits August 18, 2024 15:28
Adds `extendedConfig` parameter to facilitate the configuration of an `in memory` `NativeSqliteDrive`, for instance, to enable `foreignKeyConstraints`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants