Skip to content

Facilitate the configuration of an in memory NativeSqliteDrive #5539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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 2 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.

1 participant