Provide a way to access auto-generated rowid on dataclasses
From the sqlite docs:
The rowid (and "oid" and "rowid") is omitted in WITHOUT ROWID tables. WITHOUT ROWID tables are only available in SQLite version 3.8.2 (2013-12-06) and later. A table that lacks the WITHOUT ROWID clause is called a "rowid table".
This poses an issue if one wants to access rowid on a table with a custom primaryKey, but not as a user-defined column
FWIW this has gotten a bit better now:
- In selects, you can access the rowid column in Dart and add it via a join or
selectOnly. - Recently (see the linked PR), the
rowidwould also be exposed on companions so it can be set to custom values for inserts or updates.
@simolus3 Is there a concise way to use selectOnly to get a select rowId, * from table?
That said, I don't entirely remember what I wanted rowId for in and haven't touched the Flutter app I was working on in a while, so I can't say if that solves my issue. Though, I'm guessing I explicitly wanted to access rowId from companions.
Is there a concise way to use
selectOnlyto get aselect rowId, * from table?
select(table).addColumns([table.rowId]) should work. You'll get a TypedResult back on which you can use readTable(table) to get the row class for the table and read(table.rowid) to get its rowid.