stephencelis / SQLite.swift

A type-safe, Swift-language layer over SQLite3.
MIT License
9.72k stars 1.57k forks source link

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

Open ivanlares opened 10 months ago

ivanlares commented 10 months ago

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 🙇