Parallelize SQL queries
This commit is contained in:
parent
86b4da1ec2
commit
c64762858e
178 changed files with 3377 additions and 3618 deletions
|
@ -7,14 +7,22 @@ import type { MainSQL } from '../ts/sql/main';
|
|||
import { remove as removeUserConfig } from './user_config';
|
||||
import { remove as removeEphemeralConfig } from './ephemeral_config';
|
||||
|
||||
let sql: Pick<MainSQL, 'sqlCall'> | undefined;
|
||||
let sql:
|
||||
| Pick<
|
||||
MainSQL,
|
||||
'sqlRead' | 'sqlWrite' | 'pauseWriteAccess' | 'resumeWriteAccess'
|
||||
>
|
||||
| undefined;
|
||||
|
||||
let initialized = false;
|
||||
|
||||
const SQL_CHANNEL_KEY = 'sql-channel';
|
||||
const SQL_READ_KEY = 'sql-channel:read';
|
||||
const SQL_WRITE_KEY = 'sql-channel:write';
|
||||
const ERASE_SQL_KEY = 'erase-sql-key';
|
||||
const PAUSE_WRITE_ACCESS = 'pause-sql-writes';
|
||||
const RESUME_WRITE_ACCESS = 'resume-sql-writes';
|
||||
|
||||
export function initialize(mainSQL: Pick<MainSQL, 'sqlCall'>): void {
|
||||
export function initialize(mainSQL: typeof sql): void {
|
||||
if (initialized) {
|
||||
throw new Error('sqlChannels: already initialized!');
|
||||
}
|
||||
|
@ -22,15 +30,36 @@ export function initialize(mainSQL: Pick<MainSQL, 'sqlCall'>): void {
|
|||
|
||||
sql = mainSQL;
|
||||
|
||||
ipcMain.handle(SQL_CHANNEL_KEY, (_event, callName, ...args) => {
|
||||
ipcMain.handle(SQL_READ_KEY, (_event, callName, ...args) => {
|
||||
if (!sql) {
|
||||
throw new Error(`${SQL_CHANNEL_KEY}: Not yet initialized!`);
|
||||
throw new Error(`${SQL_READ_KEY}: Not yet initialized!`);
|
||||
}
|
||||
return sql.sqlCall(callName, ...args);
|
||||
return sql.sqlRead(callName, ...args);
|
||||
});
|
||||
|
||||
ipcMain.handle(SQL_WRITE_KEY, (_event, callName, ...args) => {
|
||||
if (!sql) {
|
||||
throw new Error(`${SQL_WRITE_KEY}: Not yet initialized!`);
|
||||
}
|
||||
return sql.sqlWrite(callName, ...args);
|
||||
});
|
||||
|
||||
ipcMain.handle(ERASE_SQL_KEY, () => {
|
||||
removeUserConfig();
|
||||
removeEphemeralConfig();
|
||||
});
|
||||
|
||||
ipcMain.handle(PAUSE_WRITE_ACCESS, () => {
|
||||
if (!sql) {
|
||||
throw new Error(`${PAUSE_WRITE_ACCESS}: Not yet initialized!`);
|
||||
}
|
||||
return sql.pauseWriteAccess();
|
||||
});
|
||||
|
||||
ipcMain.handle(RESUME_WRITE_ACCESS, () => {
|
||||
if (!sql) {
|
||||
throw new Error(`${PAUSE_WRITE_ACCESS}: Not yet initialized!`);
|
||||
}
|
||||
return sql.resumeWriteAccess();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue