Skip to content

Commit

Permalink
feat: expose db driver to reduce dependency in consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-lara committed Jan 4, 2023
1 parent 538c823 commit 7f3e511
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/database/src/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ class Database extends Clonable {
return this.collections[name];
}

createId(key) {
return this.getAdapter().createId(key);
}

find(name, condition, limit) {
return this.getAdapter(name).find(name, condition, limit);
}
Expand Down
8 changes: 7 additions & 1 deletion packages/mongodb-adapter/src/mongodb-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

const { MongoClient, ObjectId } = require('mongodb');
const mongodb = require('mongodb');
const { Clonable } = require('@nlpjs/core');

const { MongoClient, ObjectId } = mongodb;
const idField = '_id';

class MongodbAdapter extends Clonable {
Expand Down Expand Up @@ -52,6 +53,7 @@ class MongodbAdapter extends Clonable {
useUnifiedTopology: true,
});
this.registerDefault();
this.driver = mongodb;
}

registerDefault() {
Expand Down Expand Up @@ -134,6 +136,10 @@ class MongodbAdapter extends Clonable {
});
}

createId(key) {
return new ObjectId(key);
}

async find(name, condition, limit, offset, sort) {
return this.executeInCollection(name, (collection, cb) => {
const options = {};
Expand Down

0 comments on commit 7f3e511

Please sign in to comment.