diff --git a/web/database/queries/draft-queries.js b/web/database/queries/draft-queries.js --- a/web/database/queries/draft-queries.js +++ b/web/database/queries/draft-queries.js @@ -1,5 +1,9 @@ // @flow +import type { ClientDBDraftInfo } from 'lib/types/draft-types.js'; + +import { parseSQLiteResult } from '../utils/db-utils.js'; + function removeAllDrafts(db: SqliteDatabase) { db.exec(`DELETE from drafts`); } @@ -31,4 +35,14 @@ db.exec(query, params); } -export { removeAllDrafts, updateDraft, moveDraft }; +function getAllDrafts(db: SqliteDatabase): ClientDBDraftInfo[] { + const rawDBResult = db.exec(`SELECT * FROM drafts`); + const dbResult = parseSQLiteResult(rawDBResult); + if (!dbResult.length) { + return []; + } + + return dbResult[0]; +} + +export { removeAllDrafts, updateDraft, moveDraft, getAllDrafts };