Capacitor plugin exposing platform-specific sqlite bindings.
- Android
- Web
- iOS
There is another Capacitor SQLite plugin, that seems to have a fair number of happy users. When attempting to use this plugin, however, I was struck by a few things:
- Sprawling API, very difficult to find straight-forward examples for the most basic use case.
- Appears to opt for programmatic alternatives to existing SQLite features
- Buggy. I was getting cryptic errors that appeared to be due to complex transformation of my statements.
- As far as I can tell, the plugin seems to expose methods for transaction handling across asynchronous processes. This is a bad idea.
For these reasons, I sought to create a plugin that:
- Is easy to integrate and understand.
- Nudges developers toward SQLite best practices (no keeping transactions open across async processes).
- Support as much expressiveness as possible given the restrictions imposed by the asynchronous nature of Capacitor calls.
For now, I am only building an Android app, so that is the only implementation available. PRs are welcome.
npm install @lagoware/capacitor-sqlite
npx cap sync
openDb(options: { dbName: string; version: number; upgrades: Record<number, string[]>; }) => Promise<void>
Param | Type |
---|---|
options |
{ dbName: string; version: number; upgrades: Record<number, string[]>; } |
runStatements<T = any>(options: { dbName: string; statementSpecs: StatementSpec[]; }) => Promise<{ results: StatementExecReturnVal<T>[]; }>
Param | Type |
---|---|
options |
{ dbName: string; statementSpecs: StatementSpec[]; } |
Returns: Promise<{ results: StatementExecReturnVal<T>[]; }>
Construct a type with a set of properties K of type T
{
[P in K]: T;
}
(null|T[]) | (null|T[])[]
{ type: "query"|"command"; statement: string; beginsTransaction?: boolean, commitsTransaction?: boolean, params?: (string | string[])[] }