Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SQLite Row values does not seem to work, my test case
import sqlite3 from "sqlite3";
let db: any;
beforeEach(done => {
db = new sqlite3.Database(":memory:", () => {
db.run("CREATE TABLE foo (a INT, b INT)", done);
});
});
test("This is valid prepared statement with row values as an example", done => {
db.run("INSERT INTO foo VALUES (1,2), (2,3), (3,4)", (err: any) => {
db.all(
"SELECT * from foo WHERE (a,b) IN (VALUES (?, ?), (?, ?))",
[2, 3, 3, 4],
(err: any, rows: any) => {
expect(err).toBe(undefined);
expect(rows).toEqual([{ a: 2, b: 3 }, { a: 3, b: 4 }]);
done();
}
);
});
});
test("This is what I would like it to be, yet it fails", done => {
db.run("INSERT INTO foo VALUES (1,2), (2,3), (3,4)", (err: any) => {
db.all("SELECT * from foo WHERE (a,b) IN ?", [[2, 3], [3, 4]], (err: any, rows: any) => {
// It fails here with: Error: SQLITE_ERROR: near "?": syntax error
expect(err).toBe(undefined);
expect(rows).toEqual([{ a: 2, b: 3 }, { a: 3, b: 4 }]);
done();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.