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

SQLite does not support uint64 #97

Open
danpalmer opened this issue Aug 11, 2024 · 1 comment
Open

SQLite does not support uint64 #97

danpalmer opened this issue Aug 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@danpalmer
Copy link

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

@danpalmer danpalmer added the bug Something isn't working label Aug 11, 2024
@gwynne
Copy link
Member

gwynne commented Aug 11, 2024

The inability to diagnose this failure mode earlier in the process is an architectural issue inherent to some of Fluent 4's many, many design flaws. Since development of Fluent 4 has essentially ended, the expectation is to fix this in Fluent 5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants