mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 10:46:00 +00:00
read json lines field values
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const { filterName } = require('dbgate-tools');
|
||||
const fs = require('fs');
|
||||
const lineReader = require('line-reader');
|
||||
const _ = require('lodash');
|
||||
@@ -148,6 +149,19 @@ module.exports = {
|
||||
return {};
|
||||
},
|
||||
|
||||
loadFieldValues_meta: true,
|
||||
async loadFieldValues({ jslid, field, search }) {
|
||||
const datastore = await this.ensureDatastore(jslid);
|
||||
const res = new Set();
|
||||
await datastore.enumRows(row => {
|
||||
if (!filterName(search, row[field])) return true;
|
||||
res.add(row[field]);
|
||||
return res.size < 100;
|
||||
});
|
||||
// @ts-ignore
|
||||
return [...res].map(value => ({ value }));
|
||||
},
|
||||
|
||||
async notifyChangedStats(stats) {
|
||||
// console.log('SENDING STATS', JSON.stringify(stats));
|
||||
const datastore = this.datastores[stats.jslid];
|
||||
|
||||
@@ -159,6 +159,18 @@ class JsonLinesDatastore {
|
||||
}
|
||||
}
|
||||
|
||||
async enumRows(eachRow) {
|
||||
await lock.acquire('reader', async () => {
|
||||
await this._ensureReader(0, null);
|
||||
for (;;) {
|
||||
const line = await this._readLine(true);
|
||||
if (line == null) break;
|
||||
const shouldContinue = eachRow(line);
|
||||
if (!shouldContinue) break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async getRows(offset, limit, filter) {
|
||||
const res = [];
|
||||
await lock.acquire('reader', async () => {
|
||||
|
||||
Reference in New Issue
Block a user