Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions src/adapters/FsAdapter/methods/findCollection.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
const Collection = require('../../../types/Collection/Collection');
module.exports = async function findCollection(tyrInstance, dbName, colName, opts){
let col = undefined;
if(!dbName){
throw new Error("Expected dbName");
}
if(!colName){
throw new Error("Expected colName");
}
const path = `${tyrInstance.options.path}/${dbName}/${colName}/meta.json`
const exists = await this.queue.add('File.exists', path).getResults();
if(!exists){
//This is done to match MemoryAdapter way of failing a find
return col;
}
const meta = await this.queue.add('File.read',path).getResults();
col = new Collection(Object.assign(meta,{ adapter:this, tyrInstance}, opts));

return new Promise((resolve)=>{
col.emitter.on('ready', ()=>{
return resolve(col)
})
})
}
module.exports = async function findCollection(tyrInstance, dbName, colName, opts) {
let col;
if (!dbName) {
throw new Error('Expected dbName');
}
if (!colName) {
throw new Error('Expected colName');
}
const path = `${tyrInstance.options.path}/${dbName}/${colName}/meta.json`;
let job = await this.queue.add('File.exists', path).execution();
const exists = job.result;
if (!exists) {
// This is done to match MemoryAdapter way of failing a find
return col;
}
job = await this.queue.add('File.read', path).execution();
const meta = job.result;
col = new Collection(Object.assign(meta, { adapter: this, tyrInstance }, opts));

return new Promise((resolve) => {
col.emitter.on('ready', () => resolve(col));
});
};
31 changes: 17 additions & 14 deletions src/adapters/FsAdapter/methods/findDatabase.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
const Database = require('../../../types/Database/Database');
module.exports = async function findDatabase(tyrInstance, dbName, opts){
let db = undefined;
if(!dbName){
throw new Error("Expected dbName");

module.exports = async function findDatabase(tyrInstance, dbName, opts) {
let db;
if (!dbName) {
throw new Error('Expected dbName');
}
const job = await this.queue.add('File.exists', `${tyrInstance.options.path}/${dbName}/meta.json`);
await job.execution();
let job = await this.queue.add('File.exists', `${tyrInstance.options.path}/${dbName}/meta.json`).execution();

const exists = job.results
if(!exists){
//This is done to match MemoryAdapter way of failing a find
const exists = job.results;
if (!exists) {
// This is done to match MemoryAdapter way of failing a find
return db;
}
const meta = await this.queue
.add('File.read',`${tyrInstance.options.path}/${dbName}/meta.json`)
.getResults();

db = new Database(Object.assign(meta,{ adapter:this, tyrInstance}));
job = await this.queue
.add('File.read', `${tyrInstance.options.path}/${dbName}/meta.json`)
.execution();

const meta = job.result;

db = new Database(Object.assign(meta, { adapter: this, tyrInstance }));
return db;
}
};