Created
May 9, 2019 07:48
-
-
Save Ciantic/8e6e1e077e67d51266d6495af34db6e5 to your computer and use it in GitHub Desktop.
SQLite Row values does not seem to work, my test case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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