-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
What version of drizzle-orm are you using?
0.31.2
What version of drizzle-kit are you using?
No response
Describe the Bug
Boolean columns always get set to 1 when using a prepared statement. It's working fine when not using a prepared statement.
Simple index.js to reproduce:
import Database from 'better-sqlite3'
import { drizzle } from 'drizzle-orm/better-sqlite3'
import { sql } from 'drizzle-orm'
import { sqliteTable, integer } from 'drizzle-orm/sqlite-core'
const sqlite = new Database('data.sqlite', { verbose: console.log })
sqlite.exec(
`CREATE TABLE foos (\
id INTEGER PRIMARY KEY,\
b1 INTEGER NOT NULL,\
b2 INTEGER NOT NULL\)`
)
const drizzleDB = drizzle(sqlite)
const foos = sqliteTable('foos', {
id: integer('id').notNull().primaryKey(),
b1: integer('b1', { mode: 'boolean' }).notNull(),
b2: integer('b2').notNull(),
})
drizzleDB.insert(foos).values({ id: 1, b1: false, b2: 0 }).run() // correct
drizzleDB.insert(foos).values({ id: 2, b1: true, b2: 1 }).run() // correct
const prep = drizzleDB
.insert(foos)
.values({
id: sql.placeholder('id'),
b1: sql.placeholder('b1'),
b2: sql.placeholder('b2'),
})
.prepare()
prep.run({ id: 3, b1: false, b2: 0 }) // wrong
prep.run({ id: 4, b1: true, b2: 1 }) // correctExpected behavior
CREATE TABLE foos ( id INTEGER PRIMARY KEY, b1 INTEGER NOT NULL, b2 INTEGER NOT NULL)
insert into "foos" ("id", "b1", "b2") values (1.0, 0.0, 0.0)
insert into "foos" ("id", "b1", "b2") values (2.0, 1.0, 1.0)
insert into "foos" ("id", "b1", "b2") values (3.0, 0.0, 0.0)
insert into "foos" ("id", "b1", "b2") values (4.0, 1.0, 1.0)Environment & setup
MacOS 14.5
better-sqlite3 11.0.0
SQLite 3.43.2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working