Page MenuHomePhabricator

[web-db] implement function get all drafts from SQLite
ClosedPublic

Authored by kamil on Mar 21 2023, 8:22 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jun 15, 8:35 AM
Unknown Object (File)
Thu, Jun 13, 4:50 PM
Unknown Object (File)
Wed, Jun 12, 6:59 AM
Unknown Object (File)
Tue, Jun 11, 5:40 AM
Unknown Object (File)
Fri, Jun 7, 9:17 PM
Unknown Object (File)
Fri, Jun 7, 8:05 AM
Unknown Object (File)
Thu, May 30, 5:31 AM
Unknown Object (File)
Thu, May 30, 5:31 AM
Subscribers

Details

Summary

Function to return all drafts, native version: link

Depends on D7122

Test Plan

Tests D7124

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kamil held this revision as a draft.
kamil published this revision for review.Mar 23 2023, 6:14 AM
ashoat added inline comments.
web/database/queries/draft-queries.js
43 ↗(On Diff #24022)
  1. I think it's more clear / readable to check dbResult.length === 0
  2. In what scenario would dbResult.length === 0? Looking at D7118, it seems like the first array here should have on result for each statement in the query. But the query always has precisely one statement, so wouldn't we expect dbResult.length === 1? Should we use an invariant instead of checking this here?
This revision is now accepted and ready to land.Mar 23 2023, 12:48 PM
web/database/queries/draft-queries.js
43 ↗(On Diff #24022)
  1. I think it's more clear / readable to check dbResult.length === 0

You're right, I'll address this before landing

  1. In what scenario would dbResult.length === 0? Looking at D7118, it seems like the first array here should have on result for each statement in the query. But the query always has precisely one statement, so wouldn't we expect dbResult.length === 1? Should we use an invariant instead of checking this here?

It's non-standard sql.js behavior, I added a comment in D7118 (above the function to warn developers in the future).
Imagine that the drafts table is empty, in that case, you would expect (because it's one query) the result to look like this: [[]] or [undefined].
However, sql.js skips empty results, so rawDBResult variable will be [], which implies dbResult will also be [].
I don't think invariant is suitable, dbResult.length === 0 it's sql.js quirk but it's a legal situation.

web/database/queries/draft-queries.js
43 ↗(On Diff #24022)

Thanks for explaining! That is weird behavior but your approach makes sense