-
-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Optimize Pragma Fetching with Batch IPC #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -897,13 +897,17 @@ export async function createNativeDatabaseConnection( | |
| 'auto_vacuum' | ||
| ]; | ||
|
|
||
| const queries = pragmasToFetch.map(pragma => ({ sql: `PRAGMA ${pragma}` })); | ||
| const res = await worker.call<any>('queryBatch', [queries]); | ||
|
|
||
| const result: Record<string, CellValue> = {}; | ||
|
|
||
| for (const pragma of pragmasToFetch) { | ||
| const res = await worker.call<any>('query', [`PRAGMA ${pragma}`]); | ||
| if (res && res.values && res.values.length > 0) { | ||
| result[pragma] = res.values[0][0]; | ||
| } | ||
| if (res && res.results && Array.isArray(res.results)) { | ||
| res.results.forEach((r: any, i: number) => { | ||
| if (r && r.values && r.values.length > 0) { | ||
| result[pragmasToFetch[i]] = r.values[0][0]; | ||
| } | ||
| }); | ||
| } | ||
|
Comment on lines
+901
to
911
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve type safety and code clarity, it's best to avoid using interface QueryBatchResult {
results: {
values: CellValue[][];
}[];
}
const res = await worker.call<QueryBatchResult>('queryBatch', [queries]);
const result: Record<string, CellValue> = {};
if (res?.results) {
res.results.forEach((r, i) => {
if (r?.values?.length > 0 && r.values[0]?.length > 0) {
result[pragmasToFetch[i]] = r.values[0][0];
}
});
} |
||
|
|
||
| return result; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on a
try...catchblock to handle an empty result set fromdb.prepare(...).all()can be considered an anti-pattern. It's more robust to explicitly check the array length before accessing an element. This makes the code's intent clearer and avoids using exceptions for control flow in a non-exceptional case.