Compare commits
4 Commits
f70d15583c
...
687494727b
Author | SHA1 | Date | |
---|---|---|---|
687494727b | |||
29230e01a8 | |||
ac127428b2 | |||
c61af94efc |
@ -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",
|
||||||
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user