This commit is contained in:
2024-12-16 16:51:46 +02:00
parent e264956831
commit 96fbfb60e8
16 changed files with 250 additions and 295 deletions
+40 -40
View File
@@ -4,22 +4,22 @@ let db;
let dbo;
/**
* Manages database operations
* Manages database operations, управление на операциите към базата от данни
*/
class Db {
name = 'db';
/**
* Initializes the database plugin
* @param {App} app The application instance
* Initializes the database plugin, инициализация
* @param {App} app The application instance, апликация
*/
init(app){
}
/**
* Starts the database plugin
* @param {App} app The application instance
* Starts the database plugin, стартиране
* @param {App} app The application instance, апликация
*/
async start(app){
db = await MongoClient.connect(app.config.db.url, {maxPoolSize: 256});
@@ -36,10 +36,10 @@ 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 {ObjectId} Inserted Id
* Inserts a record in a db collection, добавяне на запис в базата от данни
* @param {string} collection The name of the collection, име на колекцията, в която да бъде добавен записа
* @param {Object} value The object to insert, стойност на записа
* @returns {ObjectId} Inserted Id, идентификатор на новия запис
*/
async create(collection, value){
try {
@@ -50,11 +50,11 @@ 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 {Object} A record
* 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 {Object} A record, запис
*/
async get(collection, key, projection){
try {
@@ -65,10 +65,10 @@ class Db {
}
/**
* Performs a database query
* @param {string} collection Collection name
* @param {Object} query A mongo db query
* @returns {Object[]} Array of records
* Performs a database query, проста заявка за търсене в базата от данни
* @param {string} collection Collection name, име на колекция
* @param {Object} query A mongo db query, заявка
* @returns {Object[]} Array of records, масив от записи
*/
async list(collection, query){
try {
@@ -84,10 +84,10 @@ class Db {
}
/**
* Performs a database aggregation according to a given pipeline
* @param {string} collection Database collection name
* @param {Object} specs aggregation definition (the pipeline)
* @returns {Object[]} Array of records
* Performs a database aggregation according to a given pipeline, сложна заявка (агрегираща) към базата от данни
* @param {string} collection Database collection name, име на колекция
* @param {Object} specs aggregation definition (the pipeline), дефиниция на заявката
* @returns {Object[]} Array of records, списък от записи
*/
async aggregate(collection, specs){
try {
@@ -100,11 +100,11 @@ class Db {
}
/**
* Finds the distinct values for a specified field across a single collection
* @param {string} collection Database collection name
* @param {Object} key The target field for the distinction
* @param {Object} query filter to be applied
* @returns {Object[]}
* Finds the distinct values for a specified field across a single collection, извличане на списък от уникални записи в колекция по зададени критерии
* @param {string} collection Database collection name, име на колекцията
* @param {Object} key The target field for the distinction, целеви атрибут, по който се търси уникалност
* @param {Object} query filter to be applied, филтър на записите в колекцията
* @returns {Object[]} Array of records, списък от записи
*/
async distinct(collection, key, query){
try {
@@ -114,11 +114,11 @@ class Db {
}
/**
* Updates a record in database by given key and value
* @param {Object} collection DB collection
* @param {Object} key The key/query which identifies the record to be updated
* @param {Object} value The new value for the record
* @returns {Object} The result from the update operation
* Updates a record in database by given key and value, обновяване на запис в базата данни по дадени ключ и стойност
* @param {Object} collection DB collection, име на колекцията
* @param {Object} key The key/query which identifies the record to be updated, ключ или заявка за идентификация на съществуващия запис
* @param {Object} value The new value for the record, нова стойност на записа
* @returns {Object} The result from the update operation, резултат от операцията
*/
async update(collection, key, value){
let r;
@@ -131,11 +131,11 @@ class Db {
}
/**
* Performs partial update on a record by given key and partial value
* @param {Object} collection Database collection
* @param {Object} key The key/query which identifies the record to be updated
* @param {Object} value The partial value to be updated
* @returns {Object} The result from the update operation
* Performs partial update on a record by given key and partial value, частично обновяване на запис в базата от данни
* @param {Object} collection Database collection, име на колекция
* @param {Object} key The key/query which identifies the record to be updated, ключ или заявка за идентификация на целевите обекти
* @param {Object} value The partial value to be updated, дефиниция на частичното обновяване
* @returns {Object} The result from the update operation, резултат от операцията
*/
async updateSet(collection, key, value){
let r;
@@ -147,9 +147,9 @@ class Db {
}
/**
* Removes a record from the database by given key
* @param {Object} collection Database collection
* @param {Object} key The key/query which identifies the record to be updated
* Removes a record from the database by given key, изтриване на запис от базата от данни по зададен критерий
* @param {Object} collection Database collection, име на колекцията
* @param {Object} key The key/query which identifies the record to be updated, ключ/заявка за идентификация на целевите записи
*/
async remove(collection, key){
try {