1.2.0
This commit is contained in:
parent
20ac2da081
commit
59de642d31
6 changed files with 3 additions and 85 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@endeavorance/prequel",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"exports": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
|
|
10
src/index.ts
10
src/index.ts
|
@ -1,13 +1,5 @@
|
|||
import type { Column, ColumnShorthand, DataType } from "./columns";
|
||||
import { WrappedRow } from "./wrapped-row";
|
||||
import { Prequel } from "./prequel";
|
||||
import { Table } from "./table";
|
||||
|
||||
export {
|
||||
Prequel,
|
||||
Table,
|
||||
WrappedRow,
|
||||
type DataType,
|
||||
type Column,
|
||||
type ColumnShorthand,
|
||||
};
|
||||
export { Prequel, Table, type DataType, type Column, type ColumnShorthand };
|
||||
|
|
|
@ -7,7 +7,6 @@ import {
|
|||
} from "./columns";
|
||||
import { SchemaError } from "./error";
|
||||
import { Prequel } from "./prequel";
|
||||
import type { WrappedRow } from "./wrapped-row";
|
||||
|
||||
export type ExtractRowShape<T> = T extends Table<infer R> ? R : never;
|
||||
|
||||
|
@ -499,11 +498,6 @@ export class Table<RowShape> {
|
|||
return res.count;
|
||||
}
|
||||
|
||||
public save(wrapped: WrappedRow<RowShape>) {
|
||||
const row = wrapped.unwrap();
|
||||
this.update(row);
|
||||
}
|
||||
|
||||
public toString() {
|
||||
return `"${this._name}"`;
|
||||
}
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/**
|
||||
* Represents an instance of a row in a table of a database.
|
||||
* Wraps the raw Row data and provides methods for interacting with it.
|
||||
*/
|
||||
export class WrappedRow<RowShape> {
|
||||
protected row: RowShape;
|
||||
|
||||
constructor(row: RowShape) {
|
||||
this.row = row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns The row data as a JSON string.
|
||||
*/
|
||||
toJSON(): string {
|
||||
return JSON.stringify(this.row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the raw row data.
|
||||
* @returns The raw row data.
|
||||
*/
|
||||
unwrap(): RowShape {
|
||||
return this.row;
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
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");
|
||||
});
|
|
@ -25,4 +25,5 @@
|
|||
"noPropertyAccessFromIndexSignature": false,
|
||||
"noUncheckedIndexedAccess": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue