Skip to content

Instantly share code, notes, and snippets.

@Ciantic
Created May 9, 2019 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ciantic/8e6e1e077e67d51266d6495af34db6e5 to your computer and use it in GitHub Desktop.
Save Ciantic/8e6e1e077e67d51266d6495af34db6e5 to your computer and use it in GitHub Desktop.
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