read json lines field values

This commit is contained in:
Jan Prochazka 2022-03-31 15:35:38 +02:00
parent 5aac142e4c
commit c0b365602b
5 changed files with 52 additions and 10 deletions

View File

@ -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];

View File

@ -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 () => {

View File

@ -29,6 +29,7 @@
export let conid = null;
export let database = null;
export let driver = null;
export let jslid = null;
export let pureName = null;
export let schemaName = null;
@ -177,9 +178,8 @@
{ onClick: () => openFilterWindow('>='), text: 'Greater Than Or Equal To...' },
{ onClick: () => openFilterWindow('<'), text: 'Less Than...' },
{ onClick: () => openFilterWindow('<='), text: 'Less Than Or Equal To...' },
{ divider: true },
{ divider: true },
{ onClick: () => openFilterWindow('+'), text: 'Contains...' },
{ onClick: () => openFilterWindow('~'), text: 'Does Not Contain...' },
@ -248,6 +248,7 @@
conid,
database,
driver,
jslid,
multiselect: true,
schemaName,
pureName,
@ -304,6 +305,10 @@
<FontIcon icon="icon dots-vertical" />
</InlineButton>
{/if}
{:else if jslid}
<InlineButton on:click={handleShowValuesModal} narrow square>
<FontIcon icon="icon dots-vertical" />
</InlineButton>
{/if}
<DropDownButton icon="icon filter" menu={createMenu} narrow />
{#if showResizeSplitter}

View File

@ -336,6 +336,7 @@
export let tabControlHiddenTab = false;
export let onCustomGridRefresh;
export let useEvalFilters = false;
export let jslid;
// export let generalAllowSave = false;
export const activator = createActivator('DataGridCore', false);
@ -1548,6 +1549,7 @@
schemaName={col.schemaName}
{conid}
{database}
{jslid}
driver={display?.driver}
filterType={useEvalFilters ? 'eval' : col.filterType || getFilterType(col.dataType)}
filter={display.getFilter(col.uniqueName)}

View File

@ -24,6 +24,7 @@
export let field;
export let driver;
export let multiselect = false;
export let jslid;
// console.log('ValueLookupModal', conid, database, pureName, schemaName, columnName, driver);
@ -36,14 +37,22 @@
async function reload() {
isLoading = true;
rows = await apiCall('database-connections/load-field-values', {
conid,
database,
search,
schemaName,
pureName,
field,
});
if (jslid) {
rows = await apiCall('jsldata/load-field-values', {
jslid,
search,
field,
});
} else {
rows = await apiCall('database-connections/load-field-values', {
conid,
database,
search,
schemaName,
pureName,
field,
});
}
isLoading = false;
}