UNPKG

tspace-mysql

Version:

Tspace MySQL is a promise-based ORM for Node.js, designed with modern TypeScript and providing type safety for schema databases.

1,128 lines (1,127 loc) 80.9 kB
import { AbstractBuilder } from "./Abstracts/AbstractBuilder"; import { DB } from "./DB"; import { Join } from "./Join"; import { CONSTANTS } from "../constants"; import { QueryBuilder } from "./Driver"; import { TPagination, TConnectionOptions, TPoolConnected, TConnectionTransaction, TDriver } 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 * @returns {TDriver} driver */ driver(): TDriver; /** * The 'database' method is used to get current database * @returns {string} database */ database(): string; /** * 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?: boolean; nowait?: boolean; }): 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?: boolean; nowait?: boolean; }): 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?: boolean; nowait?: boolean; }): 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 '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<string, string | `${string}.${string}`>, alias: string): 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 */ selectArray(object: Record<string, `${string}.${string}`>, 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(): this; /** * 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<string, any>, 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): 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): 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<string, any>): 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<string, any>, updateNotExists?: string[]): this; /** * 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<string, any>, updateNotExists?: string[]): this; /** * 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<string, string | number | boolean | null | undefined>, columns: Record<string, string | number | boolean | null | undefined>}>>} 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<string, any>; columns: Record<string, any>; }[]): this; /** * 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<string, any>): this; /** * 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<string, any>): this; /** * 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<string, any>): this; /** * 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[]): this; /** * 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[]): this; /** * 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[]): this; /** * 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[]): this; /** * 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<string, any>): this; /** * 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<string, any> & { length?: never; }): this; /** * 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<string, any> & { length?: never; }): this; /** * 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<string, any> & { length?: never; }): this; /** * 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<string, any> & { length?: never; }): this; /** * 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<string, any> & { length?: never; }): this; /** * 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<string, any> & { length?: never; }): this; /** * * 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<string, any> & { length?: never; }): this; /** * 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<Array<{ * Field: string; * ColumnType: string; * Type: string; * Nullable: 'YES' | 'NO'; * Default: string | null; * }>>} * */ getColumns(): Promise<{ Field: string; ColumnType: string; Type: string; Nullable: "YES" | "NO"; Default: string | null; }[]>; /**