Compare commits

..

3 Commits

Author SHA1 Message Date
ef5449509e
dear lord the amount of nesting 2023-05-03 00:59:06 +03:00
93823c3a04
v1.3.8 2023-04-30 22:35:04 +03:00
3f9cdc2d69
mongo index specification type 2023-04-30 22:34:47 +03:00
5 changed files with 33 additions and 6 deletions

1
.gitignore vendored
View File

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

View File

@ -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",

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);
}
}

View File

@ -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
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();