import DBConnection from "./db/DBConnection.js"; import { Logger } from "./Logger.js"; import CommonSearchCriteria from "./db/CommonSearchCriteria.js"; import PaginationList from "./db/PaginationList.js"; /** * Quick search result interface. * @template T Type of items in the list. */ export interface QuickSearchResult { /** * Result list. */ list: Array; /** * Whether more data is available beyond the current page. */ hasMore: boolean; } export default abstract class CommonDAO { protected readonly logger: Logger; protected constructor(); /** * Retrieves the database connection for the current execution thread (transaction-aware). * - Returns active transaction connection if inside a transaction. * - Otherwise throws an error if no connection is active in the context. */ protected getDBConnection(): Promise; /** * Generates a 32-character UUID string. * @protected * @returns Generated 32-character UUID string. */ protected genID(): string; /** * Executes a count query and returns the count value. * Handles NaN gracefully. * @param sql - Count SQL query to execute. * @param params - Array of SQL query parameters. * @param key - Key name of the count column, defaults to 'cc'. * @protected * @returns Promise resolving to the count number. */ protected executeCountSQL(sql: string, params: Array, key?: string): Promise; /** * Converts a boolean value to an integer (true=1, false=0). * @param value - Boolean value to convert. * @protected * @returns Integer value (1 or 0). */ protected getBooleanValue(value: boolean): number; /** * Converts a boolean value to a character ('T' or 'F'). * @param value - Boolean value to convert. * @protected * @returns String ('T' or 'F'). */ protected getBoolean(value: boolean): string; /** * Quick paginated search query using driver-independent limit/offset clauses. * @template T - Type of items in the result list. * @param sql - Base SQL query statement. * @param params - Array of SQL query parameters (defaults to empty array). * @param pageNo - Page number (defaults to 1). * @param rowCount - Number of rows per page (defaults to 25). * @param booleanFields - Field names to coerce to boolean (supports nested properties like 'user.isActive'). * @protected * @returns Promise resolving to QuickSearchResult containing list data and hasMore flag. */ protected quickSearch(sql: string, params?: Array, pageNo?: number, rowCount?: number, booleanFields?: Array): Promise>; /** * Executes a query and returns the first row of the result. * @param sql - SQL query statement to execute. * @param params - Array of SQL query parameters (defaults to empty array). * @protected * @returns Promise resolving to the first row, or null if no rows match. */ protected findFirst(sql: string, params?: Array): Promise; protected findByPK(sql: string, params?: Array): Promise; /** * Executes a query and returns all matching rows as a list. * @param sql - SQL query statement to execute. * @param params - Array of SQL query parameters (defaults to empty array). * @protected * @returns Promise resolving to the array of result rows. */ protected listQuery(sql: string, params?: Array): Promise; /** * Executes an INSERT statement. * @param sql - INSERT SQL statement to execute. * @param params - Array of SQL query parameters (defaults to empty array). * @protected * @returns Promise resolving to the insert result (driver-specific, e.g. generated key). */ protected executeInsertQuery(sql: string, params?: Array): Promise; /** * Executes an UPDATE statement. * @param sql - UPDATE SQL statement to execute. * @param params - Array of SQL query parameters (defaults to empty array). * @protected * @returns Promise resolving to the update result (driver-specific, e.g. affected row count). */ protected executeUpdateQuery(sql: string, params?: Array): Promise; /** * Executes a DELETE statement and returns the number of deleted rows. * @param sql - DELETE SQL statement to execute. * @param params - Array of SQL query parameters (defaults to empty array). * @protected * @returns Promise resolving to the number of deleted rows. */ protected executeDeleteQuery(sql: string, params?: Array): Promise; /** * Executes a paginated search query using the provided CommonSearchCriteria object. * Automatically obtains the active database connection from the current context. * @param criteria - CommonSearchCriteria instance defining dynamic query conditions, pagination, and sorting. * @protected * @returns Promise resolving to PaginationList containing paginated records and metadata. */ protected executePaginationQuery(criteria: CommonSearchCriteria): Promise; }