import knex from "knex"; import { IModel, InductModelOpts } from "./types/model-schema"; /** * Base class for CRUD operation APIs. Takes a generic type parameter based on */ export declare abstract class Model implements IModel { /** * Tenant database connection object. */ protected _con: knex; /** * Table name to do queries on */ protected _table_name: string; /** * Name of the ID field in the table as a string */ protected _id_field: string; /** * Represents the transaction that the model is using */ protected _trx: knex.Transaction; /** * Stores the model data */ protected _model: T; /** * Contains the model options used to generate the model instance */ protected _options: InductModelOpts; /** * Represents an object that can be used to create new database transactions */ protected trxProvider: any; /** * Represents whether the model data has been validated */ protected _validated: boolean; constructor(model: T, con: knex); get validated(): boolean; get options(): InductModelOpts; get con(): knex; get table_name(): string; get id_field(): string; get model(): T; get trx(): knex.Transaction; destroyConnection(): Promise; /** Creates a new database transaction and sets this transaction to the model instance */ startTransaction(): Promise; commitTransaction(): Promise; rollbackTransaction(): Promise; /** Typed property getter of model data */ get(prop: K): T[K]; /** Typed property setter of model data */ set(prop: K, value: T[K]): void; exists(column: K, value: T[K]): Promise; /** * Use the resource unique identifier to lookup one value. * Returns an array to validate results in the controller. */ abstract findOneById(lookup?: string | number): Promise; /** * Returns an array of objects of the model's type */ abstract findAll(): Promise; /** * Abstract update method. Requires resource specific implementation */ abstract update(value?: Partial): Promise; /** * Inserts the data stored in the class instance into the resource table */ abstract create(value?: Partial): Promise; /** * Deletes the specified entry from the resource table. Returns an amount of deleted rows. */ abstract delete(value: string | number): Promise; /** * Returns a validated JSON representation of the class properties; */ abstract validate(value?: T): Promise; }