Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
databases: [{
url: 'http://myserver.com/animals',
entities: {
fish: {}
}
}],
mapDocToEntity: doc => new Fish(doc)
});
let result = await db.find('fish', 'byName', {
selector: {
name: 'Great white'
}
});
assert.equals(result.length, 1);
assert.equals(result[0], { _id: 'F1', name: 'Great white' });
assert.equals(result[0].constructor, Fish);
},
'can find with implicit selector': async function () {
entities: {
fish: {}
}
}],
findHook() {
throw new Error('Invalid');
}
});
let err = await catchError(() => db.find('fish', 'byName', {
selector: {
name: 'Great white'
}
}));
assert.equals(err.message, 'Invalid');
},
'can set a default find limit': async function () {
let db = createDb({
databases: [{
url: 'http://myserver.com/animals',
entities: {
fish: {}
}
}],
mapDocToEntity: doc => new Fish(doc)
});
let result = await db.find('fish', 'byName', {
name: 'Great white'
});
assert.equals(result.length, 1);
assert.equals(result[0], { _id: 'F1', name: 'Great white' });
assert.equals(result[0].constructor, Fish);
},
'can rewrite index name': async function () {
entities: {
fish: {}
}
}],
findHook(type, index, args) {
args.foo = 'bar';
}
});
let result = await db.find('fish', 'byName', {
selector: {
name: 'Great white'
}
});
assert.equals(result, [{ _id: 'F1', name: 'Great white' }]);
},
'can use a hook to validate': async function () {
databases: [{
url: 'http://myserver.com/animals',
entities: {
fish: {}
}
}],
mapDocToEntity: doc => new Fish(doc)
});
let result = await db.find('fish', 'byName', {
name: 'Great white'
});
assert.equals(result.length, 1);
assert.equals(result[0], { _id: 'F1', name: 'Great white' });
assert.equals(result[0].constructor, Fish);
},
'can rewrite index name': async function () {