{"id":44699,"library":"declarative-sqlite","title":"declarative-sqlite","description":"TypeScript port of declarative_sqlite for PWA and Capacitor applications. Version 2.2.29 (stable) provides zero code generation via JavaScript Proxy, automatic schema migration, and built-in conflict resolution for offline-first apps. Key differentiators: tiny bundle (~15KB gzipped), RxJS reactive queries, multi-backend support (wa-sqlite, Capacitor, better-sqlite3), and HLC+LWW conflict resolution. Release cadence is frequent (multiple updates per month). Requires rxjs as a peer dependency.","status":"active","version":"2.2.29","language":"javascript","source_language":"en","source_url":"https://github.com/graknol/declarative_sqlite","tags":["javascript","sqlite","database","declarative","schema","migration","pwa","capacitor","typescript"],"install":[{"cmd":"npm install declarative-sqlite","lang":"bash","label":"npm"},{"cmd":"yarn add declarative-sqlite","lang":"bash","label":"yarn"},{"cmd":"pnpm add declarative-sqlite","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for reactive streaming queries","package":"rxjs","optional":false}],"imports":[{"note":"ESM-only; does not export CommonJS. Use dynamic import if needed in Node.","wrong":"const { SchemaBuilder } = require('declarative-sqlite')","symbol":"SchemaBuilder","correct":"import { SchemaBuilder } from 'declarative-sqlite'"},{"note":"Named export, not part of a default namespace.","wrong":"import * as declarative from 'declarative-sqlite'; const db = new declarative.DeclarativeDatabase(...)","symbol":"DeclarativeDatabase","correct":"import { DeclarativeDatabase } from 'declarative-sqlite'"},{"note":"Factory to create adapters for different backends.","wrong":"","symbol":"AdapterFactory","correct":"import { AdapterFactory } from 'declarative-sqlite'"},{"note":"Enum-like object for specifying storage backend.","wrong":"Interface is a type export; use import type if not needed at runtime.","symbol":"StorageBackend","correct":"import { StorageBackend } from 'declarative-sqlite'"}],"quickstart":{"code":"import { SchemaBuilder, DeclarativeDatabase, AdapterFactory } from 'declarative-sqlite';\n\nconst schema = new SchemaBuilder()\n  .table('users', t => {\n    t.guid('id').notNull('');\n    t.text('name').notNull('');\n    t.text('email').notNull('');\n    t.integer('age').notNull(0);\n    t.key('id').primary();\n  })\n  .build();\n\nconst adapter = await AdapterFactory.create({\n  name: 'myapp.db',\n  enableWAL: true,\n});\n\nconst db = new DeclarativeDatabase({\n  adapter,\n  schema,\n  autoMigrate: true\n});\n\nawait db.initialize();\n\nawait db.insert('users', { id: 'u1', name: 'Alice', email: 'alice@example.com', age: 30 });\nconst users = await db.query('users', { where: 'age >= ?', whereArgs: [21] });\nconsole.log(users);","lang":"typescript","description":"Defines a users schema with automatic migration and inserts/query records using DeclarativeDatabase."},"warnings":[{"fix":"Use AdapterFactory.create() instead of direct instantiation.","message":"In v2.0.0, the API changed from class-based to factory-based adapter creation. Old code using new Adapter() will break.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Use explicit type assertion with 'as' or cast the record to the desired type.","message":"The method db.createRecord() uses Proxy objects; some TypeScript strict mode configurations may complain about property assignments on Proxy targets.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Always use lowercase table/column names in schema and queries.","message":"Table names and column definitions in SchemaBuilder are case-sensitive. Mismatched casing between schema and query leads to silent failures.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Manually backup database before schema changes or disable autoMigrate for production.","message":"The autoMigrate option does not rollback on failure; partial migrations may leave the database in an inconsistent state.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'15kb':42 '2.2.29':15 'app':37 'applic':13 'automat':24 'backend':49 'better':56 'better-sqlite3':55 'built':29 'built-in':28 'bundl':41 'cadenc':64 'capacitor':12,54,84 'code':19 'conflict':31,61 'databas':79 'declar':2,7,80 'declarative-sqlit':1 'depend':76 'differenti':39 'first':36 'frequent':66 'generat':20 'gzip':43 'hlc':59 'javascript':22,77 'key':38 'lww':60 'migrat':26,82 'month':70 'multi':48 'multi-backend':47 'multipl':67 'offlin':35 'offline-first':34 'peer':75 'per':69 'port':5 'provid':17 'proxi':23 'pwa':10,83 'queri':46 'reactiv':45 'releas':63 'requir':71 'resolut':32,62 'rxjs':44,72 'schema':25,81 'sqlite':3,8,53,78 'sqlite3':57 'stabl':16 'support':50 'tini':40 'typescript':4,85 'updat':68 'version':14 'via':21 'wa':52 'wa-sqlit':51 'zero':18","created_at":"2026-06-07T12:51:24.624449+00:00","updated_at":"2026-06-07T12:51:24.624449+00:00","problems":[{"fix":"Run 'npm install declarative-sqlite rxjs' (rxjs is a required peer dependency)","cause":"Package not installed or installed without peer dependency rxjs.","error":"Error: Cannot find module 'declarative-sqlite'"},{"fix":"Ensure you await db.initialize() before any CRUD operations.","cause":"Calling insert before the database is fully initialized.","error":"TypeError: db.insert is not a function"},{"fix":"Remove duplicate table definitions from the schema builder chain.","cause":"Defining the same table twice in the schema.","error":"Error: SchemaBuilder: Duplicate table name 'users'"},{"fix":"Check environment compatibility; use StorageBackend.Auto for automatic detection.","cause":"Invalid backend string or unsupported environment (e.g., StorageBackend.OPFS in Node.js).","error":"Error: AdapterFactory.create: backend not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/graknol/declarative_sqlite#readme","github":"https://github.com/graknol/declarative_sqlite","docs":null,"changelog":null,"pypi":null,"npm":"declarative-sqlite","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}