Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: replace current DB access with Data Access Library
This PR integrates the data access library in the typescript-client. Fixes VAX-526, VAX-587, VAX-613 and VAX-623 *Code structure:* - The DAL source files reside in `src/client`. The main functionality is implemented by `src/client/model/table.ts` which represents a table from the DB and provides a Prisma-inspired API for CRUD operations on that table. - The entry point of the DAL is the static `ElectricClient.create` method which takes a description of the DB (generated by our custom Prisma generator) as input and generates a namespace that extends the electric namespace with a property for each table. - The `src/client/input` folder defines the input types that are accepted by the different methods of the API of a table. - The `src/client/execution/executor.ts` file defines an `Executor` class wraps a DB adapter and a notifier and provides methods to execute queries and transactions while also calling `potentiallyChanged` on the notifier. *Notes about the code:* The main code is located in `src/client/model/table.ts`. This `Table` class implements the API of the DAL. The queries are executed using one of the supported drivers. However, drivers have subtle differences: some are synchronous (e.g. better-sqlite3) some are async (e.g. wa-sqlite). Within the async drivers, some support promises, others do not support promises and require continuation passing style using callbacks. For this reason, the unified adapter API also requires passing callbacks and thus writing code in continuation passing style. **As a result, the `Table` class is also implemented in continuation passing style.** Thus, internally, we can compose API calls but have to pass callbacks around. --------- BREAKING CHANGE: The way how queries are executed against the DB has changed. All database access goes through the Data Access Library (DAL) which provides a Prisma-like API. Raw SQL queries can still be executed using the `raw` and `liveRaw` methods of the DAL.
- Loading branch information