@avonjs/avonjs
Version:
A fluent Node.js API generator.
114 lines (113 loc) • 3.27 kB
TypeScript
import type { Knex } from 'knex';
import { type Model, Operator, type Optional, type PrimaryKey, type SearchCollection, type Where } from '../Contracts';
import { Fluent } from '../Models';
import Repository from './Repository';
export default abstract class KnexRepository<TModel extends Model = Fluent> extends Repository<TModel> {
/**
* List of selectable columns.
*/
protected columns: string[];
/**
* The columns that should be searched.
*/
protected searches: Array<string | Knex.Raw>;
/**
* Start new transaction.
*/
prepareTransaction(): Promise<Knex.Transaction<any, any[]>>;
/**
* Search storage for given query string.
*/
search(search: string, page?: number, perPage?: number): Promise<SearchCollection<Fluent>>;
/**
* Perform searches on the given item.
*/
protected performSearch(query: Knex.QueryBuilder, search: string): Knex.QueryBuilder;
/**
* Get the searchable columns for the resource.
*/
searchableColumns(): (string | Knex.Raw<any>)[];
/**
* Find all model's for the given conditions.
*/
all(wheres?: Where[]): Promise<TModel[]>;
/**
* Get the select columns.
*/
protected selectColumns(query: Knex.QueryBuilder): Knex.QueryBuilder;
/**
* Get list of selectable columns.
*/
select(columns?: string[]): this;
/**
* Find first model for the given conditions.
*/
first(wheres?: Where[]): Promise<Optional<TModel>>;
/**
* Store given model into the storage.
*/
store(model: TModel): Promise<TModel>;
/**
* Store given model into the storage.
*/
update(model: TModel): Promise<TModel>;
/**
* Delete model for the given key.
*/
delete(key: PrimaryKey): Promise<void>;
/**
* Get new query with wheres and orders.
*/
makeQuery(): Knex.QueryBuilder;
/**
* Prepare raw orders for query.
*/
protected prepareOrdersForQuery(): {
column: string;
order: string;
}[];
/**
* Apply wheres to the query.
*/
protected applyWheres(query: Knex.QueryBuilder): Knex.QueryBuilder;
/**
* Query where the value "is" or "isNot" null.
*/
protected queryNullValues(query: Knex.QueryBuilder, key: string, operator: Operator): Knex.QueryBuilder<any, any>;
/**
* Get the sanitized value corresponding to the operator.
*/
protected sanitizeValueForOperator(value: never, operator: Operator): never[];
/**
* Get fully qualified column name.
*/
getQualifiedColumnName(columnName: string): string;
/**
* Apply wheres to the query.
*/
protected applyModifiers(query: Knex.QueryBuilder): Knex.QueryBuilder;
/**
* Get the base query.
*/
protected query(): Knex.QueryBuilder;
/**
* Get the database table name.
*/
tableName(): string;
/**
* Parse the query result.
*/
parseResult(result?: TModel): TModel | undefined;
/**
* Create new instance of model.
*/
model(): TModel;
/**
* Get the debugging state.
*/
protected debug(): boolean;
/**
* Get the knex connection.
*/
abstract connection(): Knex;
}