What are the differences in executing prepared statemenst?

Hi everyone! Given the following examples from the docs:
const p1 = db
.select()
.from(customers)
.where(eq(customers.id, sql.placeholder('id')))
.prepare()

p1.get({ id: 10 }) // SELECT * FROM customers WHERE id = 10
p1.get({ id: 12 }) // SELECT * FROM customers WHERE id = 12

const p2 = db
.select()
.from(customers)
.where(sql`lower(${customers.name}) like ${sql.placeholder('name')}`)
.prepare();

p2.all({ name: '%an%' })
const p1 = db
.select()
.from(customers)
.where(eq(customers.id, sql.placeholder('id')))
.prepare()

p1.get({ id: 10 }) // SELECT * FROM customers WHERE id = 10
p1.get({ id: 12 }) // SELECT * FROM customers WHERE id = 12

const p2 = db
.select()
.from(customers)
.where(sql`lower(${customers.name}) like ${sql.placeholder('name')}`)
.prepare();

p2.all({ name: '%an%' })
What exactly is the difference between get and all?
2 Replies
Linus
LinusOP14mo ago
Does get just return the first row?
Angelelz
Angelelz14mo ago
GitHub
better-sqlite3/docs/api.md at master · WiseLibs/better-sqlite3
The fastest and simplest library for SQLite3 in Node.js. - WiseLibs/better-sqlite3
Want results from more Discord servers?
Add your server