Skip to content
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

Update NativeSqlDatabase.kt #5409

Closed
wants to merge 1 commit into from
Closed

Update NativeSqlDatabase.kt #5409

wants to merge 1 commit into from

Conversation

GuilhE
Copy link

@GuilhE GuilhE commented Aug 18, 2024

Adds extendedConfig parameter to facilitate the configuration of an in memory NativeSqliteDrive, for instance, to enable foreignKeyConstraints.

Adds `extendedConfig` parameter to facilitate the configuration of an `in memory` `NativeSqliteDrive`, for instance, to enable `foreignKeyConstraints`.
@AlecKazakova
Copy link
Collaborator

i dont see enough value here over the existing constructor with overloads to have it in the public api

@GuilhE
Copy link
Author

GuilhE commented Sep 5, 2024

i dont see enough value here over the existing constructor with overloads to have it in the public api

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
Copy link
Author

GuilhE commented Sep 6, 2024

@AlecKazakova any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants