import { Knex } from 'knex'; import { NestedForeignKeyKeysOf, NestedKeysOf } from './NestedKeysOf'; import { NonForeignKeyObjects } from './NonForeignKeyObjects'; import { NonNullableRecursive } from './NonNullableRecursive'; import { GetNestedProperty, GetNestedPropertyType } from './PropertyTypes'; import { SelectableColumnTypes } from './SelectableColumnTypes'; import { FlattenOption } from './unflatten'; export declare class ModelRepository { private knex; constructor(knex: Knex); query(tableClass: new () => T): ITypedQueryBuilder; beginTransaction(): Promise; } export declare function registerBeforeInsertTransform(f: (item: T, typedQueryBuilder: ITypedQueryBuilder<{}, {}, {}>) => T): void; export declare function registerBeforeUpdateTransform(f: (item: T, typedQueryBuilder: ITypedQueryBuilder<{}, {}, {}>) => T): void; export interface ITypedQueryBuilder { columns: { name: string; }[]; where: IWhereWithOperator; andWhere: IWhereWithOperator; orWhere: IWhereWithOperator; whereNot: IWhere; select: ISelectWithFunctionColumns3; selectQuery: ISelectQuery; orderBy: IOrderBy; innerJoinColumn: IKeyFunctionAsParametersReturnQueryBuider; leftOuterJoinColumn: IKeyFunctionAsParametersReturnQueryBuider; whereColumn: IWhereCompareTwoColumns; whereNull: IColumnParameterNoRowTransformation; whereNotNull: IColumnParameterNoRowTransformation; orWhereNull: IColumnParameterNoRowTransformation; orWhereNotNull: IColumnParameterNoRowTransformation; leftOuterJoinTableOnFunction: IJoinTableMultipleOnClauses; innerJoinTableOnFunction: IJoinTableMultipleOnClauses; selectRaw: ISelectRaw; findByPrimaryKey: IFindByPrimaryKey; whereIn: IWhereIn; whereNotIn: IWhereIn; orWhereIn: IWhereIn; orWhereNotIn: IWhereIn; whereBetween: IWhereBetween; whereNotBetween: IWhereBetween; orWhereBetween: IWhereBetween; orWhereNotBetween: IWhereBetween; whereExists: IWhereExists; orWhereExists: IWhereExists; whereNotExists: IWhereExists; orWhereNotExists: IWhereExists; whereParentheses: IWhereParentheses; groupBy: ISelectableColumnKeyFunctionAsParametersReturnQueryBuider; having: IHaving; havingNull: ISelectableColumnKeyFunctionAsParametersReturnQueryBuider; havingNotNull: ISelectableColumnKeyFunctionAsParametersReturnQueryBuider; havingIn: IWhereIn; havingNotIn: IWhereIn; havingExists: IWhereExists; havingNotExists: IWhereExists; havingBetween: IWhereBetween; havingNotBetween: IWhereBetween; union: IUnion; unionAll: IUnion; min: IDbFunctionWithAlias; count: IDbFunctionWithAlias; countDistinct: IDbFunctionWithAlias; max: IDbFunctionWithAlias; sum: IDbFunctionWithAlias; sumDistinct: IDbFunctionWithAlias; avg: IDbFunctionWithAlias; avgDistinct: IDbFunctionWithAlias; insertSelect: IInsertSelect; clearSelect(): ITypedQueryBuilder; clearWhere(): ITypedQueryBuilder; clearOrder(): ITypedQueryBuilder; limit(value: number): ITypedQueryBuilder; offset(value: number): ITypedQueryBuilder; useKnexQueryBuilder(f: (query: Knex.QueryBuilder) => void): ITypedQueryBuilder; toQuery(): string; getFirstOrNull(flattenOption?: FlattenOption): Promise : Row | null>; getFirst(flattenOption?: FlattenOption): Promise : Row>; getSingleOrNull(flattenOption?: FlattenOption): Promise : Row | null>; getSingle(flattenOption?: FlattenOption): Promise : Row>; getMany(flattenOption?: FlattenOption): Promise<(Row extends Model ? RemoveObjectsFrom : Row)[]>; getCount(): Promise; insertItem(newObject: Partial>): Promise; insertItems(items: Partial>[]): Promise; del(): Promise; delByPrimaryKey(primaryKeyValue: any): Promise; updateItem(item: Partial>): Promise; updateItemByPrimaryKey(primaryKeyValue: any, item: Partial>): Promise; updateItemsByPrimaryKey(items: { primaryKeyValue: any; data: Partial>; }[]): Promise; execute(): Promise; whereRaw(sql: string, ...bindings: string[]): ITypedQueryBuilder; havingRaw(sql: string, ...bindings: string[]): ITypedQueryBuilder; transacting(trx: Knex.Transaction): ITypedQueryBuilder; truncate(): Promise; distinct(): ITypedQueryBuilder; clone(): ITypedQueryBuilder; groupByRaw(sql: string, ...bindings: string[]): ITypedQueryBuilder; orderByRaw(sql: string, ...bindings: string[]): ITypedQueryBuilder; keepFlat(): ITypedQueryBuilder; } declare type ReturnNonObjectsNamesOnly = { [K in keyof T]: T[K] extends SelectableColumnTypes ? K : never; }[keyof T]; declare type RemoveObjectsFrom = { [P in ReturnNonObjectsNamesOnly]: T[P]; }; export declare type ObjectToPrimitive = T extends String ? string : T extends Number ? number : T extends Boolean ? boolean : never; export declare type Operator = '=' | '!=' | '>' | '<' | string; interface IConstructor { new (...args: any[]): T; } export declare type AddPropertyWithType = Original & Record; interface IColumnParameterNoRowTransformation { , keyof NonNullableRecursive, ''>>(key: ConcatKey): ITypedQueryBuilder; } interface IJoinOn { , keyof NonNullableRecursive, ''>, ConcatKey2 extends NestedKeysOf, keyof NonNullableRecursive, ''>>(key1: ConcatKey1, operator: Operator, key2: ConcatKey2): IJoinOnClause2; } interface IJoinOnVal { , keyof NonNullableRecursive, ''>>(key: ConcatKey, operator: Operator, value: any): IJoinOnClause2; } interface IJoinOnNull { , keyof NonNullableRecursive, ''>>(key: ConcatKey): IJoinOnClause2; } interface IJoinOnClause2 { on: IJoinOn; orOn: IJoinOn; andOn: IJoinOn; onVal: IJoinOnVal; andOnVal: IJoinOnVal; orOnVal: IJoinOnVal; onNull: IJoinOnNull; } interface IInsertSelect { , keyof NonNullableRecursive, ''>>(newPropertyClass: new () => NewPropertyType, ...columnNames: ConcatKey[]): Promise; } interface IJoinTableMultipleOnClauses { (newPropertyKey: NewPropertyKey, newPropertyClass: new () => NewPropertyType, on: (join: IJoinOnClause2, NewPropertyType>) => void): ITypedQueryBuilder, AddPropertyWithType, Row>; } interface ISelectRaw { (name: TName, returnType: IConstructor, query: string): ITypedQueryBuilder> & Row>; } interface ISelectQuery { (name: TName, returnType: IConstructor, subQueryModel: new () => SubQueryModel, code: (subQuery: ITypedQueryBuilder, parent: TransformPropsToFunctionsReturnPropertyName) => void): ITypedQueryBuilder> & Row>; } declare type TransformPropsToFunctionsReturnPropertyName = { [P in keyof Model]: Model[P] extends object ? (Model[P] extends Required ? () => P : TransformPropsToFunctionsReturnPropertyName) : () => P; }; interface IOrderBy { , keyof NonNullableRecursive, ''>, TName extends keyof any>(columnNames: ConcatKey, direction?: 'asc' | 'desc'): ITypedQueryBuilder>>; } interface IDbFunctionWithAlias { , keyof NonNullableRecursive, ''>, TName extends keyof any>(columnNames: ConcatKey, name: TName): ITypedQueryBuilder>>; } declare type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; interface ISelectWithFunctionColumns3 { , keyof NonNullableRecursive, ''>>(...columnNames: ConcatKey[]): ITypedQueryBuilder>>; } interface IFindByPrimaryKey<_Model, SelectableModel, Row> { , keyof NonNullableRecursive, ''>>(primaryKeyValue: any, ...columnNames: ConcatKey[]): Promise<(Row & UnionToIntersection>) | undefined>; } interface IKeyFunctionAsParametersReturnQueryBuider { , keyof NonNullableRecursive, ''>>(key: ConcatKey): ITypedQueryBuilder; } interface ISelectableColumnKeyFunctionAsParametersReturnQueryBuider { , keyof NonNullableRecursive, ''>>(key: ConcatKey): ITypedQueryBuilder; } interface IWhere { , keyof NonNullableRecursive, ''>>(key: ConcatKey, value: GetNestedPropertyType): ITypedQueryBuilder; } interface IWhereWithOperator { , keyof NonNullableRecursive, ''>>(key: ConcatKey, value: GetNestedPropertyType): ITypedQueryBuilder; , keyof NonNullableRecursive, ''>>(key: ConcatKey, operator: Operator, value: GetNestedPropertyType): ITypedQueryBuilder; } interface IWhereIn { , keyof NonNullableRecursive, ''>>(key: ConcatKey, value: GetNestedPropertyType[]): ITypedQueryBuilder; } interface IWhereBetween { , keyof NonNullableRecursive, ''>, PropertyType extends GetNestedPropertyType>(key: ConcatKey, value: [PropertyType, PropertyType]): ITypedQueryBuilder; } interface IHaving { , keyof NonNullableRecursive, ''>>(key: ConcatKey, operator: Operator, value: GetNestedPropertyType): ITypedQueryBuilder; } interface IWhereCompareTwoColumns { <_PropertyType1, _PropertyType2, Model2>(key1: NestedKeysOf, keyof NonNullableRecursive, ''>, operator: Operator, key2: NestedKeysOf, keyof NonNullableRecursive, ''>): ITypedQueryBuilder; } interface IWhereExists { (subQueryModel: new () => SubQueryModel, code: (subQuery: ITypedQueryBuilder, parent: TransformPropsToFunctionsReturnPropertyName) => void): ITypedQueryBuilder; } interface IWhereParentheses { (code: (subQuery: ITypedQueryBuilder) => void): ITypedQueryBuilder; } interface IUnion { (subQueryModel: new () => SubQueryModel, code: (subQuery: ITypedQueryBuilder) => void): ITypedQueryBuilder; } export {};