gameobject module dev

This commit is contained in:
2024-11-04 20:26:27 +02:00
parent 53350ef548
commit 2978f11869
20 changed files with 1391 additions and 114 deletions
+23 -1
View File
@@ -3,10 +3,13 @@ import { ObjectId, MongoClient } from 'mongodb';
let db;
let dbo;
/**
* Manages database operations
*/
class Db {
name = 'db';
init(app){
this.app = app;
}
async start(app){
@@ -23,6 +26,12 @@ class Db {
}
}
/**
* Inserts a record in a db collection
* @param {string} collection The name of the collection
* @param {Object} value The object to insert
* @returns Inserted Id
*/
async create(collection, value){
try {
delete value._id;
@@ -31,6 +40,13 @@ class Db {
}
}
/**
* Loads a record from db collection
* @param {string} collection The name of the collection
* @param {Object} key Record identifier
* @param {Object} projection What data to take from the object
* @returns A record
*/
async get(collection, key, projection){
try {
let res = await dbo.collection(collection).findOne(key, projection ? {projection} : undefined)
@@ -39,6 +55,12 @@ class Db {
}
}
/**
* Performs a database query
* @param {string} collection Collection name
* @param {Object} query A mongo db query
* @returns Array of records
*/
async list(collection, query){
try {
let cursor = dbo.collection(collection).find(query.query, query.project ? {projection: query.project} : undefined);