Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3353372
D7118.id24133.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D7118.id24133.diff
View Options
diff --git a/web/database/utils/db-utils.js b/web/database/utils/db-utils.js
new file mode 100644
--- /dev/null
+++ b/web/database/utils/db-utils.js
@@ -0,0 +1,27 @@
+// @flow
+
+import type { QueryExecResult } from 'sql.js';
+
+function parseSQLiteQueryResult<T>(result: QueryExecResult): T[] {
+ const { columns, values } = result;
+ return values.map(rowResult => {
+ const row: any = Object.fromEntries(
+ columns.map((key, index) => [key, rowResult[index]]),
+ );
+ return row;
+ });
+}
+
+// NOTE: sql.js has behavior that when there are multiple statements in query
+// e.g. "statement1; statement2; statement3;"
+// and statement2 will not return anything, the result will be:
+// [result1, result3], not [result1, undefined, result3]
+function parseMultiStatementSQLiteResult<T: Object>(
+ rawResult: $ReadOnlyArray<QueryExecResult>,
+): T[][] {
+ return rawResult.map((queryResult: QueryExecResult) =>
+ parseSQLiteQueryResult<T>(queryResult),
+ );
+}
+
+export { parseMultiStatementSQLiteResult };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 9:37 AM (18 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2574854
Default Alt Text
D7118.id24133.diff (1 KB)
Attached To
Mode
D7118: [web-db] add function for parsing SQLite query
Attached
Detach File
Event Timeline
Log In to Comment