Page MenuHomePhabricator

D7180.diff
No OneTemporary

D7180.diff

diff --git a/web/database/queries/db-queries.js b/web/database/queries/db-queries.js
--- a/web/database/queries/db-queries.js
+++ b/web/database/queries/db-queries.js
@@ -21,7 +21,12 @@
CREATE TABLE IF NOT EXISTS drafts (
key TEXT UNIQUE PRIMARY KEY NOT NULL,
text TEXT NOT NULL
- )
+ );
+
+ CREATE TABLE IF NOT EXISTS metadata (
+ name TEXT UNIQUE PRIMARY KEY NOT NULL,
+ data TEXT NOT NULL
+ );
`);
}
diff --git a/web/database/queries/metadata-queries.js b/web/database/queries/metadata-queries.js
new file mode 100644
--- /dev/null
+++ b/web/database/queries/metadata-queries.js
@@ -0,0 +1,56 @@
+// @flow
+
+import { SqliteDatabase } from 'sql.js';
+
+import { parseMultiStatementSQLiteResult } from '../utils/db-utils.js';
+
+type Metadata = {
+ name: string,
+ data: string,
+};
+
+function setMetadata(db: SqliteDatabase, entryName: string, data: string) {
+ const query = `
+ INSERT OR REPLACE INTO metadata (name, data)
+ VALUES ($entryName, $data)
+ `;
+ const params = {
+ $entryName: entryName,
+ $data: data,
+ };
+
+ db.exec(query, params);
+}
+
+function getMetadata(db: SqliteDatabase, entryName: string): ?string {
+ const query = `
+ SELECT *
+ FROM metadata
+ WHERE name = $entryName
+ `;
+ const params = {
+ $entryName: entryName,
+ };
+
+ const rawResult = db.exec(query, params);
+ const result = parseMultiStatementSQLiteResult<Metadata>(rawResult);
+ if (result.length === 0 || result[0].length === 0) {
+ return undefined;
+ }
+ const [entry] = result[0];
+ return entry.data;
+}
+
+function clearMetadata(db: SqliteDatabase, entryName: string) {
+ const query = `
+ DELETE FROM metadata
+ WHERE name = $entryName
+ `;
+ const params = {
+ $entryName: entryName,
+ };
+
+ db.exec(query, params);
+}
+
+export { setMetadata, getMetadata, clearMetadata };

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 9:31 PM (22 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591730
Default Alt Text
D7180.diff (1 KB)

Event Timeline