Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bulkAdd = async (table: string, records: Array | Object, ...otherRecords: Array) => {
const all = (records instanceof Array) ? records : [records, ...otherRecords];
try {
const allWithoutRevs = all.map(record => {
const recordWithoutRev = { ...record };
delete recordWithoutRev._rev;
return recordWithoutRev;
});
await this._dbs[table].bulkDocs(toDB(allWithoutRevs));
} catch (e) {
if (e.status === 409) {
throw new dbErrors.RecordNotUnique(e);
}
throw new dbErrors.UnknownError(e);
}
}
put = async (table: string, record: Object) => {
try {
await this._db.table(table).put(record);
} catch (e) {
if (e.name === 'ConstraintError') {
throw new dbErrors.RecordNotUnique(e);
}
throw new dbErrors.UnknownError(e);
}
}