Registry / database / vue-sqlite-hook

vue-sqlite-hook

JSON →
library3.0.3jsnpmunverified

A Vue 3 composable (hook) wrapping @capacitor-community/sqlite for reactive database operations in Ionic/Capacitor apps. Current stable version v3.0.3 targets Capacitor 4 and Vue 3. Provides a simple useState-like API (useSqlite) with reactive state for queries, mutations, and transaction support. Unlike raw capacitor-community/sqlite, it integrates deeply with Vue's reactivity system, automatically triggering component re-renders on data changes. Ships TypeScript types. Supports iOS, Android, and Web with SQLite via Capacitor.

npm install vue-sqlite-hook
INSTALL
IMPORT
SIG · VUE-SQLITE-HOOK
V
vue-sqlite-hook
databasejavascriptv3.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

useSqlite
import { useSqlite } from 'vue-sqlite-hook'
const useSqlite = require('vue-sqlite-hook')
ESM-only. Use named import in Vue 3 script setup.
useSqlite
import { useSqlite } from 'vue-sqlite-hook'
import useSqlite from 'vue-sqlite-hook'
Not a default export; must use named import.
SqliteDb
import type { SqliteDb } from 'vue-sqlite-hook'
import { SqliteDb } from 'vue-sqlite-hook'
Type-only export; use 'import type' to avoid runtime inclusion.

Initialize SQLite connection, open database, create table, and query data using the reactive composable.

import { useSqlite } from 'vue-sqlite-hook'; import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite'; const sqlite = new SQLiteConnection(CapacitorSQLite); const { execute, query, isReady } = useSqlite(sqlite); async function initDB() { await sqlite.openDB('myDB', false, 'no-encryption', 1, false); // create table await execute(`CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT);`); } async function getUsers() { const result = await query('SELECT * FROM users'); console.log(result.values); } initDB();
Debug
Known issues
breakingv3.0.0 dropped support for Capacitor 3; requires @capacitor/core ^4.0.0
fix
Upgrade Capacitor and @capacitor-community/sqlite to version 4+
affects: >=3.0.0
gotchamust await sqlite.openDB() before calling execute/query
fix
call openDB() in onMounted or before any database operation
affects: >=1.0.0
deprecatedv2.x used 'useDatabase' hook; renamed to 'useSqlite' in v3
fix
replace 'useDatabase' import with 'useSqlite'
affects: >=3.0.0
gotchathe composable must be called inside a Vue component setup function or <script setup>
fix
only call useSqlite() within component setup context
affects: >=1.0.0
gotchaweb platform requires installing 'sql.js' and 'localforage' for in-memory SQLite
fix
add '@capacitor-community/sqlite' web setup; ensure proper polyfills
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught (in promise) Error: No open database found
Called execute/query before opening database with sqlite.openDB()
fix
await sqlite.openDB() before any CRUD operations
Cannot read properties of undefined (reading 'connection')
useSqlite called before sqlite connection is initialized
fix
Create SQLiteConnection instance and pass to useSqlite
Upgrade
Version history
3.0.3latest on npm
Audit
Dependencies
@capacitor/corerequiredpeer dependency: required for Capacitor plugin runtime
vuerequiredpeer dependency: required for Vue 3 composition API
@capacitor-community/sqliterequiredunderlying SQLite plugin for Capacitor
Agent activity
23 hits · last 30 days
node
18
Meta
1
Amazon
1
OpenAI (training)
1
Resources
vue-sqlite-hook — npm install vue-sqlite-hook · libregistry