Skip to content

lagoware/capacitor-sqlite

Repository files navigation

@lagoware/capacitor-sqlite

Capacitor plugin exposing platform-specific sqlite bindings.

  • Android
  • Web
  • iOS

Why Does This Exist?

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.

Install

npm install @lagoware/capacitor-sqlite
npx cap sync

API

openDb(...)

openDb(options: { dbName: string; version: number; upgrades: Record<number, string[]>; }) => Promise<void>
Param Type
options { dbName: string; version: number; upgrades: Record<number, string[]>; }

runStatements(...)

runStatements<T = any>(options: { dbName: string; statementSpecs: StatementSpec[]; }) => Promise<{ results: StatementExecReturnVal<T>[]; }>
Param Type
options { dbName: string; statementSpecs: StatementSpec[]; }

Returns: Promise<{ results: StatementExecReturnVal<T>[]; }>


Type Aliases

Record

Construct a type with a set of properties K of type T

{ [P in K]: T; }

StatementExecReturnVal

(null|T[]) | (null|T[])[]

StatementSpec

{ type: "query"|"command"; statement: string; beginsTransaction?: boolean, commitsTransaction?: boolean, params?: (string | string[])[] }

About

Capacitor plugin exposing sqlite bindings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published