@ocap/indexdb-elasticsearch
Version:
OCAP indexdb adapter that uses elasticsearch as backend
36 lines (29 loc) • 860 B
JavaScript
/* eslint-disable no-underscore-dangle */
const omit = require('lodash/omit');
const ESIndex = require('./base');
const getParams = require('../model/asset');
const { getTableName } = require('../util');
class Asset extends ESIndex {
constructor(db) {
super({
name: getTableName(db.config.prefix, 'asset'),
docId: 'address',
client: db.client,
http: db.http,
indexParams: getParams(),
});
}
batchInsert(rows) {
return super.batchInsert(rows.map((row) => Asset.formatRowBeforeInsert(row)));
}
// eslint-disable-next-line require-await
async _insert(row) {
return super._insert(Asset.formatRowBeforeInsert(row));
}
}
Asset.formatRowBeforeInsert = (row) => {
const tmpRow = omit(row, ['context']);
Object.assign(tmpRow, { ...(row.context || '') });
return tmpRow;
};
module.exports = Asset;