Compare commits

..

4 Commits

Author SHA1 Message Date
1a45c35090 v1.6.6 2023-10-14 12:49:27 +03:00
e3e7623c27 throw clear error about unavailable db nodes 2023-10-14 12:48:57 +03:00
a82dacdc30 v1.6.5 2023-10-11 14:40:26 +03:00
8230fa376b Cap length of debug outputs 2023-10-11 14:39:52 +03:00
2 changed files with 7 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@navy.gif/wrappers", "name": "@navy.gif/wrappers",
"version": "1.6.4", "version": "1.6.6",
"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

@ -337,6 +337,9 @@ class MariaDB
const pool = this.#pool; const pool = this.#pool;
if (nodeName) if (nodeName)
{ {
const available = this.#nodes.filter(n => n.status === 'synced');
if (!available.length)
throw new Error('No nodes available for query');
const node = this.#nodes.find(n => n.name === nodeName); const node = this.#nodes.find(n => n.name === nodeName);
if (!node) if (!node)
{ {
@ -358,7 +361,7 @@ class MariaDB
this.#logger.debug(`Selected node ${nodeName} for query`); this.#logger.debug(`Selected node ${nodeName} for query`);
return pool.of(nodeName ?? '*').getConnection((err, conn) => return pool.of(nodeName ?? '*').getConnection((err, conn) =>
{ {
if (err) if (err)
return reject(err); return reject(err);
return resolve(conn); return resolve(conn);
}); });
@ -391,7 +394,7 @@ class MariaDB
resolve(fields); resolve(fields);
connection.release(); connection.release();
}); });
this.#logger.debug(`Constructed query: ${q.sql}`); this.#logger.debug(`Constructed query: ${q.sql.substring(0, 1024)}`);
}); });
return Promise.resolve(result || []); return Promise.resolve(result || []);
} }
@ -421,7 +424,7 @@ class MariaDB
let batch = false; let batch = false;
if (values && typeof values.some === 'function') if (values && typeof values.some === 'function')
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).substring(0, 1024)}`);
return this.#_query<T>(query, values ?? [], opts); return this.#_query<T>(query, values ?? [], opts);