UNPKG

puddysql

Version:

🍮 Powerful SQL toolkit for Node.js, built with flexibility and structure in mind. Easily manage SQLite3/PostgreSQL, advanced queries, smart tag systems, and full JSON-friendly filters.

75 lines (74 loc) 3.35 kB
export default PuddySqlEngine; declare class PuddySqlEngine { /** * Checks whether the SQL engine identifier is empty. * * Returns `true` if the SQL engine is either `null`, `undefined`, or an empty string. * * @returns {boolean} Whether the SQL engine is unset or empty. */ isSqlEngineEmpty(): boolean; /** * Returns the current SQL engine identifier used by this instance. * * Throws an error if the engine has not been defined. * * @returns {string} The name of the current SQL engine. * @throws {Error} If the SQL engine is not defined. */ getSqlEngine(): string; /** * Sets the SQL engine identifier for this instance. * * This can only be set once, and only with a valid string. * Subsequent attempts or invalid types will throw an error. * * @param {string} engine - The SQL engine name to set (e.g., 'sqlite3' or 'postgre'). * @throws {Error} If the SQL engine is already set or if the input is not a string. */ setSqlEngine(engine: string): void; /** * Checks if the given error message indicates a connection error based on the SQL engine in use. * * This method evaluates if the provided error message contains any known connection error codes * for the current SQL engine (PostgreSQL or SQLite3). * * @param {Error} err - The error message to check. * @returns {boolean} True if the error message matches any known connection error codes; otherwise, false. */ isConnectionError(err: Error): boolean; /** * Executes a query to get all rows from a database table. * @function * @async * @param {string} query - The SQL query to execute. * @param {any[*]} [params] - The parameters to bind to the query. * @param {string} [debugName] - Optional label or context name for the debug log. * @returns {Promise<any[*]>} A promise that resolves to an array of rows. * @throws {Error} Throws an error if the query fails. */ all: (query: string, params?: any[any], debugName?: string) => Promise<any[any]>; /** * Executes a query to get a single row from a database table. * @function * @async * @param {string} query - The SQL query to execute. * @param {any[*]} [params] - The parameters to bind to the query. * @param {string} [debugName] - Optional label or context name for the debug log. * @returns {Promise<Record<any, any>|null>} A promise that resolves to a single row object. * @throws {Error} Throws an error if the query fails. */ get: (query: string, params?: any[any], debugName?: string) => Promise<Record<any, any> | null>; /** * Executes an SQL statement to modify the database (e.g., INSERT, UPDATE). * @function * @async * @param {string} query - The SQL query to execute. * @param {any[*]} params - The parameters to bind to the query. * @param {string} [debugName] - Optional label or context name for the debug log. * @returns {Promise<Record<any, any>|null>} A promise that resolves to the result of the query execution. * @throws {Error} Throws an error if the query fails. */ run: (query: string, params: any[any], debugName?: string) => Promise<Record<any, any> | null>; #private; }