Compare commits
No commits in common. "da1a45e9f0fa805cc6a8a18fd279dcb5f0f62ace" and "ef5449509e690fda3681ab29df2138290edf9156" have entirely different histories.
da1a45e9f0
...
ef5449509e
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@navy.gif/wrappers",
|
"name": "@navy.gif/wrappers",
|
||||||
"version": "1.3.9",
|
"version": "1.3.8",
|
||||||
"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",
|
||||||
|
@ -187,7 +187,7 @@ class MongoDB {
|
|||||||
* @returns {WriteResult} Object containing the followint counts: Matched, Upserted, Modified
|
* @returns {WriteResult} Object containing the followint counts: Matched, Upserted, Modified
|
||||||
* @memberof Database
|
* @memberof Database
|
||||||
*/
|
*/
|
||||||
async updateMany (db: string, filter: MongoQuery, data: Document, upsert = false) {
|
async updateMany (db: string, filter: MongoQuery, data: object, upsert = false) {
|
||||||
|
|
||||||
if (!this.#db)
|
if (!this.#db)
|
||||||
throw new Error(`MongoDB not connected`);
|
throw new Error(`MongoDB not connected`);
|
||||||
@ -195,6 +195,7 @@ class MongoDB {
|
|||||||
throw new TypeError('Expecting collection name for the first argument');
|
throw new TypeError('Expecting collection name for the first argument');
|
||||||
if (!filter)
|
if (!filter)
|
||||||
throw new Error(`Cannot run update many without a filter, if you mean to update every single document, pass an empty object`);
|
throw new Error(`Cannot run update many without a filter, if you mean to update every single document, pass an empty object`);
|
||||||
|
|
||||||
if (typeof filter._id === 'string')
|
if (typeof filter._id === 'string')
|
||||||
filter._id = new ObjectId(filter._id);
|
filter._id = new ObjectId(filter._id);
|
||||||
|
|
||||||
@ -213,12 +214,13 @@ class MongoDB {
|
|||||||
* @returns {WriteResult} Object containing the followint counts: Matched, Upserted, Modified
|
* @returns {WriteResult} Object containing the followint counts: Matched, Upserted, Modified
|
||||||
* @memberof Database
|
* @memberof Database
|
||||||
*/
|
*/
|
||||||
async updateOne (db: string, filter: MongoQuery, data: Document, upsert = false) {
|
async updateOne (db: string, filter: MongoQuery, data: object, upsert = false) {
|
||||||
|
|
||||||
if (!this.#db)
|
if (!this.#db)
|
||||||
throw new Error(`MongoDB not connected`);
|
throw new Error(`MongoDB not connected`);
|
||||||
if (typeof db !== 'string')
|
if (typeof db !== 'string')
|
||||||
throw new TypeError('Expecting collection name for the first argument');
|
throw new TypeError('Expecting collection name for the first argument');
|
||||||
|
|
||||||
if (typeof filter._id === 'string')
|
if (typeof filter._id === 'string')
|
||||||
filter._id = new ObjectId(filter._id);
|
filter._id = new ObjectId(filter._id);
|
||||||
|
|
||||||
@ -237,14 +239,12 @@ class MongoDB {
|
|||||||
* @returns {WriteResult} Object containing the followint counts: Matched, Upserted, Modified
|
* @returns {WriteResult} Object containing the followint counts: Matched, Upserted, Modified
|
||||||
* @memberof Database
|
* @memberof Database
|
||||||
*/
|
*/
|
||||||
async insertOne (db: string, data: Document) {
|
async insertOne (db: string, data: object) {
|
||||||
|
|
||||||
if (!this.#db)
|
if (!this.#db)
|
||||||
throw new Error(`MongoDB not connected`);
|
throw new Error(`MongoDB not connected`);
|
||||||
if (typeof db !== 'string')
|
if (typeof db !== 'string')
|
||||||
throw new TypeError('Expecting collection name for the first argument');
|
throw new TypeError('Expecting collection name for the first argument');
|
||||||
if (typeof data._id === 'string')
|
|
||||||
data._id = new ObjectId(data._id);
|
|
||||||
|
|
||||||
this.#logger.debug(`Incoming insertOne query for ${db} with parameters ${inspect(data)}`);
|
this.#logger.debug(`Incoming insertOne query for ${db} with parameters ${inspect(data)}`);
|
||||||
const result = await this.#db.collection(db).insertOne(data);
|
const result = await this.#db.collection(db).insertOne(data);
|
||||||
@ -252,14 +252,12 @@ class MongoDB {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteOne (db: string, filter: Document) {
|
async deleteOne (db: string, filter: object) {
|
||||||
|
|
||||||
if (!this.#db)
|
if (!this.#db)
|
||||||
throw new Error(`MongoDB not connected`);
|
throw new Error(`MongoDB not connected`);
|
||||||
if (typeof db !== 'string')
|
if (typeof db !== 'string')
|
||||||
throw new TypeError('Expecting collection name for the first argument');
|
throw new TypeError('Expecting collection name for the first argument');
|
||||||
if (typeof filter._id === 'string')
|
|
||||||
filter._id = new ObjectId(filter._id);
|
|
||||||
|
|
||||||
this.#logger.debug(`Incoming deleteOne query for ${db} with parameters ${inspect(filter)}`);
|
this.#logger.debug(`Incoming deleteOne query for ${db} with parameters ${inspect(filter)}`);
|
||||||
const result = await this.#db.collection(db).deleteOne(filter);
|
const result = await this.#db.collection(db).deleteOne(filter);
|
||||||
@ -277,14 +275,12 @@ class MongoDB {
|
|||||||
* @returns
|
* @returns
|
||||||
* @memberof Database
|
* @memberof Database
|
||||||
*/
|
*/
|
||||||
async push (db: string, filter: Document, data: object, upsert = false) {
|
async push (db: string, filter: object, data: object, upsert = false) {
|
||||||
|
|
||||||
if (!this.#db)
|
if (!this.#db)
|
||||||
throw new Error(`MongoDB not connected`);
|
throw new Error(`MongoDB not connected`);
|
||||||
if (typeof db !== 'string')
|
if (typeof db !== 'string')
|
||||||
throw new TypeError('Expecting collection name for the first argument');
|
throw new TypeError('Expecting collection name for the first argument');
|
||||||
if (typeof filter._id === 'string')
|
|
||||||
filter._id = new ObjectId(filter._id);
|
|
||||||
|
|
||||||
this.#logger.debug(`Incoming push query for ${db}, with upsert ${upsert} and with parameters ${inspect(filter)} and data ${inspect(data)}`);
|
this.#logger.debug(`Incoming push query for ${db}, with upsert ${upsert} and with parameters ${inspect(filter)} and data ${inspect(data)}`);
|
||||||
const result = await this.#db.collection(db).updateOne(filter, { $push: data }, { upsert });
|
const result = await this.#db.collection(db).updateOne(filter, { $push: data }, { upsert });
|
||||||
@ -301,14 +297,12 @@ class MongoDB {
|
|||||||
* @returns {object}
|
* @returns {object}
|
||||||
* @memberof Database
|
* @memberof Database
|
||||||
*/
|
*/
|
||||||
random (db: string, filter: Document = {}, amount = 1) {
|
random (db: string, filter = {}, amount = 1) {
|
||||||
|
|
||||||
if (!this.#db)
|
if (!this.#db)
|
||||||
throw new Error(`MongoDB not connected`);
|
throw new Error(`MongoDB not connected`);
|
||||||
if (typeof db !== 'string')
|
if (typeof db !== 'string')
|
||||||
throw new TypeError('Expecting collection name for the first argument');
|
throw new TypeError('Expecting collection name for the first argument');
|
||||||
if (typeof filter._id === 'string')
|
|
||||||
filter._id = new ObjectId(filter._id);
|
|
||||||
|
|
||||||
this.#logger.debug(`Incoming random query for ${db} with parameters ${inspect(filter)} and amount ${amount}`);
|
this.#logger.debug(`Incoming random query for ${db} with parameters ${inspect(filter)} and amount ${amount}`);
|
||||||
|
|
||||||
@ -341,6 +335,18 @@ class MongoDB {
|
|||||||
await this.#db.collection(collection).createIndex(indices);
|
await this.#db.collection(collection).createIndex(indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// async getKey (key: string, collection = 'memoryStore') {
|
||||||
|
// const response = await this.findOne(collection, { key });
|
||||||
|
// if (response)
|
||||||
|
// return response.value;
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async setKey (key: string, value: object, collection = 'memoryStore') {
|
||||||
|
// await this.updateOne(collection, { key }, { value }, true);
|
||||||
|
// return value;
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { MongoDB };
|
export { MongoDB };
|
Loading…
Reference in New Issue
Block a user