@fabrika/db 0.9.0-dev.62 → 0.9.0-dev.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/db",
3
- "version": "0.9.0-dev.62",
3
+ "version": "0.9.0-dev.64",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "./src/testing.ts",
@@ -96,9 +96,9 @@
96
96
  "test": "bun test"
97
97
  },
98
98
  "dependencies": {
99
- "@fabrika/auth-core": "0.9.0-dev.62",
100
- "@fabrika/platform": "0.9.0-dev.62",
101
- "@fabrika/platform-node": "0.9.0-dev.62",
99
+ "@fabrika/auth-core": "0.9.0-dev.64",
100
+ "@fabrika/platform": "0.9.0-dev.64",
101
+ "@fabrika/platform-node": "0.9.0-dev.64",
102
102
  "kysely": "0.29.6",
103
103
  "kysely-postgres-js": "5.0.1",
104
104
  "zod": "^3.25.76"
@@ -122,14 +122,15 @@ function introspect(db: Database): { columns: SqliteColumn[]; foreignKeys: Forei
122
122
  if (table.type === 'virtual') throw new CodegenError(`table ${table.name} is a virtual table, which the data layer does not read`)
123
123
  const declared = z.array(columnSchema).parse(db.query('SELECT * FROM pragma_table_xinfo(?) ORDER BY cid').all(table.name))
124
124
  const keyColumns = declared.filter((column) => column.pk > 0)
125
- const unique = new Set(
126
- z.array(z.object({ name: z.string().nullable() })).parse(
127
- db.query(`SELECT i.name FROM pragma_index_list(?1) l, pragma_index_info(l.name) i WHERE l."unique" = 1`).all(table.name),
128
- ).map((column) => column.name),
125
+ const indexed = z.array(z.object({ name: z.string().nullable(), unique: z.number(), origin: z.string() })).parse(
126
+ db.query(`SELECT i.name, l."unique", l.origin FROM pragma_index_list(?1) l, pragma_index_info(l.name) i`).all(table.name),
129
127
  )
128
+ const unique = new Set(indexed.filter((column) => column.unique === 1).map((column) => column.name))
129
+ // SQLite indexes a primary key apart (index origin `pk`) unless it is the rowid, which `INTEGER PRIMARY KEY DESC` is not.
130
+ const keyIndexed = indexed.some((column) => column.origin === 'pk')
130
131
  for (const column of declared) {
131
- // An INTEGER PRIMARY KEY of a rowid table is the rowid: never null, assigned when an insert omits it.
132
- const rowid = table.wr === 0 && keyColumns.length === 1 && column.pk === 1 && column.type.trim().toUpperCase() === 'INTEGER'
132
+ // Otherwise an INTEGER PRIMARY KEY of a rowid table is the rowid: never null, assigned when an insert omits it.
133
+ const rowid = table.wr === 0 && !keyIndexed && keyColumns.length === 1 && column.pk === 1 && column.type.trim().toUpperCase() === 'INTEGER'
133
134
  const computed = column.hidden === 2 || column.hidden === 3
134
135
  columns.push({
135
136
  table_name: table.name,