Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the parameterized "IN" operator in prepared statments? #881

Closed
h-sifat opened this issue Oct 7, 2022 · 2 comments
Closed

How to use the parameterized "IN" operator in prepared statments? #881

h-sifat opened this issue Oct 7, 2022 · 2 comments

Comments

@h-sifat
Copy link

h-sifat commented Oct 7, 2022

Sorry for bothering you guys. I'm trying to delete multiple records using the IN operator but it's not working.

Example:

const Sqlite = require("better-sqlite3");

const db = new Sqlite(":memory:");

db.exec(`create table if not exists categories(
  id integer primary key,
  name text not null,
  parentId integer default null
    references categories(id)
    on update cascade
    on delete restrict
);

insert into categories (name) values ('A'), ('B'), ('C');`);

const findAll = db.prepare(`select * from categories;`);

console.log(findAll.all());

const stmt = db.prepare(`delete from categories where id in ($ids);`);

const ids = [1, 2, 3].join(", ");
console.log(stmt.run({ ids }));

console.log(findAll.all());

Does better-sqlite3 not support parameterized IN operator? If it doesn't than should I delete records one by one inside a transaction?

Thanks in advance 💝

@Prinzhorn
Copy link
Contributor

#283

@h-sifat
Copy link
Author

h-sifat commented Oct 7, 2022

#283

Thanks for the mention. I've got what I needed.
I actually tried to search the issues before opening this one but couldn't find one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants