something is working

This commit is contained in:
quoije
2022-09-15 01:55:36 -04:00
parent a0aa251c27
commit f38e69883c
1123 changed files with 251731 additions and 11 deletions
+47
View File
@@ -0,0 +1,47 @@
'use strict';
/**
* methods a collection must implement
*/
const methods = [
'find',
'findOne',
'update',
'updateMany',
'updateOne',
'replaceOne',
'remove',
'count',
'distinct',
'findOneAndDelete',
'findOneAndUpdate',
'aggregate',
'findCursor',
'deleteOne',
'deleteMany'
];
/**
* Collection base class from which implementations inherit
*/
function Collection() {}
for (let i = 0, len = methods.length; i < len; ++i) {
const method = methods[i];
Collection.prototype[method] = notImplemented(method);
}
module.exports = exports = Collection;
Collection.methods = methods;
/**
* creates a function which throws an implementation error
*/
function notImplemented(method) {
return function() {
throw new Error('collection.' + method + ' not implemented');
};
}
+13
View File
@@ -0,0 +1,13 @@
'use strict';
const env = require('../env');
if ('unknown' == env.type) {
throw new Error('Unknown environment');
}
module.exports =
env.isNode ? require('./node') :
env.isMongo ? require('./collection') :
require('./collection');
+132
View File
@@ -0,0 +1,132 @@
'use strict';
/**
* Module dependencies
*/
const Collection = require('./collection');
class NodeCollection extends Collection {
constructor(col) {
super();
this.collection = col;
this.collectionName = col.collectionName;
}
/**
* find(match, options, function(err, docs))
*/
find(match, options, cb) {
const cursor = this.collection.find(match, options);
try {
cursor.toArray(cb);
} catch (error) {
cb(error);
}
}
/**
* findOne(match, options, function(err, doc))
*/
findOne(match, options, cb) {
this.collection.findOne(match, options, cb);
}
/**
* count(match, options, function(err, count))
*/
count(match, options, cb) {
this.collection.count(match, options, cb);
}
/**
* distinct(prop, match, options, function(err, count))
*/
distinct(prop, match, options, cb) {
this.collection.distinct(prop, match, options, cb);
}
/**
* update(match, update, options, function(err[, result]))
*/
update(match, update, options, cb) {
this.collection.update(match, update, options, cb);
}
/**
* update(match, update, options, function(err[, result]))
*/
updateMany(match, update, options, cb) {
this.collection.updateMany(match, update, options, cb);
}
/**
* update(match, update, options, function(err[, result]))
*/
updateOne(match, update, options, cb) {
this.collection.updateOne(match, update, options, cb);
}
/**
* replaceOne(match, update, options, function(err[, result]))
*/
replaceOne(match, update, options, cb) {
this.collection.replaceOne(match, update, options, cb);
}
/**
* deleteOne(match, options, function(err[, result])
*/
deleteOne(match, options, cb) {
this.collection.deleteOne(match, options, cb);
}
/**
* deleteMany(match, options, function(err[, result])
*/
deleteMany(match, options, cb) {
this.collection.deleteMany(match, options, cb);
}
/**
* remove(match, options, function(err[, result])
*/
remove(match, options, cb) {
this.collection.remove(match, options, cb);
}
/**
* findOneAndDelete(match, options, function(err[, result])
*/
findOneAndDelete(match, options, cb) {
this.collection.findOneAndDelete(match, options, cb);
}
/**
* findOneAndUpdate(match, update, options, function(err[, result])
*/
findOneAndUpdate(match, update, options, cb) {
this.collection.findOneAndUpdate(match, update, options, cb);
}
/**
* var cursor = findCursor(match, options)
*/
findCursor(match, options) {
return this.collection.find(match, options);
}
/**
* aggregation(operators..., function(err, doc))
* TODO
*/
}
/**
* Expose
*/
module.exports = exports = NodeCollection;