import { AbstractBuilder } from "./Abstracts/AbstractBuilder"; import { DB } from "./DB"; import { Join } from "./Join"; import { CONSTANTS } from "../constants"; import { QueryBuilder } from "./Driver"; import type { TPagination, TConnectionOptions, TPoolConnected, TDriver, TSaveBuilderResult, TAction, TCursorPagination, TExplain, TConnection } from "../types"; declare class Builder extends AbstractBuilder { constructor(); /** * The 'instance' method is used get instance. * @static * @returns {Builder} instance of the Builder */ static get instance(): Builder; /** * The 'driver' method is used to get current driver * @static * @returns {TDriver} driver */ static driver(): TDriver; /** * The 'driver' method is used to get current driver * @returns {TDriver} driver */ driver(): TDriver; /** * The 'database' method is used to get current database * @returns {string} database */ database(): string; /** * The 'useNode' method is used to selects the database node used to execute the query. * * - `primary`: Uses the primary database node. * - `replica`: Uses a replica node. If `node` is provided, the specified * replica is used; otherwise, a replica is selected randomly. * * @param type - The database node type to use. * @param options - Node selection options. * @param options.node - 1-based replica node number. Only applicable when * `type` is `replica`. * * @throws {Error} If node selection is requested outside cluster mode. * @throws {Error} If a replica node is requested but no replicas are available. * * @example * // Use the primary node * query.useNode('primary'); * * @example * // Use a random replica * query.useNode('replica'); * * @example * // Use replica node 2 * query.useNode('replica', { node: 2 }); */ useNode(type: 'primary'): this; useNode(type: 'replica', options?: { node?: number; }): this; /** * The 'rowLock' method is used to row level locks (`FOR UPDATE` or `FOR SHARE`) to the query. * * @param {string} mode * @returns {this} this */ rowLock(mode: "FOR_UPDATE" | "FOR_SHARE", opts?: { skipLocked: true; nowait?: false; } | { skipLocked?: false; nowait: true; } | { skipLocked?: false; nowait?: false; }): this; /** * The 'forUpdate' method is used to applies a row-level exclusive lock (`FOR UPDATE`) to the query. * * This lock prevents other transactions from modifying or acquiring * conflicting locks on the selected rows until the current transaction * is committed or rolled back. * * Commonly used in queue systems or critical sections to safely * select and update rows without race conditions. * * @param {Object} [opts] - Locking options * @param {boolean} [opts.skipLocked=false] - If true, skips rows that are already locked by other transactions. * Useful for building non-blocking workers (e.g., job queues). * @param {boolean} [opts.nowait=false] - If true, throws an error immediately if the lock cannot be acquired. * * @throws {Error} If both `skipLocked` and `nowait` are enabled at the same time. * * @returns {this} Returns the query builder instance for chaining. */ forUpdate(opts?: { skipLocked: true; nowait?: false; } | { skipLocked?: false; nowait: true; } | { skipLocked?: false; nowait?: false; }): this; /** * The 'forShare' method is used to applies a row-level exclusive lock (`FOR SHARE`) to the query. * * This lock prevents other transactions from modifying or acquiring * conflicting locks on the selected rows until the current transaction * is committed or rolled back. * * Commonly used in queue systems or critical sections to safely * select and update rows without race conditions. * * @param {Object} [opts] - Locking options * @param {boolean} [opts.skipLocked=false] - If true, skips rows that are already locked by other transactions. * Useful for building non-blocking workers (e.g., job queues). * @param {boolean} [opts.nowait=false] - If true, throws an error immediately if the lock cannot be acquired. * * @throws {Error} If both `skipLocked` and `nowait` are enabled at the same time. * * @returns {this} Returns the query builder instance for chaining. */ forShare(opts?: { skipLocked: true; nowait?: false; } | { skipLocked?: false; nowait: true; } | { skipLocked?: false; nowait?: false; }): this; /** * The 'unset' method is used to drop a property as desired. * @param {object} options * @property {boolean | undefined} options.select * @property {boolean | undefined} options.where * @property {boolean | undefined} options.join * @property {boolean | undefined} options.limit * @property {boolean | undefined} options.offset * @property {boolean | undefined} options.orderBy * @property {boolean | undefined} options.groupBy * @property {boolean | undefined} options.having * @returns {this} this */ unset(options: { select?: boolean; where?: boolean; join?: boolean; limit?: boolean; offset?: boolean; orderBy?: boolean; groupBy?: boolean; having?: boolean; alias?: boolean; }): this; /** * The 'CTEs' method is used to create common table expressions(CTEs). * * @returns {string} return sql query */ CTEs(as: string, callback: (query: Builder) => Builder): this; /** * The 'getQueries' method is used to retrieve the raw SQL queries that would be executed. * * @returns {string} return sql query */ getQueries(): string[]; /** * The 'distinct' method is used to apply the DISTINCT keyword to a database query. * * It allows you to retrieve unique values from one or more columns in the result set, eliminating duplicate rows. * @returns {this} this */ distinct(): this; /** * The 'select' method is used to specify which columns you want to retrieve from a database table. * * It allows you to choose the specific columns that should be included in the result set of a database query. * @param {string[]} ...columns * @returns {this} this */ select(...columns: string[]): this; /** * The 'addSelect' method is used to add columns you want to retrieve from a database table. * * It allows you to choose the specific columns that should be included in the result set of a database query. * @param {string[]} ...columns * @returns {this} this */ addSelect(...columns: string[]): this; /** * The 'selectRaw' method is used to specify which columns you want to retrieve from a database table. * * It allows you to choose the specific columns that should be included in the result set of a database query. * * This method allows you to specify raw-sql parameters for the query. * @param {string[]} ...columns * @returns {this} this */ selectRaw(...columns: string[]): this; /** * The 'select1' method is used to select 1 from database table. * * @returns {this} this */ select1(): this; /** * The 'selectObject' method is used to specify which columns you want to retrieve from a database table. * * It allows you to choose the specific columns that should be included in the result set to 'Object' of a database query. * @param {string} object table name * @param {string} alias as name of the column * @returns {this} this */ selectObject(object: Record, alias: string): this; /** * The 'selectArray' method is used to specify which columns you want to retrieve from a database table. * * It allows you to choose the specific columns that should be included in the result set to 'Object' of a database query. * @param {string} object table name * @param {string} alias as name of the column * @returns {this} this */ selectArray(object: Record, alias: string): this; /** * The 'table' method is used to set the table name. * * @param {string} table table name * @returns {this} this */ table(table: string): this; /** * The 'from' method is used to set the table name. * * @param {string} table table name * @returns {this} this */ from(table: string | null, { push }?: { push?: string[]; }): this; /** * The 'fromRaw' method is used to set the table name. * * @param {string} table table name * @returns {this} this */ fromRaw(table: string | null, { push }?: { push?: string[]; }): this; /** * The 'alias' method is used to set the table name. * * @param {string} alias alias name * @param {string} from from sql raw sql from make a new alias for this table * @returns {this} this */ alias(alias: string, from?: string): this; /** * The 'as' method is used to set the table name. * * @param {string} alias alias name * @param {string} from from sql raw sql from make a new alias for this table * @returns {this} this */ as(alias: string, from?: string): this; /** * The 'sleep' method is used to delay the query. * * @param {number} second - The number of seconds to sleep * @returns {this} this */ sleep(second: number): this; /** * The 'except' method is used to specify which columns you don't want to retrieve from a database table. * * It allows you to choose the specific columns that should be not included in the result set of a database query. * @param {...string} columns * @returns {this} this */ except(...columns: string[]): this; /** * The 'exceptTimestamp' method is used to timestamp columns (created_at , updated_at) you don't want to retrieve from a database table. * * @returns {this} this */ exceptTimestamp(): this; /** * The 'void' method is used to specify which you don't want to return a result from database table. * * @returns {this} this */ void(): Builder; /** * The 'when' method is used to specify if condition should be true will be next to the actions * @param {string | number | undefined | null | Boolean} condition when condition true will return query callback * @returns {this} this */ when(condition: string | number | undefined | null | Boolean, callback: (query: Builder) => Builder): this; /** * The 'where' method is used to add conditions to a database query. * * It allows you to specify conditions that records in the database must meet in order to be included in the result set. * * If has only 2 arguments default operator '=' * @param {string} column if arguments is object * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE'] * @param {any?} value * @returns {this} */ where(column: string | Record, operator?: any, value?: any): this; /** * The 'orWhere' method is used to add conditions to a database query. * * It allows you to specify conditions that records in the database must meet in order to be included in the result set. * * If has only 2 arguments default operator '=' * @param {string} column * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE'] * @param {any?} value * @returns {this} */ orWhere(column: string, operator?: any, value?: any): this; /** * The 'whereDay' method is used to add a "where" clause that filters results based on the day part of a date column. * * It is especially useful for querying records that fall within a specific day. * @param {string} column * @param {number} day * @returns {this} */ whereDay(column: string, day: number): this; /** * The 'whereMonth' method is used to add a "where" clause that filters results based on the month part of a date column. * * It is especially useful for querying records that fall within a specific month. * @param {string} column * @param {number} month * @returns {this} */ whereMonth(column: string, month: number): this; /** * The 'whereYear' method is used to add a "where" clause that filters results based on the year part of a date column. * * It is especially useful for querying records that fall within a specific year. * @param {string} column * @param {number} year * @returns {this} */ whereYear(column: string, year: number): this; /** * The 'whereRaw' method is used to add a raw SQL condition to a database query. * * It allows you to include custom SQL expressions as conditions in your query, * which can be useful for situations where you need to perform complex or custom filtering that cannot be achieved using Laravel's standard query builder methods. * @param {string} sql where column with raw sql * @returns {this} this */ whereRaw(sql: string, parameters?: (boolean | number | string | any[] | null)[]): this; /** * The 'orWhereRaw' method is used to add a raw SQL condition to a database query. * * It allows you to include custom SQL expressions as conditions in your query, * which can be useful for situations where you need to perform complex or custom filtering that cannot be achieved using Laravel's standard query builder methods. * @param {string} sql where column with raw sql * @returns {this} this */ orWhereRaw(sql: string, parameters?: (boolean | number | string | any[] | null)[]): this; /** * The 'whereObject' method is used to add conditions to a database query. * * It allows you to specify conditions in object that records in the database must meet in order to be included in the result set. * * This method is defalut operator '=' only * @param {Object} columns * @returns {this} */ whereObject(columns: Record): this; /** * The 'whereJSON' method is used to add conditions to a database query. * * It allows you to specify conditions in that records json in the database must meet in order to be included in the result set. * @param {string} column * @param {object} property object { key , value , operator } * @property {string} property.key * @property {string} property.value * @property {string?} property.operator * @returns {this} */ whereJSON(column: string, { key, value, operator }: { key: string; value: string; operator?: string; }): this; /** * The 'whereJSON' method is used to add conditions to a database query. * * It allows you to specify conditions in that records json in the database must meet in order to be included in the result set. * @param {string} column * @param {object} property object { key , value , operator } * @property {string} property.key * @property {string} property.value * @property {string?} property.operator * @returns {this} */ whereJson(column: string, { key, value, operator }: { key: string; value: string; operator?: string; }): this; /** * * The 'whereExists' method is used to add a conditional clause to a database query that checks for the existence of related records in a subquery or another table. * * It allows you to filter records based on whether a specified condition is true for related records. * @param {string} sql * @returns {this} */ whereExists(sql: string | Builder): this; /** * * The 'whereExists' method is used to add a conditional clause to a database query that checks for the existence of related records in a subquery or another table. * * It allows you to filter records based on whether a specified condition is true for related records. * @param {string} sql * @returns {this} */ whereNotExists(sql: string | Builder): this; /** * * The 'orWhereExists' method is used to add a conditional clause to a database query that checks for the existence of related records in a subquery or another table. * * It allows you to filter records based on whether a specified condition is true for related records. * @param {string} sql * @returns {this} */ orWhereExists(sql: string | Builder): this; /** * * The 'orWhereExists' method is used to add a conditional clause to a database query that checks for the existence of related records in a subquery or another table. * * It allows you to filter records based on whether a specified condition is true for related records. * @param {string} sql * @returns {this} */ orWhereNotExists(sql: string | Builder): this; /** * * @param {number} id * @returns {this} this */ whereId(id: number, column?: string): this; /** * * @param {string} email where using email * @returns {this} */ whereEmail(email: string): this; /** * * @param {number} userId * @param {string?} column custom it *if column is not user_id * @returns {this} */ whereUser(userId: number, column?: string): this; /** * The 'whereIn' method is used to add a conditional clause to a database query that checks if a specified column's value is included in a given array of values. * * This method is useful when you want to filter records based on a column matching any of the values provided in an array. * @param {string} column * @param {array} array * @returns {this} */ whereIn(column: string, array: any[]): this; /** * The 'orWhereIn' method is used to add a conditional clause to a database query that checks if a specified column's value is included in a given array of values. * * This method is useful when you want to filter records based on a column matching any of the values provided in an array. * @param {string} column * @param {array} array * @returns {this} */ orWhereIn(column: string, array: any[]): this; /** * The 'whereNotIn' method is used to add a conditional clause to a database query that checks if a specified column's value is not included in a given array of values. * * This method is the opposite of whereIn and is useful when you want to filter records based on a column not matching any of the values provided in an array. * @param {string} column * @param {array} array * @returns {this} */ whereNotIn(column: string, array: any[]): this; /** * The 'orWhereNotIn' method is used to add a conditional clause to a database query that checks if a specified column's value is not included in a given array of values. * * This method is the opposite of whereIn and is useful when you want to filter records based on a column not matching any of the values provided in an array. * @param {string} column * @param {array} array * @returns {this} */ orWhereNotIn(column: string, array: any[]): this; /** * The 'whereSubQuery' method is used to add a conditional clause to a database query that involves a subquery. * * Subqueries also known as nested queries, are queries that are embedded within the main query. * * They are often used when you need to perform a query to retrieve some values and then use those values as part of the condition in the main query. * @param {string} column * @param {string} subQuery * @returns {this} */ whereSubQuery(column: string, subQuery: string | Builder, options?: { operator?: (typeof CONSTANTS)["EQ"] | (typeof CONSTANTS)["IN"]; }): this; /** * The 'whereNotSubQuery' method is used to add a conditional clause to a database query that involves a subquery. * * Subqueries also known as nested queries, are queries that are embedded within the main query. * * They are often used when you need to perform a query to retrieve not some values and then use those values as part of the condition in the main query. * @param {string} column * @param {string} subQuery * @returns {this} */ whereNotSubQuery(column: string, subQuery: string | Builder, options?: { operator?: (typeof CONSTANTS)["NOT_EQ"] | (typeof CONSTANTS)["NOT_IN"]; }): this; /** * The 'orWhereSubQuery' method is used to add a conditional clause to a database query that involves a subquery. * * Subqueries also known as nested queries, are queries that are embedded within the main query. * * They are often used when you need to perform a query to retrieve some values and then use those values as part of the condition in the main query. * @param {string} column * @param {string} subQuery * @returns {this} */ orWhereSubQuery(column: string, subQuery: string | Builder, options?: { operator?: (typeof CONSTANTS)["EQ"] | (typeof CONSTANTS)["IN"]; }): this; /** * The 'orWhereNotSubQuery' method is used to add a conditional clause to a database query that involves a subquery. * * Subqueries also known as nested queries, are queries that are embedded within the main query. * * They are often used when you need to perform a query to retrieve not some values and then use those values as part of the condition in the main query. * @param {string} column * @param {string} subQuery * @returns {this} */ orWhereNotSubQuery(column: string, subQuery: string | Builder, options?: { operator?: (typeof CONSTANTS)["NOT_EQ"] | (typeof CONSTANTS)["NOT_IN"]; }): this; /** * The 'whereBetween' method is used to add a conditional clause to a database query that checks if a specified column's value falls within a specified range of values. * * This method is useful when you want to filter records based on a column's value being within a certain numeric or date range. * @param {string} column * @param {array} array * @returns {this} */ whereBetween(column: string, array: [any, any]): this; /** * The 'orWhereBetween' method is used to add a conditional clause to a database query that checks if a specified column's value falls within a specified range of values. * * This method is useful when you want to filter records based on a column's value being within a certain numeric or date range. * @param {string} column * @param {array} array * @returns {this} */ orWhereBetween(column: string, array: [any, any]): this; /** * The 'whereNotBetween' method is used to add a conditional clause to a database query that checks if a specified column's value falls within a specified range of values. * * This method is useful when you want to filter records based on a column's value does not fall within a specified range of values. * @param {string} column * @param {array} array * @returns {this} */ whereNotBetween(column: string, array: any[]): this; /** * The 'orWhereNotBetween' method is used to add a conditional clause to a database query that checks if a specified column's value falls within a specified range of values. * * This method is useful when you want to filter records based on a column's value does not fall within a specified range of values. * @param {string} column * @param {array} array * @returns {this} */ orWhereNotBetween(column: string, array: any[]): this; /** * The 'whereNull' method is used to add a conditional clause to a database query that checks if a specified column's value is NULL. * * This method is helpful when you want to filter records based on whether a particular column has a NULL value. * @param {string} column * @returns {this} */ whereNull(column: string): this; /** * The 'orWhereNull' method is used to add a conditional clause to a database query that checks if a specified column's value is NULL. * * This method is helpful when you want to filter records based on whether a particular column has a NULL value. * @param {string} column * @returns {this} */ orWhereNull(column: string): this; /** * The 'whereNotNull' method is used to add a conditional clause to a database query that checks if a specified column's value is not NULL. * * This method is useful when you want to filter records based on whether a particular column has a non-null value. * @param {string} column * @returns {this} */ whereNotNull(column: string): this; /** * The 'orWhereNotNull' method is used to add a conditional clause to a database query that checks if a specified column's value is not NULL. * * This method is useful when you want to filter records based on whether a particular column has a non-null value. * @param {string} column * @returns {this} */ orWhereNotNull(column: string): this; /** * The 'whereSensitive' method is used to add conditions to a database query. * * It allows you to specify conditions that records in the database must meet in order to be included in the result set. * * The where method is need to perform a case-sensitive comparison in a query. * @param {string} column * @param {string?} operator = < > != !< !> * @param {any?} value * @returns {this} */ whereSensitive(column: string, operator?: any, value?: any): this; /** * The 'whereStrict' method is used to add conditions to a database query. * * It allows you to specify conditions that records in the database must meet in order to be included in the result set. * * The where method is need to perform a case-sensitive comparison in a query. * @param {string} column * @param {string?} operator = < > != !< !> * @param {any?} value * @returns {this} */ whereStrict(column: string, operator?: any, value?: any): this; /** * The 'orWhereSensitive' method is used to add conditions to a database query. * * It allows you to specify conditions that records in the database must meet in order to be included in the result set. * * The where method is need to perform a case-sensitive comparison in a query. * @param {string} column * @param {string?} operator = < > != !< !> * @param {any?} value * @returns {this} */ orWhereSensitive(column: string, operator?: any, value?: any): this; /** * The 'whereQuery' method is used to add conditions to a database query to create a grouped condition. * * It allows you to specify conditions that records in the database must meet in order to be included in the result set. * @param {Function} callback callback query * @returns {this} */ whereQuery(callback: Function): this; /** * The 'whereGroup' method is used to add conditions to a database query to create a grouped condition. * * It allows you to specify conditions that records in the database must meet in order to be included in the result set. * @param {function} callback callback query * @returns {this} */ whereGroup(callback: Function): this; /** * The 'orWhereQuery' method is used to add conditions to a database query to create a grouped condition. * * It allows you to specify conditions that records in the database must meet in order to be included in the result set. * @param {function} callback callback query * @returns {this} */ orWhereQuery(callback: Function): this; /** * The 'orWhereGroup' method is used to add conditions to a database query to create a grouped condition. * * It allows you to specify conditions that records in the database must meet in order to be included in the result set. * @param {function} callback callback query * @returns {this} */ orWhereGroup(callback: Function): this; /** * The 'whereAny' method is used to add conditions to a database query, * where either the original condition or the new condition must be true. * * If has only 2 arguments default operator '=' * @param {string[]} columns * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE'] * @param {any?} value * @returns {this} */ whereAny(columns: string[], operator?: any, value?: any): this; /** * The 'whereAll' method is used to clause to a database query. * * This method allows you to specify conditions that the retrieved records must meet. * * If has only 2 arguments default operator '=' * @param {string[]} columns * @param {string?} operator ['=', '<', '>' ,'!=', '!<', '!>' ,'LIKE'] * @param {any?} value * @returns {this} */ whereAll(columns: string[], operator?: any, value?: any): this; /** * The 'whereCases' method is used to add conditions with cases to a database query. * * It allows you to specify conditions that records in the database must meet in order to be included in the result set. * * @param {Array<{when , then}>} cases used to add conditions when and then * @param {string?} elseCase else when end of conditions * @returns {this} */ whereCases(cases: { when: string; then: string; }[], elseCase?: string): this; /** * The 'orWhereCases' method is used to add conditions with cases to a database query. * * It allows you to specify conditions that records in the database must meet in order to be included in the result set. * * @param {Array<{when , then}>} cases used to add conditions when and then * @param {string?} elseCase else when end of conditions * @returns {this} */ orWhereCases(cases: { when: string; then: string; }[], elseCase?: string): this; whereReference(tableAndLocalKey: string, tableAndForeignKey?: string): this; /** * select by cases * @param {array} cases array object [{ when : 'id < 7' , then : 'id is than under 7'}] * @param {string} as assign name * @returns {this} */ case(cases: { when: string; then: string; }[], as: string): this; /** * The 'join' method is used to perform various types of SQL joins between two or more database tables. * * Joins are used to combine data from different tables based on a specified condition, allowing you to retrieve data from related tables in a single query. * @param {string} localKey local key in current table * @param {string} referenceKey reference key in next table * @example * await new DB('users') * .select('users.id as userId','posts.id as postId','email') * .join('users.id','posts.id') * .join('posts.category_id','categories.id') * .where('users.id',1) * .where('posts.id',2) * .get() * @returns {this} */ join(localKey: `${string}.${string}` | ((join: Join) => Join), referenceKey?: `${string}.${string}`): this; /** * The 'rightJoin' method is used to perform a right join operation between two database tables. * * A right join, also known as a right outer join, retrieves all rows from the right table and the matching rows from the left table. * * If there is no match in the left table, NULL values are returned for columns from the left table * @param {string} localKey local key in current table * @param {string} referenceKey reference key in next table * @returns {this} */ rightJoin(localKey: `${string}.${string}` | ((join: Join) => Join), referenceKey?: `${string}.${string}`): this; /** * The 'leftJoin' method is used to perform a left join operation between two database tables. * * A left join retrieves all rows from the left table and the matching rows from the right table. * * If there is no match in the right table, NULL values are returned for columns from the right table. * @param {string} localKey local key in current table * @param {string} referenceKey reference key in next table * @returns {this} */ leftJoin(localKey: `${string}.${string}` | ((join: Join) => Join), referenceKey?: `${string}.${string}`): this; /** * The 'crossJoin' method performs a cross join operation between two or more tables. * * A cross join, also known as a Cartesian join, combines every row from the first table with every row from the second table. * @param {string} localKey local key in current table * @param {string} referenceKey reference key in next table * @returns {this} */ crossJoin(localKey: `${string}.${string}` | ((join: Join) => Join), referenceKey?: `${string}.${string}`): this; /** * The 'joinSubQuery' method is used to perform various types of SQL joins between two or more database tables. * * Joins are used to combine data from different tables based on a specified condition, allowing you to retrieve data from related tables in a single query. * @param {object} property object { localKey , foreignKey , sqlr } * @property {string} property.localKey local key in current table * @property {string} property.foreignKey reference key in next table * @property {string} property.sql sql string * @example * await new DB('users') * .joinSubQuery({ localKey : 'id' , foreignKey : 'userId' , sql : '....sql'}) * .get() * @returns {this} */ joinSubQuery({ localKey, foreignKey, sql, }: { localKey: string; foreignKey: string; sql: string | DB; }): this; /** * The 'orderBy' method is used to specify the order in which the results of a database query should be sorted. * * This method allows you to specify one or more columns by which the result set should be ordered, as well as the sorting direction (ascending or descending) for each column. * @param {string} column * @param {string?} order by default order = 'asc' but you can used 'asc' or 'desc' * @returns {this} */ orderBy(column: string, order?: "ASC" | "asc" | "DESC" | "desc"): this; /** * The 'orderByRaw' method is used to specify the order in which the results of a database query should be sorted. * * This method allows you to specify one or more columns by which the result set should be ordered, as well as the sorting direction (ascending or descending) for each column. * * This method allows you to specify raw-sql parameters for the query. * @param {string} column * @param {string?} order [order=asc] asc, desc * @returns {this} */ orderByRaw(column: string, order?: "ASC" | "asc" | "DESC" | "desc"): this; /** * The 'random' method is used to retrieve random records from a database table or to randomize the order in which records are returned in the query result set. * * @returns {this} */ random(): this; /** * The 'inRandom' method is used to retrieve random records from a database table or to randomize the order in which records are returned in the query result set. * * @returns {this} */ inRandom(): this; /** * The 'latest' method is used to specify the order in which the results of a database query should be sorted. * * This method allows you to specify one or more columns by which the result set should be ordered, as well as the sorting direction descending for each column. * @param {string?} columns [column=id] * @returns {this} */ latest(...columns: string[]): this; /** * The 'latestRaw' method is used to specify the order in which the results of a database query should be sorted. * * This method allows you to specify one or more columns by which the result set should be ordered, as well as the sorting direction descending for each column. * * This method allows you to specify raw-sql parameters for the query. * @param {string?} columns [column=id] * @returns {this} */ latestRaw(...columns: string[]): this; /** * The 'oldest' method is used to specify the order in which the results of a database query should be sorted. * * This method allows you to specify one or more columns by which the result set should be ordered, as well as the sorting direction ascending for each column. * @param {string?} columns [column=id] * @returns {this} */ oldest(...columns: string[]): this; /** * The 'oldestRaw' method is used to specify the order in which the results of a database query should be sorted. * * This method allows you to specify one or more columns by which the result set should be ordered, as well as the sorting direction ascending for each column. * * This method allows you to specify raw-sql parameters for the query. * @param {string?} columns [column=id] * @returns {this} */ oldestRaw(...columns: string[]): this; /** * The groupBy method is used to group the results of a database query by one or more columns. * * It allows you to aggregate data based on the values in specified columns, often in conjunction with aggregate functions like COUNT, SUM, AVG, and MAX. * * Grouping is commonly used for generating summary reports, calculating totals, and performing other aggregate operations on data. * @param {string?} columns [column=id] * @returns {this} */ groupBy(...columns: string[]): this; /** * The groupBy method is used to group the results of a database query by one or more columns. * * It allows you to aggregate data based on the values in specified columns, often in conjunction with aggregate functions like COUNT, SUM, AVG, and MAX. * * Grouping is commonly used for generating summary reports, calculating totals, and performing other aggregate operations on data. * * This method allows you to specify raw-sql parameters for the query. * @param {string?} columns [column=id] * @returns {this} */ groupByRaw(...columns: string[]): this; /** * The 'having' method is used to add a conditional clause to a database query that filters the result set after the GROUP BY operation has been applied. * * It is typically used in conjunction with the GROUP BY clause to filter aggregated data based on some condition. * * The having clause allows you to apply conditions to aggregated values, such as the result of COUNT, SUM, AVG, or other aggregate functions. * @param {string} condition * @returns {this} */ having(condition: string): this; /** * The 'limit' method is used to limit the number of records returned by a database query. * * It allows you to specify the maximum number of rows to retrieve from the database table. * @param {number=} n [number=1] * @returns {this} */ limit(n?: number): this; /** * The 'limit' method is used to limit the number of records returned by a database query. * * It allows you to specify the maximum number of rows to retrieve from the database table. * @param {number=} number [number=1] * @returns {this} */ take(number?: number): this; /** * The offset method is used to specify the number of records to skip from the beginning of a result set. * * It is often used in combination with the limit method for pagination or to skip a certain number of records when retrieving data from a database table. * @param {number=} n [number=1] * @returns {this} */ offset(n?: number): this; /** * The offset method is used to specify the number of records to skip from the beginning of a result set. * * It is often used in combination with the limit method for pagination or to skip a certain number of records when retrieving data from a database table. * @param {number=} number [number=1] * @returns {this} */ skip(number?: number): this; /** * 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. * @param {object} data * @param {array?} updateNotExists options for except update some records in your ${data} using name column(s) * @returns {this} this */ update(data: Record, updateNotExists?: string[]): Builder<"update">; /** * 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. * @param {object} data * @param {array?} updateNotExists options for except update some records in your ${data} using name column(s) * @returns {this} this */ updateMany(data: Record, updateNotExists?: string[]): Builder<"updateMany">; /** * 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`). * * @param {Array<{when: Record, columns: Record}>>} cases * An array of update cases. * - `when` is an object specifying the conditions to match records. * - `columns` is an object specifying the new values to set for the matched records. * * @returns {this} Returns the current instance for method chaining. * * @example * new User().updateCases([ * { when: { id: 1 }, columns: { status: 'active', updatedAt: new Date() } }, * { when: { id: 2 }, columns: { status: 'inactive', updatedAt: new Date() } } * ]); */ updateCases(cases: { condition: ((query: Builder) => Builder) | Record; columns: Record; }[]): Builder<"updateMany">; /** * The 'updateNotExists' 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 method will be update record if data is empty or null in the column values * @param {object} data * @returns {this} this */ updateNotExists(data: Record): Builder<'update'>; /** * The 'insert' method is used to insert a new record into a database table associated. * * It simplifies the process of creating and inserting records. * @param {object} data * @returns {this} this */ insert(data: Record): Builder<"create">; /** * The 'create' method is used to insert a new record into a database table associated. * * It simplifies the process of creating and inserting records. * @param {object} data * @returns {this} this */ create(data: Record): Builder<"create">; /** * 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. * @param {array} data create multiple data * @returns {this} this this */ createMultiple(data: any[]): Builder<"createMany">; /** * 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. * @param {array} data create multiple data * @returns {this} this this */ createMany(data: any[]): Builder<"createMany">; /** * The 'insertMultiple' 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. * @param {array} data create multiple data * @returns {this} this this */ insertMultiple(data: any[]): Builder<"createMany">; /** * The 'insertMany' 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. * @param {array} data create multiple data * @returns {this} this this */ insertMany(data: any[]): Builder<"createMany">; /** * 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. * @param {object} data create not exists data * @returns {this} this this */ createNotExists(data: Record): Builder<"create">; /** * The 'insertNotExists' 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. * @param {object} data insert not exists data * @returns {this} this this */ insertNotExists(data: Record & { length?: never; }): Builder<"create">; /** * 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. * @param {object} data insert data * @returns {this} this this */ createOrSelect(data: Record & { length?: never; }): Builder<'create'>; /** * The 'insertOrSelect' 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. * @param {object} data insert or update data * @returns {this} this this */ insertOrSelect(data: Record & { length?: never; }): Builder<'create'>; /** * The 'updateOrCreate' 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. * @param {object} data insert or update data * @returns {this} this this */ updateOrCreate(data: Record & { length?: never; }): Builder<"createOrUpdate">; /** * The 'updateOrInsert' 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. * @param {object} data insert or update data * @returns {this} this this */ updateOrInsert(data: Record & { length?: never; }): Builder<"createOrUpdate">; /** * The 'insertOrUpdate' 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. * @param {object} data insert or update data * @returns {this} this this */ insertOrUpdate(data: Record & { length?: never; }): Builder<"createOrUpdate">; /** * * 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. * @param {object} data create or update data * @returns {this} this this */ createOrUpdate(data: Record & { length?: never; }): Builder<"createOrUpdate">; /** * 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. * @returns {string} return sql query */ toString(): string; /** * The 'toSQL' 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. * @returns {string} return sql query */ toSQL(): string; /** * The 'toRawSQL' 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. * @returns {string} */ toRawSQL(): string; /** * The `getTableName` method is used to retrieve the name of the table * associated with the current context or model. * * @returns {string} The name of the table. */ getTableName(): string; /** * The `getColumns` method is used to retrieve detailed column information * from the database, including the column name, type, nullability, and default value. * * @returns {Promise>} * */ getColumns(): Promise<{ Field: string; ColumnType: string; Type: string; Nullable: "YES" | "NO"; Default: string | null; }[]>; /** * The 'showSchema' method is used to show schema table. * * @param {string=} table [table= current table name] * @returns {Promise} */ showSchema(table?: string, options?: { raw?: boolean; }): Promise; /** * The `getSchema` method is used to retrieve the column schema for the database * or a specific table, including details such as type, nullability, default values, * and key information. * * @returns {Promise>} * */ getSchema(): Promise<{ Field: string; Key: 'PRI' | ''; Type: string; Nullable: 'YES' | 'NO'; Default: string | null; Extra: string | null; }[]>; /** * The 'getFKs' method is used to get foreign key constraints for the database or a specific table. * * @param {string} [table] - Optional table name to filter foreign keys. If omitted, * foreign keys for all tables are returned. * @returns {Promise>} * */ getFKs(table?: string): Promise<{ Constraint: string; RefTable: string; RefColumn: string; Column: string; OnDelete: string; OnUpdate: string; }[]>; /** * The `hasFK` method is used to determine whether a specific foreign key * constraint exists in the database, optionally scoped to a given table. * * @param {{ constraint: string; table?: string }} params - Parameters object. * @param {string} params.constraint - The name of the foreign key constraint to check. * @param {string} [params.table] - Optional table name to limit the search. * @returns {Promise} * */ hasFK({ constraint, table }: { constraint: string; table?: string; }): Promise; /** * The `getChildFKs` method is used to retrieve foreign key constraints where the * specified table acts as the parent (referenced) table. If no table name is * provided, all child foreign key relationships in the database are returned. * * @param {string} [table] - Optional parent table name to filter child foreign keys. * @returns {Promise>} * */ getChildFKs(table?: string): Promise<{ Constraint: string; ChildTable: string; ChildColumn: string; ParentTable: string; ParentColumn: string; }[]>; /** * Adds a foreign key constraint to a table. * * This method checks whether the specified foreign key constraint already exists * on the table before attempting to create it. If the constraint exists, an error * will be thrown to prevent duplication. * * @async * @method addFK * @param {Object} params - Parameters for creating the foreign key. * @param {string} params.table - The name of the table where the foreign key will be added. * @param {string} params.tableRef - The referenced table name. * @param {string} params.key - The column in the current table that will act as the foreign key. * @param {string} params.constraint - The name of the foreign key constraint. * @param {Object} params.foreign - Foreign key configuration. * @param {string} params.foreign.references - The referenced column in the referenced table. * @param {string} params.foreign.onDelete - Action when a referenced row is deleted (e.g. CASCADE, SET NULL). * @param {string} params.foreign.onUpdate - Action when a referenced row is updated (e.g. CASCADE, RESTRICT). * * @throws {Error} If the specified foreign key constraint already exists. * * @returns {Promise} Resolves when the foreign key constraint is successfully created. */ addFK({ table, tableRef, key, constraint, foreign }: { table: string; tableRef: string; key: string; constraint: string; foreign: { references: string; onDelete: string; onUpdate: string; }; }): Promise; /** * The `dropFK` method is used to remove a foreign key constraint from the database. * If a table name is provided, the constraint will be dropped from that table; * otherwise, the constraint is dropped wherever it exists. * * @param {{ constraint: string; table?: string }} params - Parameters object. * @param {string} params.constraint - The name of the foreign key constraint to drop. * @param {string} [params.table] - Optional table name from which to drop the constraint. * @returns {Promise} */ dropFK({ constraint, table }: { constraint: string; table?: string; }): Promise; /** * The `getIndexes` method is used to retrieve index definitions from the database. * When a table name is provided, only indexes for that table are returned; * otherwise, indexes for all tables are included. * * @param {string} [table] - Optional table name to filter index results. * @returns {Promise>} * */ getIndexes(table?: string): Promise<{ Column: string; IndexName: string; IndexType: string; Nullable: 'YES' | 'NO'; Unique: 'YES' | 'NO'; }[]>; /** * The `hasIndex` method is used to determine whether a specific index exists * in the database, optionally limited to a given table. * * @param {{ index: string; table?: string }} params - Parameters object. * @param {string} params.index - The name of the index to check for. * @param {string} [params.table] - Optional table name to scope the index lookup. * @returns {Promise} * */ hasIndex({ name, table }: { name: string; table?: string; }): Promise; /** * Adds an index to a table. * * This method checks whether the specified index already exists on the table * before attempting to create it. If the index exists, an error will be thrown * to prevent duplication. * * @async * @method addIndex * @param {Object} params - Parameters for creating the index. * @param {string} params.name - The name of the index. * @param {string} [params.table] - The table where the index will be created. Defaults to the current model table. * @param {string[]} params.columns - The columns included in the index. * * @throws {Error} If the specified index already exists. * * @returns {Promise} Resolves when the index has been successfully created. */ addIndex({ name, table, columns }: { name: string; table?: string; columns: string[]; }): Promise; /** * Drops an index from a table. * * This method checks whether the specified index exists on the table * before attempting to drop it. If the index does not exist, an error * will be thrown. * * @async * @method dropIndex * @param {Object} params - Parameters for dropping the index. * @param {string} params.name - The name of the index to drop. * @param {string} [params.table] - The table from which the index will be removed. Defaults to the current model table. * * @throws {Error} If the specified index was not found. * * @returns {Promise} Resolves when the index has been successfully dropped. */ dropIndex({ name, table }: { name: string; table?: string; }): Promise; /** * Checks whether a unique constraint exists on a table. * * This method queries the database metadata to determine if the specified * unique constraint exists on the given table. * * @async * @method hasUnique * @param {Object} params - Parameters for checking the unique constraint. * @param {string} params.name - The name of the unique constraint. * @param {string} [params.table] - The table to check. Defaults to the current model table. * * @returns {Promise} Returns `true` if the unique constraint exists, otherwise `false`. */ hasUnique({ name, table }: { name: string; table?: string; }): Promise; /** * Adds a unique constraint to a table. * * This method checks whether the specified unique constraint already exists * on the table before attempting to create it. If the constraint already exists, * an error will be thrown to prevent duplication. * * @async * @method addUnique * @param {Object} params - Parameters for creating the unique constraint. * @param {string} params.name - The name of the unique constraint. * @param {string} [params.table] - The table where the unique constraint will be added. Defaults to the current model table. * @param {string[]} params.columns - The columns that will be included in the unique constraint. * * @throws {Error} If the specified unique constraint already exists. * * @returns {Promise} Resolves when the unique constraint has been successfully created. */ addUnique({ name, table, columns }: { name: string; table?: string; columns: string[]; }): Promise; /** * Drops a unique constraint from a table. * * This method checks whether the specified unique constraint exists * on the table before attempting to remove it. If the constraint does * not exist, an error will be thrown. * * @async * @method dropUnique * @param {Object} params - Parameters for dropping the unique constraint. * @param {string} params.name - The name of the unique constraint to drop. * @param {string} [params.table] - The table from which the unique constraint will be removed. Defaults to the current model table. * * @throws {Error} If the specified unique constraint was not found. * * @returns {Promise} Resolves when the unique constraint has been successfully dropped. */ dropUnique({ name, table }: { name: string; table?: string; }): Promise; /** * Checks whether a primary key constraint exists on a table. * * This method queries the database metadata to determine if the specified * table contains a primary key constraint. * * @async * @method hasPrimaryKey * @param {Object} [params={}] - Parameters for checking the primary key. * @param {string} [params.table] - The table to check. Defaults to the current model table. * * @returns {Promise} Returns `true` if the table has a primary key constraint, * otherwise `false`. */ hasPrimaryKey({ table }?: { table?: string; }): Promise; /** * Adds a primary key constraint to a table. * * This method checks whether the table already has a primary key * before attempting to create one. If a primary key already exists, * an error will be thrown. * * @async * @method addPrimaryKey * @param {Object} params - Parameters for creating the primary key. * @param {string} [params.table] - The table where the primary key will be added. Defaults to the current model table. * @param {string[]} params.columns - The column(s) that will form the primary key. * * @throws {Error} If the table already has a primary key constraint. * * @returns {Promise} Resolves when the primary key has been successfully created. */ addPrimaryKey({ table, columns }: { table?: string; columns: string[]; }): Promise; /** * Drops the primary key constraint from a table. * * This method checks whether the table has a primary key before * attempting to remove it. If no primary key exists, an error will be thrown. * * @async * @method dropPrimaryKey * @param {Object} [params={}] - Parameters for dropping the primary key. * @param {string} [params.table] - The table from which the primary key will be removed. Defaults to the current model table. * * @throws {Error} If the specified primary key constraint was not found. * * @returns {Promise} Resolves when the primary key constraint has been successfully removed. */ dropPrimaryKey({ table }?: { table?: string; }): Promise; /** * The 'bindColumn' method is used to concat table and column -> `users`.`id` * @param {string} column * @returns {string} return table.column */ bindColumn(column: string): string; /** * The 'debug' method is used to console.log raw SQL query that would be executed by a query builder * @param {boolean} debug debug sql statements * @returns {this} this this */ debug(debug?: boolean): this; /** * The 'dd' method is used to console.log raw SQL query that would be executed by a query builder * @param {boolean} debug debug sql statements * @returns {this} this this */ dd(debug?: boolean): this; /** * The 'hook' method is used function when execute returns a result to callback function * @param {Function} func function for callback result * @returns {this} */ hook(func: (results: any) => void): this; /** * The 'before' method is used function when execute returns a result to callback function * @param {Function} func function for callback result * @returns {this} */ before(func: Function): this; /** * * @param {Object} options options for connection database with credentials * @param {string} option.host * @param {number} option.port * @param {string} option.database * @param {string} option.user * @param {string} option.password * @returns {this} this */ connection(options: TConnectionOptions): this; loadOptionsEnv(env?: string): { readonly cluster: boolean; readonly driver: string; readonly host: string | undefined; readonly port: string | 3306; readonly username: string; readonly password: string; readonly database: string | undefined; } | null; /** * * @param {string} env load environment using with command line arguments * @returns {this} this */ loadEnv(env?: string): this; /** * make sure this connection has same transaction in pool connection * @param {object} connection pool database * @returns {this} this */ bind(connection: TPoolConnected | TConnection | TConnection): this; /** * This 'union' method is used to union statement sql * * @param {string} sql * @returns {this} this */ union(sql: string | Builder): this; /** * This 'union' method is used to union statement sql * * @param {string} sql * @returns {this} this */ unionAll(sql: string | Builder): this; /** * This 'rawQuery' method is used to execute sql statement * * @param {string} sql * @returns {promise} */ rawQuery(sql: string): Promise; /** * This 'rawQuery' method is used to execute sql statement * * @param {string} sql * @returns {promise} */ static rawQuery(sql: string): Promise; /** * * plus value then update * @param {string} column * @param {number} value * @returns {promise} */ increment(column?: string, value?: number): Promise; /** * * minus value then update * @param {string} column * @param {number} value * @returns {promise} */ decrement(column?: string, value?: number): Promise; version(): Promise; /** * The 'all' method is used to retrieve all records from a database table associated. * * It returns an array instances, ignore all condition. * @returns {promise} */ all(): Promise; /** * The 'find' method is used to retrieve a single record from a database table by its primary key. * * This method allows you to quickly fetch a specific record by specifying the primary key value, which is typically an integer id. * @param {number | string} primaryKey * @returns {promise} */ find(primaryKey: number | string): Promise | null>; /** * 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 * @param {object?} opts by default page = 1 , limit = 15 * @property {number?} opts.limit * @property {number?} opts.page * @property {boolean?} opts.distinct * @returns {promise} */ pagination(opts?: { limit?: number; page?: number; distinct?: boolean; }): Promise; /** * 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 * @param {object?} opts by default page = 1 , limit = 15 * @property {number?} opts.limit * @property {number?} opts.page * @property {boolean?} opts.distinct * @returns {promise} */ paginate(opts?: { limit?: number; page?: number; distinct?: boolean; }): Promise; /** * The 'cursorPagination' method is used to perform cursor-based pagination * on a set of database query results obtained through the Query Builder. * * It uses cursor-based pagination instead of offset pagination, making it * more efficient when navigating through large datasets. * * @param {Object?} opts query opts * @param {number?} opts.limit number of records per page, default is 15 * @param {string?} opts.cursor cursor used to retrieve the next page * @param {boolean?} opts.distinct whether to retrieve distinct records * @returns {Promise} */ cursorPagination(opts?: { limit?: number; cursor?: string; distinct?: boolean; }): Promise; /** * The 'cursorPaginate' method is used to perform cursor-based pagination * on a set of database query results obtained through the Query Builder. * * It uses cursor-based pagination instead of offset pagination, making it * more efficient when navigating through large datasets. * * @param {Object?} opts query opts * @param {number?} opts.limit number of records per page, default is 15 * @param {string?} opts.cursor cursor used to retrieve the next page * @param {boolean?} opts.distinct whether to retrieve distinct records * @returns {Promise} */ cursorPaginate(opts?: { limit?: number; cursor?: string; distinct?: boolean; }): Promise; /** * * The 'first' 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. * @param {Function?} cb callback function return query sql * @returns {promise} */ first(cb?: Function): 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. * @param {Function?} cb callback function return query sql * @returns {promise} */ findOne(cb?: Function): Promise | null>; /** * The 'firstOrError' 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. * * If record is null, this method will throw an error * @returns {promise} */ firstOrError(message: string, options?: Record): Promise>; /** * The 'findOneOrError' 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. * * If record is null, this method will throw an error * execute data return object | null * @returns {promise} */ findOneOrError(message: string, options?: Record): Promise>; /** * The 'get' 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. * @param {Function?} cb callback function return query sql * @returns {promise} */ get(cb?: Function): Promise; /** * The 'findMany' 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. * @param {Function?} cb callback function return query sql * @returns {promise} */ findMany(cb?: Function): Promise; /** * The 'explain' method is used to analyze the query execution plan * without executing the query itself. * * It retrieves the execution plan from the database and analyzes it * for potential performance issues such as full table scans, filesorts, * and temporary tables. * @param {string?} sql query for explain * @returns {Promise} query execution plan and analysis */ explain(sql?: string): Promise; /** * The 'lazy' method is used to retrieve and process records incrementally * without loading the entire result set into memory at once. * * It retrieves records in batches based on the specified limit and invokes * the callback for each record. The process continues until all records * have been retrieved and processed. * * The optional delayMs can be used to add a delay between each batch query, * which can help reduce database load when processing a large number of records. * * @param {Function} callback callback function that receives each retrieved record * @param {Object?} opts query opts * @param {number?} opts.limit number of records to retrieve per query * @param {number?} opts.offset number of records to skip before processing * @param {number?} opts.delayMs delay in milliseconds between each batch * @returns {Promise} */ lazy(callback: (result: any) => Promise | void, opts?: { limit?: number; offset?: number; delayMs?: number; }): Promise; /** * The 'chunk' method is used to retrieve records from the database in chunks * and process each chunk through a callback function. * * It retrieves records in batches based on the specified limit and invokes * the callback with each batch of records. The process continues until all * records have been retrieved and processed. * * The optional delayMs can be used to add a delay between each batch query, * which can help reduce database load when processing a large number of records. * * @param {Function} callback callback function that receives the retrieved records * @param {Object?} opts query opts * @param {number?} opts.limit number of records to retrieve per chunk * @param {number?} opts.offset number of records to skip before processing * @param {number?} opts.delayMs delay in milliseconds between each batch * @returns {Promise} */ chunk(callback: (results: any[]) => Promise | void, opts?: { limit?: number; offset?: number; delayMs?: number; }): Promise; /** * The 'stream' method is used to executes a SQL statement and asynchronously yields result rows. * * @returns {AsyncGenerator} An async generator that yields result rows. * * @example * ```ts * import { DB } from "tspace-mysql"; * * for await (const row of new DB('users').stream()) { * console.log(row); * } * ``` */ stream(): AsyncGenerator; /** * 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 [column=id] * @returns {promise} */ toArray(column?: string): 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. * @returns {promise} */ exists(): Promise; /** * 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 [column=id] * @returns {promise} */ count(column?: string): Promise; /** * The 'avg' method is used to calculate the average value of a numeric column in a database table. * * It calculates the mean value of the specified column for all records that match the query conditions and returns the result as a floating-point number. * @param {string=} column [column=id] * @returns {promise} */ avg(column?: string): Promise; /** * The 'sum' method is used to calculate the sum of values in a numeric column of a database table. * * It computes the total of the specified column's values for all records that match the query conditions and returns the result as a numeric value. * @param {string=} column [column=id] * @returns {promise} */ sum(column?: string): 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 [column=id] * @returns {promise} */ max(column?: string): 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 [column=id] * @returns {promise} */ min(column?: string): 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. * @returns {promise} */ delete(): Promise; /** * The 'deleteMany' method is used to delete records from a database table based on the specified query conditions. * * It allows you to remove more records that match certain criteria. * @returns {promise} */ deleteMany(): 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 or more records that match certain criteria. * * This method should be ignore the soft delete * @returns {promise} */ forceDelete(): Promise; /** * The 'getGroupBy' 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 record to new Map * @param {string} column * @example * const results = await new DB('posts') * .getGroupBy('user_id') * * // you can find with user id in the results * const postsByUserId1 = results.get(1) * @returns {promise} */ getGroupBy(column: string): Promise>; /** * The 'findGroupBy' 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 record to new Map * @param {string} column * @example * const results = await new DB('posts') * .findGroupBy('user_id') * * // you can find with user id in the results * const postsByUserId1 = results.get(1) * @returns {promise} */ findGroupBy(column: string): Promise>; /** * The 'save' method is used to persist a new 'Model' or new 'DB' instance or update an existing model instance in the database. * * It's a versatile method that can be used in various scenarios, depending on whether you're working with a new or existing record. * @returns {Promise} promise */ save({ waitMs }?: { waitMs?: number | undefined; }): Promise>; /** * * The 'makeSelectStatement' method is used to make select statement. * @returns {Promise} string */ makeSelectStatement(): Promise; /** * * The 'makeInsertStatement' method is used to make insert table statement. * @returns {Promise} string */ makeInsertStatement(): Promise; /** * * The 'makeUpdateStatement' method is used to make update table statement. * @returns {Promise} string */ makeUpdateStatement(): Promise; /** * * The 'makeDeleteStatement' method is used to make delete statement. * @returns {Promise} string */ makeDeleteStatement(): Promise; /** * * The 'makeCreateTableStatement' method is used to make create table statement. * @returns {Promise} string */ makeCreateTableStatement(): Promise; /** * The `getTables` method is used to retrieve a list of all table names * in the current database. * * @returns {Promise} A promise that resolves to an array of table names. * * @async */ getTables(): Promise; /** * The `getTable` method is used to retrieve a list of all table names * in the current database. * * @returns {Promise} A promise that resolves to an array of table names. * * @async */ hasTable(table: string): Promise; /** * * The 'showColumns' method is used to show columns table. * * @param {string=} table table name * @returns {Promise} */ showColumns(table?: string, options?: { raw?: boolean; }): Promise; /** * * The 'showValues' method is used to show values table. * * @param {string=} table table name * @returns {Promise} */ showValues(table?: string): Promise; /** * * The 'faker' method is used to insert a new records into a database table associated. * * It simplifies the process of creating and inserting records. * @param {number} rows number of rows * @returns {promise} */ faker(rows: number, cb?: (results: Record, index: number) => Record): Promise; /** * The 'truncate' method is used to clear all data in the table. * * @param {object} option * @property {boolean} option.force * @returns {promise} */ truncate({ force, dropFK }?: { force?: boolean; dropFK?: boolean; }): Promise; /** * * The 'drop' method is used to drop the table. * * @param {object} option * @property {boolean} option.force * @returns {promise} */ drop({ force, view, db }?: { force?: boolean; view?: boolean; db?: boolean; }): Promise; protected exceptColumns(): Promise; protected _updateHandler(column: string, value?: string | number | null | boolean): string; copyBuilder(instance: Builder, options?: { update?: boolean; insert?: boolean; delete?: boolean; where?: boolean; limit?: boolean; orderBy?: boolean; join?: boolean; offset?: boolean; groupBy?: boolean; select?: boolean; having?: boolean; }): Builder; getQueryBuilder(): QueryBuilder; protected _buildQueryStatement(): any; protected _resultHandler(data: any): any; protected _resultHandlerExists(data: any): any; protected _queryStatement(sql: string): Promise; protected _actionStatement(sql: string): Promise; private _insertNotExists; private _insert; private _insertMultiple; private _insertOrSelect; private _updateOrInsert; private _update; private _queryUpdate; private _queryInsert; private _queryInsertMultiple; protected _handleJoin(type: "INNER_JOIN" | "LEFT_JOIN" | "RIGHT_JOIN" | "CROSS_JOIN" | undefined, localKey: `${string}.${string}` | ((join: Join) => Join), referenceKey?: `${string}.${string}`): this; private _initClusterPool; private _initSinglePool; private _initPool; private _initConstants; private _initBuilder; } export { Builder }; export default Builder;