canvasxyz/canvas

Reduce duplicated code in Sqlite ModelDB implementations

rjwebb opened this issue · 0 comments

Right now we have X implementations of ModelDB that use Sqlite:

  • modeldb-sqlite - uses native Sqlite on Node with the better-sqlite3 library
  • modeldb-sqlite-wasm - uses a wasm compiled version of Sqlite for the browser in a web worker
  • modeldb-durable-objects- uses the Cloudflare Durable Objects distribution of Sqlite which runs in a Cloudflare worker

These three have a large amount of code in common which mostly lives in ModelAPI.ts or api.ts and encoding.ts within the respective modules. These files are not totally identical, the main difference between them is that each Sqlite library has a slightly different interface for creating prepared queries, retrieving rows, etc. The schema of the tables that need to be created by ModelDB and the queries themselves however are identical, so it should be possible to merge these files together into one.