1.1.0
This commit is contained in:
parent
13c3d86a10
commit
20ac2da081
6 changed files with 47 additions and 10 deletions
|
@ -135,3 +135,11 @@ test("kv store can set and retrieve arbitrary values", () => {
|
|||
expect(pq.kv.get<{ enabled: boolean }>("config")).toEqual({ enabled: true });
|
||||
expect(pq.kv.get<string[]>("list")).toEqual(["a", "b", "c"]);
|
||||
});
|
||||
|
||||
test(".query() creates a cached statement", () => {
|
||||
const pq = new Prequel();
|
||||
const query = pq.query("SELECT 1");
|
||||
|
||||
expect(query).toBeDefined();
|
||||
expect(query).toBe(pq.query("SELECT 1"));
|
||||
});
|
||||
|
|
|
@ -138,6 +138,22 @@ test(".insertPartial() inserts a partial row", () => {
|
|||
});
|
||||
});
|
||||
|
||||
test(".insertWithout() inserts a partial row with type safety", () => {
|
||||
const table = makeTestTable();
|
||||
table.insertWithout<"user_id">({
|
||||
name: "Jack",
|
||||
});
|
||||
|
||||
const lookup = table.db.prepare<UserWithID, string>(
|
||||
`SELECT * FROM ${table} WHERE name = ?`,
|
||||
);
|
||||
const found = lookup.get("Jack");
|
||||
expect(found).toEqual({
|
||||
user_id: 1,
|
||||
name: "Jack",
|
||||
});
|
||||
});
|
||||
|
||||
test(".count() gets the current number of rows in the table", () => {
|
||||
const table = makeTestTable();
|
||||
table.insertPartial({ name: "Jack" });
|
||||
|
@ -167,6 +183,12 @@ test(".findAll() returns the full table", () => {
|
|||
expect(allUsers[2]).toEqual({ user_id: 3, name: "Sayid" });
|
||||
});
|
||||
|
||||
test(".query() returns a prepared statement for the table", () => {
|
||||
const table = makeTestTable();
|
||||
const query = table.query("SELECT * FROM Users WHERE name = ?");
|
||||
expect(query).toBeDefined();
|
||||
});
|
||||
|
||||
test(".findOneWhere() returns a row based on basic criteria", () => {
|
||||
const table = makeTestTable();
|
||||
table.insertPartial({ name: "Jack" });
|
||||
|
|
|
@ -7,10 +7,6 @@ interface User {
|
|||
name: string;
|
||||
}
|
||||
|
||||
interface SerializedUser {
|
||||
name: string;
|
||||
}
|
||||
|
||||
const db = new Database();
|
||||
const table = new Table<User>(db, "Users", {
|
||||
id: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue