Skip to content

SQLite does not support uint64 #97

Open
@danpalmer

Description

@danpalmer

Describe the issue

SQLite stores all integers signed, and up to 64 bits wide. Unsigned 64 bit integers therefore do not fit.

Vapor version

4.76.0

Operating system and version

macOS 15.0

Swift version

Swift Package Manager - Swift 6.0.0-dev

Steps to reproduce

  1. Create a model with a model with a UInt64 field type.
@Field(key: "foo")
var foo: UInt64
  1. Create a migration to add this model.
try await database.schema("bar")
    .field("foo", .uint64)
  1. Insert an item into the table with an integer that uses 64 bits of data.
var generator = SystemRandomNumberGenerator()
Bar(foo: generator.next()).create(on: db)

Outcome

Exception thrown from FixedWidthInteger in sqlite-nio / SQLiteDataEncoder.encode in sqlite-kit / FluentSQLiteDatabase.encode in fluent-sqlite-driver.

NIO-SGLTN-0-#0 (3): Fatal error: Not enough bits to represent the passed value

I spent a while debugging this, thinking I hadn't correctly configured the model or migration, only to eventually find that SQLite doesn't support unsigned 64-bit integers.


Given that the database itself does not support the data type, I'd expect some level of the stack to prevent me from doing this at an earlier stage than when I attempt to insert data. Two earlier opportunities that could make sense would be:

  1. When initialising Fluent, with a SQLite database driver, and a model with a UInt64 field.
  2. When running a migration against a SQLite database, setting a field type to UInt64.

Which package should this be solved in? This is certainly debatable. The guiding principle I think should be a good experience for Fluent users. sqlite-kit mostly seems to exist for Fluent, so perhaps in this repo or perhaps in that one. I think sqlite-nio is probably not the right place as it won't be aware of the model or migration layers (I assume?) and therefore probably doesn't have an earlier opportunity to alert the user, that package seems to be doing the right thing with this exception.

Additional notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions