load field values logic moved to backend

This commit is contained in:
Jan Prochazka
2022-03-17 08:40:09 +01:00
parent 074a75075d
commit 5c4794deae
7 changed files with 98 additions and 108 deletions

View File

@@ -151,34 +151,33 @@ module.exports = {
return res.result;
},
loadKeys_meta: true,
async loadKeys({ conid, database, root }) {
async loadDataCore(msgtype, {conid, database, ...args}) {
const opened = await this.ensureOpened(conid, database);
const res = await this.sendRequest(opened, { msgtype: 'loadKeys', root });
const res = await this.sendRequest(opened, { msgtype, ...args });
if (res.errorMessage) {
console.error(res.errorMessage);
}
return res.result || null;
},
loadKeys_meta: true,
async loadKeys({ conid, database, root }) {
return this.loadDataCore('loadKeys', { conid, database, root });
},
loadKeyInfo_meta: true,
async loadKeyInfo({ conid, database, key }) {
const opened = await this.ensureOpened(conid, database);
const res = await this.sendRequest(opened, { msgtype: 'loadKeyInfo', key });
if (res.errorMessage) {
console.error(res.errorMessage);
}
return res.result || null;
return this.loadDataCore('loadKeyInfo', { conid, database, key });
},
loadKeyTableRange_meta: true,
async loadKeyTableRange({ conid, database, key, cursor, count }) {
const opened = await this.ensureOpened(conid, database);
const res = await this.sendRequest(opened, { msgtype: 'loadKeyTableRange', key, cursor, count });
if (res.errorMessage) {
console.error(res.errorMessage);
}
return res.result || null;
return this.loadDataCore('loadKeyTableRange', { conid, database, key, cursor, count });
},
loadFieldValues_meta: true,
async loadFieldValues({ conid, database, schemaName, pureName, field, search }) {
return this.loadDataCore('loadFieldValues', { conid, database, schemaName, pureName, field, search });
},
callMethod_meta: true,

View File

@@ -172,59 +172,41 @@ async function handleQueryData({ msgid, sql }) {
}
}
async function handleCollectionData({ msgid, options }) {
async function handleDriverDataCore(msgid, callMethod) {
await waitConnected();
const driver = requireEngineDriver(storedConnection);
try {
const result = await driver.readCollection(systemConnection, options);
const result = await callMethod(driver);
process.send({ msgtype: 'response', msgid, result });
} catch (err) {
process.send({ msgtype: 'response', msgid, errorMessage: err.message });
}
}
async function handleCollectionData({ msgid, options }) {
return handleDriverDataCore(msgid, driver => driver.readCollection(systemConnection, options));
}
async function handleLoadKeys({ msgid, root }) {
await waitConnected();
const driver = requireEngineDriver(storedConnection);
try {
const result = await driver.loadKeys(systemConnection, root);
process.send({ msgtype: 'response', msgid, result });
} catch (err) {
process.send({ msgtype: 'response', msgid, errorMessage: err.message });
}
return handleDriverDataCore(msgid, driver => driver.loadKeys(systemConnection, root));
}
async function handleLoadKeyInfo({ msgid, key }) {
await waitConnected();
const driver = requireEngineDriver(storedConnection);
try {
const result = await driver.loadKeyInfo(systemConnection, key);
process.send({ msgtype: 'response', msgid, result });
} catch (err) {
process.send({ msgtype: 'response', msgid, errorMessage: err.message });
}
return handleDriverDataCore(msgid, driver => driver.loadKeyInfo(systemConnection, key));
}
async function handleCallMethod({ msgid, method, args }) {
await waitConnected();
const driver = requireEngineDriver(storedConnection);
try {
const result = await driver.callMethod(systemConnection, method, args);
process.send({ msgtype: 'response', msgid, result });
} catch (err) {
process.send({ msgtype: 'response', msgid, errorMessage: err.message });
}
return handleDriverDataCore(msgid, driver => driver.callMethod(systemConnection, method, args));
}
async function handleLoadKeyTableRange({ msgid, key, cursor, count }) {
await waitConnected();
const driver = requireEngineDriver(storedConnection);
try {
const result = await driver.loadKeyTableRange(systemConnection, key, cursor, count);
process.send({ msgtype: 'response', msgid, result });
} catch (err) {
process.send({ msgtype: 'response', msgid, errorMessage: err.message });
}
return handleDriverDataCore(msgid, driver => driver.loadKeyTableRange(systemConnection, key, cursor, count));
}
async function handleLoadFieldValues({ msgid, schemaName, pureName, field, search }) {
return handleDriverDataCore(msgid, driver =>
driver.loadFieldValues(systemConnection, { schemaName, pureName }, field, search)
);
}
async function handleUpdateCollection({ msgid, changeSet }) {
@@ -300,6 +282,7 @@ const messageHandlers = {
ping: handlePing,
syncModel: handleSyncModel,
generateDeploySql: handleGenerateDeploySql,
loadFieldValues: handleLoadFieldValues,
// runCommand: handleRunCommand,
};