57 lines
3.8 KiB
JavaScript
57 lines
3.8 KiB
JavaScript
"use strict";
|
|
const plugins = require('./smartdata.plugins');
|
|
class DbCollection {
|
|
constructor(nameArg, dbArg) {
|
|
this.collection = dbArg.db.collection(nameArg);
|
|
}
|
|
/**
|
|
* adds a validation function that all newly inserted and updated objects have to pass
|
|
*/
|
|
addObjectValidation(funcArg) { }
|
|
/**
|
|
* finds an object in the DbCollection
|
|
*/
|
|
find(docMatchArg) {
|
|
let done = plugins.q.defer();
|
|
this.collection.find(docMatchArg).toArray((err, docs) => {
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
done.resolve(docs);
|
|
});
|
|
return done.promise;
|
|
}
|
|
/**
|
|
* inserts object into the DbCollection
|
|
*/
|
|
insertOne(docArg) {
|
|
let done = plugins.q.defer();
|
|
this.checkDoc(docArg).then(() => {
|
|
this.collection.insertOne(docArg)
|
|
.then(() => { done.resolve(); });
|
|
});
|
|
return done.promise;
|
|
}
|
|
/**
|
|
* inserts many objects at once into the DbCollection
|
|
*/
|
|
insertMany(docArrayArg) {
|
|
let done = plugins.q.defer();
|
|
let checkDocPromiseArray = [];
|
|
for (let docArg of docArrayArg) {
|
|
checkDocPromiseArray.push(this.checkDoc(docArg));
|
|
}
|
|
plugins.q.all(checkDocPromiseArray).then(() => {
|
|
this.collection.insertMany(docArrayArg)
|
|
.then(() => { done.resolve(); });
|
|
});
|
|
return done.promise;
|
|
}
|
|
checkDoc(doc) {
|
|
let done = plugins.q.defer();
|
|
done.resolve();
|
|
return done.promise;
|
|
}
|
|
}
|
|
exports.DbCollection = DbCollection;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGlu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