1 import { Knex } from 'knex';
2 import { db } from '../lib/db';
4 export class Repository<T> {
7 constructor(table: string) {
12 async Insert(data: any) {
13 console.log('inserting', data);
14 const row = await db<T>(this.table).insert(data, '*');
18 async FindOne(where: Record<string, any>): Promise<T> {
19 const res = await db<T>(this.table).select('*').where(where);
21 return res.pop() as T;
24 FindAll(where?: any) {
26 return db<T>(this.table).select('*').where(where);
28 return db<T>(this.table).select('*');
31 async Save(thing: Partial<T>, where?: any) {
32 return db<T>(this.table).update(thing as any).where(where);
35 async Delete(where: any) {
36 return db(this.table).where(where).delete();