dear lord the amount of nesting

This commit is contained in:
Erik 2023-05-03 00:59:06 +03:00
parent 93823c3a04
commit ef5449509e
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68
3 changed files with 30 additions and 3 deletions

1
.gitignore vendored
View File

@ -131,3 +131,4 @@ dist
.yarn/install-state.gz
.pnp.*
credentials.json

View File

@ -149,6 +149,7 @@ class MariaDB {
this.#pool?.removeAllListeners();
resolve();
});
this.#pool = null;
});
}
@ -179,7 +180,7 @@ class MariaDB {
const connection = await this.getConnection();
try {
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)
reject(err);
else if (results)
@ -214,8 +215,8 @@ class MariaDB {
}
q (query: string, values: (string | number | string[] | number[])[], timeout?: number) {
return this.query(query, values, timeout);
q<T> (query: string, values: (string | number | string[] | number[])[], timeout?: number) {
return this.query<T>(query, values, timeout);
}
}

25
tests/test.js Normal file
View File

@ -0,0 +1,25 @@
import { readFileSync } from 'fs';
import { MariaDB } from '../build/esm/index.js';
const credentials = JSON.parse(readFileSync('./credentials.json', { encoding: 'utf-8' }));
const maria = new MariaDB({
createLogger: () => {
return {
debug: console.log,
info: console.log,
status: console.log,
warn: console.log,
error: console.error
};
}
}, {
load: true,
credentials
});
await maria.init();
await maria.query('INSERT INTO `test` (`dingle`, `bingle`) VALUES ?', [[ 1, 2 ], [ 3, 4 ], [ 5, 6 ]]);
await maria.close();