UNPKG

typecql

Version:

ORM for CQL databases.

309 lines (308 loc) 12.4 kB
import { Client, mapping } from 'cassandra-driver'; import { OrderByFields, SelectFields, SelectResult, WhereFields } from '../factory/query.factory'; import { InsertOptions, InsertParams } from '../factory/write-query.factory'; import { deleteParameters } from './crud/delete-repository'; import { updateObject, updateParameters } from './crud/update-repository'; import { Transaction } from '../transactions/base-transaction'; import { consistencies } from '../misc/types/consistencies'; import { DeleteReturn, UpdateReturn } from '../misc/types/returning.types'; import ModelMapper = mapping.ModelMapper; import { LoggingOptions } from '../misc/logging/logging.types'; export declare class BaseRepository<T> { private readonly client; private readonly entity; mapper: ModelMapper<T>; private schemaEntity; private primaryKeys; private tableName; private globalSettings; private createRepository; private findRepository; private deleteRepository; private updateRepository; /** * Delete is an async method that takes where, if and fields parameters and executes delete query. * @param parameters parameters to delete query. * @link https://typecql.com/#Delete%20-%20delete */ delete(parameters: deleteParameters<T>): Promise<DeleteReturn>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T> | InsertParams<T>[], options: InsertOptions & { returning: false; replace: true; batch: true; }): Promise<{ wasApplied: boolean; }>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T> | InsertParams<T>[], options: InsertOptions & { returnRaw?: false; returning: true; replace: true; batch: true; }): Promise<{ rows: T[]; wasApplied: boolean; }>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T> | InsertParams<T>[], options: InsertOptions & { returnRaw: true; returning: true; replace: true; batch: true; }): Promise<T[]>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T> | InsertParams<T>[], options: InsertOptions & { returnRaw: true; returning: true; replace: true; batch: true; }): Promise<T[]>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T>, options: InsertOptions & { returning: true; }): Promise<{ wasApplied: boolean; row: T; }>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T>[], options: InsertOptions & { returning: true; }): Promise<{ wasApplied: boolean; row: T; }[]>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T> | InsertParams<T>[], options: InsertOptions): Promise<{ wasApplied: boolean; }>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T>, options: InsertOptions & { returnRaw: true; returning: true; batch: false; }): Promise<T>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T>, options: InsertOptions & { returnRaw: false; returning: true; batch: false; }): Promise<{ wasApplied: boolean; row: T; }>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T>, options: InsertOptions & { returning: false; batch: false; }): Promise<{ wasApplied: boolean; }>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T>[], options: InsertOptions & { returnRaw: true; returning: true; batch: false; }): Promise<T[]>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T>[], options: InsertOptions & { returnRaw: false; returning: true; batch: false; }): Promise<{ wasApplied: boolean; row: T; }[]>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T>[], options: InsertOptions & { returning: false; batch: false; }): Promise<{ wasApplied: boolean; }>; /** * Insert is an async method that takes options object and data parameter as object or array of objects with entity type. * @param data object or array of objects to be inserted in database. * @param options additional options. * @link https://typecql.com/#Insert%20-%20insert */ insert(data: InsertParams<T> | InsertParams<T>[], options?: undefined): Promise<{ wasApplied: boolean; }>; /** * Update is an async method that takes where, if and fields parameters and partial object to update and executes update query. * @param parameters parameters to update query. * @param partialObject object with fields as update values. * @link https://typecql.com/#Update%20-%20update */ update(parameters: updateParameters<T>, partialObject: updateObject<T>): Promise<UpdateReturn>; /** * FindMany is an async method that takes where, and select with other options parameters and executes select query. * @param parameters parameters to update query. * @link https://typecql.com/#Select%20-%20findMany */ findMany(parameters?: { select?: undefined; where?: WhereFields<T>; limit?: number; page?: number; orderBy?: OrderByFields<T>; allowFiltering?: boolean; logging?: LoggingOptions; consistency?: consistencies; }): Promise<T[]>; /** * FindMany is an async method that takes where, and select with other options parameters and executes select query. * @param parameters parameters to update query. * @link https://typecql.com/#Select%20-%20findMany */ findMany<const S extends SelectFields<T>[]>(parameters?: { select?: S; where?: WhereFields<T>; limit?: number; page?: number; orderBy?: OrderByFields<T>; allowFiltering?: boolean; logging?: LoggingOptions; consistency?: consistencies; }): Promise<SelectResult<T, S>[]>; /** * FindAndCount is an async method that takes where, and select with other options parameters and executes select query. * @param parameters parameters to update query. * @link https://typecql.com/#Select%20-%20findAndCount */ findAndCount(parameters?: { select?: undefined; where?: WhereFields<T>; limit?: number; page?: number; orderBy?: OrderByFields<T>; allowFiltering?: boolean; logging?: LoggingOptions; consistency?: consistencies; }): Promise<{ rows: T[]; count: number; }>; /** * FindAndCount is an async method that takes where, and select with other options parameters and executes select query. * @param parameters parameters to update query. * @link https://typecql.com/#Select%20-%20findAndCount */ findAndCount<const S extends SelectFields<T>[]>(parameters?: { select?: S; where?: WhereFields<T>; limit?: number; page?: number; orderBy?: OrderByFields<T>; allowFiltering?: boolean; logging?: LoggingOptions; consistency?: consistencies; }): Promise<{ rows: SelectResult<T, S>[]; count: number; }>; /** * FindOne is an async method that takes where, and select with other options parameters and executes select query. * @param parameters params to select query. * @link https://typecql.com/#Select%20-%20findOne */ findOne(parameters?: { select?: undefined; where?: WhereFields<T>; limit?: number; page?: number; orderBy?: OrderByFields<T>; allowFiltering?: boolean; logging?: LoggingOptions; consistency?: consistencies; }): Promise<T>; /** * FindOne is an async method that takes where, and select with other options parameters and executes select query. * @param parameters params to select query. * @link https://typecql.com/#Select%20-%20findOne */ findOne<const S extends SelectFields<T>[]>(parameters?: { select?: S; where?: WhereFields<T>; limit?: number; page?: number; orderBy?: OrderByFields<T>; allowFiltering?: boolean; logging?: LoggingOptions; consistency?: consistencies; }): Promise<SelectResult<T, S>>; private initialize; /** * Method, that creates new transaction manager instance * @link https://typecql.com/#Transactions */ createTransaction(): Transaction; constructor(client: Client, entity: new (...args: any[]) => any); static create<T>(client: Client, entity: new (...args: any[]) => T): Promise<BaseRepository<T>>; }