dear lord the amount of nesting
This commit is contained in:
parent
93823c3a04
commit
ef5449509e
1
.gitignore
vendored
1
.gitignore
vendored
@ -131,3 +131,4 @@ dist
|
|||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
|
credentials.json
|
||||||
|
@ -149,6 +149,7 @@ class MariaDB {
|
|||||||
this.#pool?.removeAllListeners();
|
this.#pool?.removeAllListeners();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
this.#pool = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +180,7 @@ class MariaDB {
|
|||||||
const connection = await this.getConnection();
|
const connection = await this.getConnection();
|
||||||
try {
|
try {
|
||||||
const result = await new Promise<T[] | 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);
|
||||||
else if (results)
|
else if (results)
|
||||||
@ -214,8 +215,8 @@ class MariaDB {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
q (query: string, values: (string | number | string[] | number[])[], timeout?: number) {
|
q<T> (query: string, values: (string | number | string[] | number[])[], timeout?: number) {
|
||||||
return this.query(query, values, timeout);
|
return this.query<T>(query, values, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
25
tests/test.js
Normal file
25
tests/test.js
Normal 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();
|
Loading…
Reference in New Issue
Block a user