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

Feature Request: Make Connection's userVersion property non optional #1233

Open
ivanlares opened this issue Jan 3, 2024 · 0 comments
Open

Comments

@ivanlares
Copy link
Contributor

Hello, I was wondering if it would make sense to update the type for Connection.userVersion and make it a non optional.

It seems like the default value for userVersion is 0, this can potentially be a source of confusion.
Since value is an Optional, one could assume that the default value would be nil.

Example Code

        let userVersion = try! Connection(".../myDB.sqlite3").userVersion
        print(userVersion) // Optional(0)

Proposed Change

    /// The user version of the database.
    /// See SQLite [PRAGMA user_version](https://sqlite.org/pragma.html#pragma_user_version)
    ///
    /// Defaults to 0.
    var userVersion: UserVersion {
        get {
            (try? scalar("PRAGMA user_version") as? Int64).map(Int32.init) ?? 0 
        }
        set {
            _ = try? run("PRAGMA user_version = \(newValue ?? 0)")
        }
    }

I would be happy to create a pull request if this change make sense, thank you 🙇

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

No branches or pull requests

1 participant