Compare commits
3 Commits
687494727b
...
ef5449509e
Author | SHA1 | Date | |
---|---|---|---|
ef5449509e | |||
93823c3a04 | |||
3f9cdc2d69 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -131,3 +131,4 @@ dist
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
credentials.json
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navy.gif/wrappers",
|
||||
"version": "1.3.7",
|
||||
"version": "1.3.8",
|
||||
"description": "Various wrapper classes I use in my projects",
|
||||
"repository": "https://git.corgi.wtf/Navy.gif/wrappers.git",
|
||||
"author": "Navy.gif",
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { inspect } from "node:util";
|
||||
import { MongoClient, MongoClientOptions, Db, Document, WithId, ObjectId, Filter } from "mongodb";
|
||||
import { MongoClient, MongoClientOptions, Db, Document, WithId, ObjectId, Filter, IndexSpecification } from "mongodb";
|
||||
import { IServer, ILogger, LoggerClientOptions } from "./interfaces/index.js";
|
||||
|
||||
type Credentials = {
|
||||
@ -327,7 +327,7 @@ class MongoDB {
|
||||
return this.#db.collection(coll);
|
||||
}
|
||||
|
||||
async ensureIndex (collection: string, indices: string[] = []) {
|
||||
async ensureIndex (collection: string, indices: IndexSpecification = []) {
|
||||
if (!this.#db)
|
||||
throw new Error(`MongoDB not connected`);
|
||||
if (!(indices instanceof Array))
|
||||
|
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