Add biome

This commit is contained in:
Endeavorance 2025-04-06 19:28:42 -04:00
parent 09d25c926c
commit 6479d09196
9 changed files with 586 additions and 538 deletions

View file

@ -3,143 +3,143 @@ import { SchemaError } from "../src/error";
import { Prequel, Table } from "../src/index";
interface User {
user_id: number;
name: string;
user_id: number;
name: string;
}
test("constructor", () => {
const pq = new Prequel();
const users = pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
const pq = new Prequel();
const users = pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
users.insertPartial({ name: "Yondu" });
users.insertPartial({ name: "Yondu" });
expect(users.findAll().length).toBe(1);
expect(users.findAll().length).toBe(1);
});
test(".hasTable() knows if a table exists in the DB", () => {
const pq = new Prequel();
const pq = new Prequel();
expect(pq.hasTable("Users")).toBeFalse();
expect(pq.hasTable("Notfound")).toBeFalse();
expect(pq.hasTable("Users")).toBeFalse();
expect(pq.hasTable("Notfound")).toBeFalse();
pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
expect(pq.hasTable("Users")).toBeTrue();
expect(pq.hasTable("Notfound")).toBeFalse();
expect(pq.hasTable("Users")).toBeTrue();
expect(pq.hasTable("Notfound")).toBeFalse();
});
test(".table() creates and attaches a table", () => {
const pq = new Prequel();
const pq = new Prequel();
// Already has one table because of KV
expect(Object.keys(pq.tables)).toHaveLength(1);
// Already has one table because of KV
expect(Object.keys(pq.tables)).toHaveLength(1);
const table = pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
const table = pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
expect(Object.keys(pq.tables)).toHaveLength(2);
expect(Object.values(pq.tables)).toContain(table);
expect(Object.keys(pq.tables)).toHaveLength(2);
expect(Object.values(pq.tables)).toContain(table);
});
test(".table() throws when creating a duplicate table", () => {
const pq = new Prequel();
pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
const pq = new Prequel();
pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
const oopsie = () => {
pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
};
const oopsie = () => {
pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
};
expect(oopsie).toThrow(SchemaError);
expect(oopsie).toThrow(SchemaError);
});
test(".attachTable() attaches a table", () => {
const pq = new Prequel();
const table = new Table<User>(pq.db, "Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
const pq = new Prequel();
const table = new Table<User>(pq.db, "Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
expect(pq.hasTable("Users")).toBeFalse();
expect(pq.hasTable("Users")).toBeFalse();
pq.attachTable(table);
pq.attachTable(table);
expect(pq.hasTable("Users")).toBeTrue();
expect(Object.values(pq.tables)).toContain(table);
expect(pq.hasTable("Users")).toBeTrue();
expect(Object.values(pq.tables)).toContain(table);
});
test(".attachTable() throws on duplicate table names", () => {
const pq = new Prequel();
pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
const pq = new Prequel();
pq.table<User>("Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
const secondTable = new Table<User>(pq.db, "Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
const secondTable = new Table<User>(pq.db, "Users", {
user_id: {
type: "INTEGER",
primary: true,
},
name: "TEXT",
});
const doAttachment = () => {
pq.attachTable(secondTable);
};
const doAttachment = () => {
pq.attachTable(secondTable);
};
expect(doAttachment).toThrow(SchemaError);
expect(doAttachment).toThrow(SchemaError);
});
test("kv store can set and retrieve arbitrary values", () => {
const pq = new Prequel();
const pq = new Prequel();
pq.kv.put<number>("answer", 42);
pq.kv.put<{ enabled: boolean }>("config", { enabled: true });
pq.kv.put<string[]>("list", ["a", "b", "c"]);
pq.kv.put<number>("answer", 42);
pq.kv.put<{ enabled: boolean }>("config", { enabled: true });
pq.kv.put<string[]>("list", ["a", "b", "c"]);
expect(pq.kv.get<number>("answer")).toEqual(42);
expect(pq.kv.get<{ enabled: boolean }>("config")).toEqual({ enabled: true });
expect(pq.kv.get<string[]>("list")).toEqual(["a", "b", "c"]);
expect(pq.kv.get<number>("answer")).toEqual(42);
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");
const pq = new Prequel();
const query = pq.query("SELECT 1");
expect(query).toBeDefined();
expect(query).toBe(pq.query("SELECT 1"));
expect(query).toBeDefined();
expect(query).toBe(pq.query("SELECT 1"));
});