import type { Table } from "./table"; export type ExtractRowShape = T extends Table ? R : never; /** * 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 abstract class Instance< TableType extends Table, SerializedInstanceType = void, > { protected row: ExtractRowShape; protected table: TableType; constructor(table: TableType, row: ExtractRowShape) { this.row = row; this.table = table; } /** * Saves any changes made to the row back to the database. */ save() { this.table.update(this.row); } /** * Serializes the instance into a generic format */ serialize(): SerializedInstanceType { throw new Error("Not implemented"); } /** * @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. */ export(): ExtractRowShape { return this.row; } }