43 lines
770 B
TypeScript
43 lines
770 B
TypeScript
import { Database } from "bun:sqlite";
|
|
import { expect, test } from "bun:test";
|
|
import { WrappedRow, Table } from "../src/index";
|
|
|
|
interface User {
|
|
id: number;
|
|
name: string;
|
|
}
|
|
|
|
const db = new Database();
|
|
const table = new Table<User>(db, "Users", {
|
|
id: {
|
|
type: "INTEGER",
|
|
primary: true,
|
|
},
|
|
name: "TEXT",
|
|
});
|
|
|
|
class UserWrappedRow extends WrappedRow<User> {
|
|
get name(): string {
|
|
return this.row.name;
|
|
}
|
|
|
|
set name(val: string) {
|
|
this.row.name = val;
|
|
}
|
|
}
|
|
|
|
test("setting values on an WrappedRow", () => {
|
|
table.insert({
|
|
id: 1,
|
|
name: "Alice",
|
|
});
|
|
|
|
const alice = table.findOneByIdOrFail(1);
|
|
const inst = new UserWrappedRow(alice);
|
|
|
|
inst.name = "Bob";
|
|
table.save(inst);
|
|
|
|
const bob = table.findOneByIdOrFail(1);
|
|
expect(bob.name).toEqual("Bob");
|
|
});
|