documentation of app database

Overview

Our app has two kinds of database, localStorage for user preferences and Dexie.js for patterns database. Dexie is a thin layer arround IndexedDB, async operations use promises that allow us to use asyn/await. It doesn't store data in special way, so we can use indexedDB and dexie parallelly. Our database support export and import large datafile without heavy use of main memory. Transactions are secure, so if anything goes wrong in mid of any transaction, then database rollback automatically.

<aside> 💡 I have written a article on how to use dexie database with electron app: Electron app Database with Dexie.js and web worker

</aside>

Database files documentation

Initialization

To initialize database we just need to require dexie module and define schema. It detect if database already exist or not, if not then initialize a new database with specified schema. Then we have some basics function for database transaction, documented below-

databaseInit

Database web worker

C++ code generates tones of records, each record consist of a pattern string, its popularity and its file address. These records can be 100 thousands in number, so importing them require a way, which consume low main memory, do not block app UI and safe for database transaction. We are using web workers, so UI doesn't get block while importing large data file. Our app reads data line by line to avoid loading whole file on memory. This file and some function with documentation can be found below:

databaseWorker.js

Database processes

All database processes can be triggered from a single file called "databaseClient.js". It includes above web worker, catching its error and its result. It also includes functions for importing and exporting pattern database, checking available storage quota, persisting database and lastly function for deleting pattern database. Code documentation of these functions can be found below:

databaseClient.js