Skip to content

Commit

Permalink
chore: save schema integers in INTEGER SQLite columns (#531)
Browse files Browse the repository at this point in the history
If we use the ["integer" JSON Schema type][0], we should save that as an
INTEGER column, not a REAL column. Both will work for many numbers, but
larger integers (like `2**63`) can only be safely stored in INTEGERs.
This should be a bit more reliable.

As of this patch, we don't have any integer types in our schemas, so
this has no effect. However, that may change as we address [upcoming
issues][1].

[0]: https://json-schema.org/understanding-json-schema/reference/numeric#integer
[1]: #150
  • Loading branch information
EvanHahn authored Mar 28, 2024
1 parent 3fda273 commit d5bf570
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/schema/schema-to-drizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ export function jsonSchemaToDrizzleColumns(schema) {
columns[key] = integer(key, { mode: 'boolean' })
break
case 'number':
case 'integer':
columns[key] = real(key)
break
case 'integer':
columns[key] = integer(key)
break
case 'string': {
const enumValue = isStringArray(value.enum)
? value.enum
Expand Down
2 changes: 1 addition & 1 deletion tests/schema/schema-to-drizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test('number', (t) => {

test('integer', (t) => {
const col = getColumn({ type: 'integer' })
t.is(col.getSQLType(), 'real', 'integers are stored in REAL columns')
t.is(col.getSQLType(), 'integer', 'integers are stored in INTEGER columns')
})

test('string', (t) => {
Expand Down

0 comments on commit d5bf570

Please sign in to comment.