UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

37 lines 1.96 kB
/** * Initializes and caches one or more MySQL database connections using provided configuration. * Supports Firebase and Google Cloud SQL socket-based connections, as well as local/standard MySQL setups. * * @async * @param {Record<string, any>} mysql - The `mysql2` module or similar instance, with a `.createPool()` method. * @param {string} proxyType - The type of proxy connection. Can be `"default"`, `"firebase"`, or `"google_cloud"`. * @param {Record<string, any>|Record<string, any>[]} databases - A single database config object or an array of config objects. * @param {Record<string, any>} cfg - Global fallback configuration, e.g., `{ charset: 'utf8mb4' }`. * * @returns {Promise<Record<string, any>>} Resolves with a single connection object if one database is provided, * or a map of database names to connections if multiple databases are configured. * * @throws {Error} Will reject if any database config is invalid or if the proxyType is unsupported. * * @example * const connection = await create(mysql, 'default', { * data: { database: 'my_db', user: 'root', password: 'pass', host: 'localhost', port: 3306 }, * default: { host: 'localhost', port: 3306 }, * }); * * @example * const connections = await create(mysql, 'google_cloud', [ * { * data: { database: 'db1', user: 'user', password: 'pass' }, * google_cloud: { socketPath: '/cloudsql/project:region:instance' }, * default: { host: 'localhost', port: 3306 }, * }, * { * data: { database: 'db2', user: 'user', password: 'pass' }, * google_cloud: { socketPath: '/cloudsql/project:region:instance2' }, * default: { host: 'localhost', port: 3306 }, * } * ]); */ export default function create(mysql: Record<string, any>, proxyType: string, databases: Record<string, any> | Record<string, any>[], cfg: Record<string, any>): Promise<Record<string, any>>; //# sourceMappingURL=create.d.mts.map