"use strict"; const plugins = require('./smartdata.plugins'); class DbCollection { constructor(nameArg, dbConnectionArg) { this.collection = dbConnectionArg.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().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); }); return done.promise; } checkDoc(doc) { let done = plugins.q.defer(); done.resolve(); return done.promise; } } exports.DbCollection = DbCollection; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFDekIsQ0FBQyxDQUQ2QztBQUc5QztJQUVJLFlBQVksT0FBZSxFQUFFLGVBQTZCO1FBQ3RELElBQUksQ0FBQyxVQUFVLEdBQUcsZUFBZSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDNUQsQ0FBQztJQUVEOztPQUVHO0lBQ0gsbUJBQW1CLENBQUMsT0FBTyxJQUFJLENBQUM7SUFFaEM7O09BRUc7SUFDSCxJQUFJLENBQUMsV0FBYztRQUNmLElBQUksSUFBS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