import { TRawStringQuery } from "../types"; import { Model } from "./Model"; import { type T } from "./UtilityTypes"; declare class RepositoryFactory = Record, TR = unknown, M extends Model = Model> { private _model; constructor(_model: { new (): Model; }); /** * * The 'find' method is used to retrieve a single record from a database table by its primary key. * * It allows you to retrieve a single record from a database table that meets the specified criteria. * @type {?Object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {string[]} options.relations * @property {string[]} options.relationExists * @property {?{condition,callback}} options.relationQuery * @property {?boolean} options.debug * @returns {promise} * * @example * import { Repository } from 'tspace-mysql' * import { User } from '../Models/User' * * const userRepository = Repository(User) * * const user = await userRepository.find(1,{ * select : { id: true, name: true } * }) * * const user = await userRepository.findOne() */ find | undefined = undefined, SR extends T.RelationOptions | undefined = undefined, E extends T.ExceptOptions | undefined = undefined, SRS extends Record | undefined = undefined, G extends Record | undefined = {}>(primaryKey: number | string, options?: T.RepositoryOptions): Promise | null>; /** * * The 'findOne' method is used to retrieve the first record that matches the query conditions. * * It allows you to retrieve a single record from a database table that meets the specified criteria. * @type {?Object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {string[]} options.relations * @property {string[]} options.relationExists * @property {?{condition,callback}} options.relationQuery * @property {?boolean} options.debug * @returns {promise} * * @example * import { Repository } from 'tspace-mysql' * import { User } from '../Models/User' * * const userRepository = Repository(User) * * const user = await userRepository.findOne({ * select : { id: true, name: true }, * where : { * id: 1 * } * }) * * const user = await userRepository.findOne() */ findOne | undefined = undefined, SR extends T.RelationOptions | undefined = undefined, E extends T.ExceptOptions | undefined = undefined, SRS extends Record | undefined = undefined, G extends Record | undefined = {}>(options?: T.RepositoryOptions): Promise | null>; /** * * The 'findMany' method is used to retrieve the get record that matches the query conditions. * * It allows you to retrieve a single record from a database table that meets the specified criteria. * @type {?Object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {string[]} options.relations * @property {string[]} options.relationExists * @property {?{condition,callback}} options.relationQuery * @property {?boolean} options.debug * @returns {promise[]} * * @example * import { Repository } from 'tspace-mysql' * import { User } from '../Models/User' * * const userRepository = Repository(User) * * const users = await userRepository.get({ * select : { id: true, name: true }, * where : { * id: 1 * } * }) * * const users = await userRepository.get() */ findMany | undefined = undefined, SR extends T.RelationOptions | undefined = undefined, E extends T.ExceptOptions | undefined = undefined, SRS extends Record | undefined = undefined, G extends Record | undefined = {}>(options?: T.RepositoryOptions): Promise[]>; /** * * The 'stream' method is used to executes a SQL statement and asynchronously yields result rows. * * It allows you to retrieve a single record from a database table that meets the specified criteria. * @type {?Object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {string[]} options.relations * @property {string[]} options.relationExists * @property {?{condition,callback}} options.relationQuery * @property {?boolean} options.debug * @returns {AsyncGenerator} * * @example * import { Repository } from 'tspace-mysql' * import { User } from '../Models/User' * * const userRepository = Repository(User) * * const stream = userRepository.stream({ * select : { id: true, name: true }, * where : { * id: 1 * } * }) * * for await (const user of stream) console.log(user); * */ stream | undefined = undefined, SR extends T.RelationOptions | undefined = undefined, E extends T.ExceptOptions | undefined = undefined, SRS extends Record | undefined = undefined, G extends Record | undefined = {}>(options?: T.RepositoryOptions): AsyncIterable>; /** * * The 'paginate' method is used to perform pagination on a set of database query results obtained through the Query Builder. * * It allows you to split a large set of query results into smaller, more manageable pages, * making it easier to display data in a web application and improve user experience. * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?string[]} options.relations * @property {string[]} options.relationExists * @property {?{condition,callback}} options.relationQuery * @property {?boolean} options.debug * @property {?number} options.page * @returns {promise<{ meta , data[]}>} * * @example * import { Repository } from 'tspace-mysql' * import { User } from '../Models/User' * * const userRepository = Repository(User) * * const users = await userRepository.paginate({ * select : { id: true, name: true }, * where : { * id: 1 * } * }) * * const users = await userRepository.paginate({ page : 1 , limit : 2 }) */ paginate | undefined = undefined, SR extends T.RelationOptions | undefined = undefined, E extends T.ExceptOptions | undefined = undefined, SRS extends Record | undefined = undefined, G extends Record | undefined = {}>(options?: Omit> & { page?: number; }, 'offset'>): Promise>; /** * * The 'pagination' method is used to perform pagination on a set of database query results obtained through the Query Builder. * * It allows you to split a large set of query results into smaller, more manageable pages, * making it easier to display data in a web application and improve user experience. * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?string[]} options.relations * @property {string[]} options.relationExists * @property {?{condition,callback}} options.relationQuery * @property {?boolean} options.debug * @property {?number} options.page * @returns {promise<{ meta , data[]}>} * * @example * import { Repository } from 'tspace-mysql' * import { User } from '../Models/User' * * const userRepository = Repository(User) * * const users = await userRepository.paginate({ * select : { id: true, name: true }, * where : { * id: 1 * } * }) * * const users = await userRepository.paginate({ page : 1 , limit : 2 }) */ pagination | undefined = undefined, SR extends T.RelationOptions | undefined = undefined, E extends T.ExceptOptions | undefined = undefined, SRS extends Record | undefined = undefined, G extends Record | undefined = {}>(options?: Omit> & { page?: number; }, 'offset'>): Promise>; /** * * The 'cursorPaginate' method is used to perform pagination on a set of database query results obtained through the Query Builder. * * It allows you to split a large set of query results into smaller, more manageable pages, * making it easier to display data in a web application and improve user experience. * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?string[]} options.relations * @property {string[]} options.relationExists * @property {?{condition,callback}} options.relationQuery * @property {?boolean} options.debug * @property {?number} options.cursor * @returns {promise<{ meta , data[]}>} * * @example * import { Repository } from 'tspace-mysql' * import { User } from '../Models/User' * * const userRepository = Repository(User) * * const users = await userRepository.cursorPaginate({ * select : { id: true, name: true }, * cursor : "ey...", * limit : 2 * }) * * const users = await userRepository.cursorPaginate({ cursor : "ey..." , limit : 2 }) */ cursorPaginate | undefined = undefined, SR extends T.RelationOptions | undefined = undefined, E extends T.ExceptOptions | undefined = undefined, SRS extends Record | undefined = undefined, G extends Record | undefined = {}>(options?: Partial & { cursor?: string; distinct?: boolean; }>): Promise>; /** * * The 'cursorPagination' method is used to perform pagination on a set of database query results obtained through the Query Builder. * * It allows you to split a large set of query results into smaller, more manageable pages, * making it easier to display data in a web application and improve user experience. * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?string[]} options.relations * @property {string[]} options.relationExists * @property {?{condition,callback}} options.relationQuery * @property {?boolean} options.debug * @property {?number} options.page * @returns {promise<{ meta , data[]}>} * * @example * import { Repository } from 'tspace-mysql' * import { User } from '../Models/User' * * const userRepository = Repository(User) * * const users = await userRepository.cursorPagination({ * select : { id: true, name: true }, * cursor : "ey...", * limit : 2 * }) * * const users = await userRepository.cursorPagination({ cursor : "ey..." , limit : 2 }) */ cursorPagination | undefined = undefined, SR extends T.RelationOptions | undefined = undefined, E extends T.ExceptOptions | undefined = undefined, SRS extends Record | undefined = undefined, G extends Record | undefined = {}>(options?: Partial & { cursor?: string; distinct?: boolean; }>): Promise>; /** * The 'exists' method is used to determine if any records exist in the database table that match the query conditions. * * It returns a boolean value indicating whether there are any matching records. * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?boolean} options.debug * * @example * import { Repository } from 'tspace-mysql' * import { User } from '../Models/User' * * const userRepository = Repository(User) * * const users = await userRepository.exists({ * where : { * id: 1 * } * }) * */ exists(options: Partial, "relations" | "relationsExists" | "relationQuery">>): Promise; /** * The 'toString' method is used to retrieve the raw SQL query that would be executed by a query builder instance without actually executing it. * * This method is particularly useful for debugging and understanding the SQL queries generated by your application. * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?boolean} options.debug * @returns {string} */ toString(options?: Partial, "relations" | "relationsExists" | "relationQuery">>): string; /** * The 'toArray' method is used to execute a database query and retrieve the result set that matches the query conditions. * * It retrieves multiple records from a database table based on the criteria specified in the query. * * It returns an array formatted. * @param {string} column * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?boolean} options.debug * @property {?number} options.page * @return {promise} */ toArray | `${string}.${string}`>(column: K, options?: Partial, "relations" | "relationsExists" | "relationQuery">>): Promise<(K extends keyof T.Result ? T.Result[K] : unknown)[]>; /** * The 'count' method is used to retrieve the total number of records that match the specified query conditions. * * It returns an integer representing the count of records. * @param {string} column * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?boolean} options.debug * @property {?number} options.page * @return {promise} */ count(column: T.ColumnKeys | `${string}.${string}`, options?: Partial, "relations" | "relationsExists" | "relationQuery">>): Promise; /** * The 'avg' method is used to retrieve the total number of records that match the specified query conditions. * * It returns an integer representing the avg of records. * @param {string} column * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?boolean} options.debug * @property {?number} options.page * @return {promise} */ avg(column: T.ColumnKeys | `${string}.${string}`, options?: Partial, "relations" | "relationsExists" | "relationQuery">>): Promise; /** * The 'sum' method is used to retrieve the total number of records that match the specified query conditions. * * It returns an integer representing the sum of records. * @param {string} column * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?boolean} options.debug * @property {?number} options.page * @return {promise} */ sum(column: T.ColumnKeys | `${string}.${string}`, options?: Partial, "relations" | "relationsExists" | "relationQuery">>): Promise; /** * The 'max' method is used to retrieve the maximum value of a numeric column in a database table. * * It finds the highest value in the specified column among all records that match the query conditions and returns that value. * @param {string} column * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?boolean} options.debug * @property {?number} options.page * @return {promise} */ max(column: T.ColumnKeys | `${string}.${string}`, options?: Partial, "relations" | "relationsExists" | "relationQuery">>): Promise; /** * The 'min' method is used to retrieve the minimum (lowest) value of a numeric column in a database table. * * It finds the smallest value in the specified column among all records that match the query conditions and returns that value. * @param {string} column * @type {?object} options * @property {?object} options.select * @property {?object} options.except * @property {?object[]} options.orderBy * @property {?string[]} options.groupBy * @property {?string} options.having * @property {?number} options.limit * @property {?number} options.offset * @property {?object} options.where * @property {?string[]} options.whereRaw * @property {?object} options.whereQuery * @property {?{condition,callback}} options.when * @property {?{localKey , referenceKey}[]} options.join * @property {?{localKey , referenceKey}[]} options.rightJoin * @property {?{localKey , referenceKey}[]} options.leftJoin * @property {?boolean} options.debug * @property {?number} options.page * @return {promise} */ min(column: T.ColumnKeys | `${string}.${string}`, options?: Partial, "relations" | "relationsExists" | "relationQuery">>): Promise; /** * The 'create' method is used to insert a new record into a database table associated. * * It simplifies the process of creating and inserting records. * @type {object} options * @property {object} options.data * @property {?boolean} options.debug * @property {?transaction} options.transaction * @return {promise>} */ create({ data, debug, transaction, noReturn, }: T.RepositoryCreate): Promise>; /** * The 'createNotExists' method to insert data into a database table while ignoring any duplicate key constraint violations. * * This method is particularly useful when you want to insert records into a table and ensure that duplicates are not inserted, * but without raising an error or exception if duplicates are encountered. * * @type {object} options * @property {object} options.data * @property {object} options.where * @property {?boolean} options.debug * @property {?transaction} options.transaction * @return {promise} */ createNotExists({ data, where, debug, noReturn, transaction }: T.RepositoryCreateOrThings): Promise | null>; /** * The 'createMultiple' method is used to insert a new records into a database table associated. * * It simplifies the process of creating and inserting records with an array. * @type {object} options * @property {object[]} options.data * @property {?boolean} options.debug * @property {?transaction} options.transaction * @return {promise} */ createMultiple({ data, debug, transaction, noReturn }: T.RepositoryCreateMultiple): Promise[]>; /** * The 'createMany' method is used to insert a new records into a database table associated. * * It simplifies the process of creating and inserting records with an array. * @type {object} options * @property {object[]} options.data * @property {?boolean} options.debug * @property {?transaction} options.transaction * @return {promise} */ createMany({ data, debug, transaction, noReturn }: T.RepositoryCreateMultiple): Promise[]>; /** * * The 'createOrUpdate' method allows you to update an existing record in a database table if it exists or create a new record if it does not exist. * * This method is particularly useful when you want to update a record based on certain conditions and, * if the record matching those conditions doesn't exist, create a new one with the provided data. * @type {object} options * @property {object} options.data * @property {object} options.where * @property {?boolean} options.debug * @return {promise>} */ createOrUpdate({ data, where, debug, transaction, noReturn }: T.RepositoryCreateOrThings): Promise>; /** * * The 'createOrSelect' method to insert data into a database table while select any duplicate key constraint violations. * * This method is particularly useful when you want to insert records into a table and ensure that duplicates are not inserted, * but if exists should be returns a result. * @type {object} options * @property {object} options.data * @property {object} options.where * @property {?boolean} options.debug * @return {promise>} */ createOrSelect({ data, where, debug, transaction, noReturn }: T.RepositoryCreateOrThings): Promise>; /** * The 'update' method is used to update existing records in a database table that are associated. * * It simplifies the process of updating records by allowing you to specify the values to be updated using a single call. * * It allows you to remove one record that match certain criteria. * @type {object} options * @property {object} options.data * @property {object} options.where * @property {?boolean} options.debug * @property {?transaction} options.transaction * @return {promise>} */ update({ data, where, debug, transaction, noReturn }: T.RepositoryUpdate): Promise | null>; /** * The 'updateMany' method is used to update existing records in a database table that are associated. * * It simplifies the process of updating records by allowing you to specify the values to be updated using a single call. * * It allows you to remove more records that match certain criteria. * @type {object} options * @property {object} options.data * @property {object} options.where * @property {?boolean} options.debug * @property {?transaction} options.transaction * @return {promise[]>} */ updateMany({ data, where, debug, transaction, noReturn }: T.RepositoryUpdate): Promise[]>; /** * The 'updateCases' method is used to update records in a table based on specific conditions. * * This method allows updating multiple rows at once by specifying an array of update cases. * Each case defines which records to update (`when`) and the new values to apply (`columns`). * * @type {object} options * @property {object} options.data * @property {object} options.where * @property {?boolean} options.debug * @property {?transaction} options.transaction * @return {promise} * @example * const saveUpdateMultiple = await userRepository.updateCases({ * cases : [ * { * when : { * id: 1 * }, * columns : { * name : 'name-edit-in-multiple : id 1 ' * } * }, * { * when : { * id : 2 * }, * columns : { * name : 'name-edit-in-multiple : id 2' * } * } * ], * where : { * id : Operator.in([1,2]) * } * }) * */ updateCases({ cases, debug, transaction, noReturn }: T.RepositoryUpdateMultiple): Promise[]>; /** * The 'delete' method is used to delete records from a database table based on the specified query conditions. * * It allows you to remove one record that match certain criteria. * @type {object} options * @property {object} options.data * @property {object} options.where * @property {?boolean} options.debug * @property {?transaction} options.transaction * @return {promise} */ delete({ where, debug, transaction, }: T.RepositoryDelete): Promise; /** * The 'deleteMany' method is used to delete records from a database table based on the specified query conditions. * * It allows you to remove one record that match certain criteria. * @type {object} options * @property {object} options.data * @property {object} options.where * @property {?boolean} options.debug * @property {?transaction} options.transaction * @return {promise} */ deleteMany({ where, debug, transaction, }: T.RepositoryDelete): Promise; private _handleRelationQuery; private _handlerRequest; } /** * * The 'Repository' is a class that encapsulates all database operations related to a specific model. * * It provides methods for querying, inserting, updating, and deleting records in the database associated with the model. * * @param {Model} model A class constructor for a model * @returns {RepositoryFactory} * * @example * import { Repository } from 'tspace-mysql' * import { User } from '../Models/User' * * const userRepository = Repository(User) * * const user = await userRepository.findOne() * const users = await userRepository.findMany() * */ export declare const Repository: , S extends Record = T.SchemaModel & Record, R = T.RelationModel>(model: new () => M) => RepositoryFactory; export default Repository;