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

Provide configuration hook in constructor of NativeSqliteDriver #3493

Closed
svenjacobs opened this issue Sep 9, 2022 · 0 comments · Fixed by #3512
Closed

Provide configuration hook in constructor of NativeSqliteDriver #3493

svenjacobs opened this issue Sep 9, 2022 · 0 comments · Fixed by #3512
Labels

Comments

@svenjacobs
Copy link
Contributor

svenjacobs commented Sep 9, 2022

Description

As commented here I would like to suggest an enhancement of the NativeSqliteDriver constructor.

For example if I just want to enable foreign keys, I have to write a lot of boiler plate code. I suggest an optional onConfiguration callback to hook into the configuration.

constructor(
    schema: SqlDriver.Schema,
    name: String,
    maxReaderConnections: Int = 1,
    onConfiguration: (DatabaseConfiguration) -> DatabaseConfiguration = { it },
) : this(
    configuration = DatabaseConfiguration(
        name = name,
        version = schema.version,
        create = { connection ->
            wrapConnection(connection) { schema.create(it) }
        },
        upgrade = { connection, oldVersion, newVersion ->
            wrapConnection(connection) { schema.migrate(it, oldVersion, newVersion) }
        }
    ).let(onConfiguration),
    maxReaderConnections = maxReaderConnections
)

Usage would look like

NativeSqliteDriver(
    schema = Database.Schema, 
    name = "database.db",
    onConfiguration = { config ->
        config.copy(
            extendedConfig = DatabaseConfiguration.Extended(
                foreignKeyConstraints = true,
            )
        )
    }
)

I'm happy to provide a pull request if this is a desired change.

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

Successfully merging a pull request may close this issue.

1 participant