Strict DB mode
This commit is contained in:
parent
ff7879dee7
commit
11b0598d46
6 changed files with 82 additions and 78 deletions
|
@ -1,20 +1,16 @@
|
|||
import { Database } from "bun:sqlite";
|
||||
import { expect, test } from "bun:test";
|
||||
import { ColumnOf, Prequel, Table } from "../src/index";
|
||||
import { Prequel, Table } from "../src/index";
|
||||
|
||||
function getTestDB() {
|
||||
return new Database(":memory:", { strict: true });
|
||||
}
|
||||
|
||||
interface UserWithID {
|
||||
user_id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface UserWithBio {
|
||||
user_id: number;
|
||||
bio: {
|
||||
name: string;
|
||||
age: number;
|
||||
};
|
||||
}
|
||||
|
||||
interface Post {
|
||||
post_id: number;
|
||||
user_id: number;
|
||||
|
@ -25,7 +21,7 @@ interface UserWithNullable extends UserWithID {
|
|||
}
|
||||
|
||||
function makeTestTable(): Table<UserWithID> {
|
||||
const db = new Database();
|
||||
const db = getTestDB();
|
||||
return new Table<UserWithID>(db, "Users", {
|
||||
user_id: {
|
||||
type: "INTEGER",
|
||||
|
@ -36,7 +32,7 @@ function makeTestTable(): Table<UserWithID> {
|
|||
}
|
||||
|
||||
test("constructor", () => {
|
||||
const db = new Database();
|
||||
const db = getTestDB();
|
||||
const table = new Table<UserWithID>(db, "Users", {
|
||||
user_id: {
|
||||
type: "INTEGER",
|
||||
|
@ -96,7 +92,7 @@ test(".insert() inserts a full row", () => {
|
|||
});
|
||||
|
||||
test(".insert() is able to insert nulls to nullable fields", () => {
|
||||
const table = new Table<UserWithNullable>(new Database(), "Users", {
|
||||
const table = new Table<UserWithNullable>(getTestDB(), "Users", {
|
||||
user_id: {
|
||||
type: "INTEGER",
|
||||
primary: true,
|
||||
|
@ -438,7 +434,7 @@ test(".update() updates a full record", () => {
|
|||
});
|
||||
|
||||
test(".update() throws if no primary column is set besides ROWID", () => {
|
||||
const db = new Database();
|
||||
const db = getTestDB();
|
||||
const table = new Table<UserWithID>(db, "Users", {
|
||||
user_id: "INTEGER",
|
||||
name: "TEXT",
|
||||
|
@ -454,7 +450,7 @@ test(".update() throws if no primary column is set besides ROWID", () => {
|
|||
});
|
||||
|
||||
test(".updateWhere() updates rows based on the condition", () => {
|
||||
const db = new Database();
|
||||
const db = getTestDB();
|
||||
const table = new Table<UserWithID>(db, "Users", {
|
||||
user_id: "INTEGER",
|
||||
name: "TEXT",
|
||||
|
@ -469,7 +465,7 @@ test(".updateWhere() updates rows based on the condition", () => {
|
|||
});
|
||||
|
||||
test(".updateAll() updates all rows in the table", () => {
|
||||
const db = new Database();
|
||||
const db = getTestDB();
|
||||
const table = new Table<UserWithID>(db, "Users", {
|
||||
user_id: "INTEGER",
|
||||
name: "TEXT",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue