Compare commits

...

4 Commits

Author SHA1 Message Date
687494727b
v1.3.7 2023-04-30 00:42:22 +03:00
29230e01a8
no null 2023-04-30 00:42:12 +03:00
ac127428b2
v1.3.6 2023-04-30 00:40:28 +03:00
c61af94efc
Type support for maria 2023-04-30 00:40:13 +03:00
2 changed files with 6 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@navy.gif/wrappers", "name": "@navy.gif/wrappers",
"version": "1.3.5", "version": "1.3.7",
"description": "Various wrapper classes I use in my projects", "description": "Various wrapper classes I use in my projects",
"repository": "https://git.corgi.wtf/Navy.gif/wrappers.git", "repository": "https://git.corgi.wtf/Navy.gif/wrappers.git",
"author": "Navy.gif", "author": "Navy.gif",

View File

@ -175,10 +175,10 @@ class MariaDB {
* @throws {MariaError} * @throws {MariaError}
* @private * @private
* */ * */
async #_query (query: string, values: (string | number | string[] | number[])[], timeout?: number, attempts = 0): Promise<object[] | FieldInfo[] | null> { async #_query<T> (query: string, values: (string | number | string[] | number[])[], timeout?: number, attempts = 0): Promise<T[] | FieldInfo[]> {
const connection = await this.getConnection(); const connection = await this.getConnection();
try { try {
const result = await new Promise<object[] | FieldInfo[] | undefined>((resolve, reject) => { const result = await new Promise<T[] | FieldInfo[] | undefined>((resolve, reject) => {
const q = connection.query({ timeout, sql: query }, values, (err, results, fields) => { const q = connection.query({ timeout, sql: query }, values, (err, results, fields) => {
if (err) if (err)
reject(err); reject(err);
@ -190,7 +190,7 @@ class MariaDB {
}); });
this.#logger.debug(`Constructed query: ${q.sql}`); this.#logger.debug(`Constructed query: ${q.sql}`);
}); });
return Promise.resolve(result ?? null); return Promise.resolve(result || []);
} catch (err) { } catch (err) {
const error = err as MariaError; const error = err as MariaError;
// Retry safe errors // (Galera) Instance not ready for query // Retry safe errors // (Galera) Instance not ready for query
@ -200,7 +200,7 @@ class MariaDB {
} }
} }
async query (query: string, values: (string | number | string[] | number[])[], timeout?: number) { async query<T> (query: string, values: (string | number | string[] | number[])[], timeout?: number): Promise<T[] | FieldInfo[]> {
if (!this.ready) if (!this.ready)
return Promise.reject(new Error('MariaDB not ready')); return Promise.reject(new Error('MariaDB not ready'));
@ -210,7 +210,7 @@ class MariaDB {
batch = values.some(val => val instanceof Array); batch = values.some(val => val instanceof Array);
this.#logger.debug(`Incoming query (batch: ${batch})\n${query}\n${inspect(values)}`); this.#logger.debug(`Incoming query (batch: ${batch})\n${query}\n${inspect(values)}`);
return this.#_query(query, values, timeout); return this.#_query<T>(query, values, timeout);
} }