Registry / database / react-native-ts-sqlite-orm

react-native-ts-sqlite-orm

JSON →
library0.2.0jsnpmunverified

A fully typed TypeScript ORM for SQLite in React Native and Expo environments (v0.2.0). It provides a LINQ-like query builder for SELECT, INSERT, UPDATE, DELETE operations and supports multiple SQLite backends like react-native-sqlite-storage, expo-sqlite, and even custom API contexts. The library focuses on type safety, bulk save operations, optional encryption, and a custom useQuery hook. Unlike other ORMs, it abstracts away the specific database driver, allowing flexible switching without code changes.

npm install react-native-ts-sqlite-orm
INSTALL
IMPORT
SIG · REACT-NATIVE-TS-SQ
R
react-native-ts-sqlite-orm
databasejavascriptv0.2.0
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.

Entity
import { Entity } from 'react-native-ts-sqlite-orm'
import Entity from 'react-native-ts-sqlite-orm'
Entity is a named export, not default.
Query
import { Query } from 'react-native-ts-sqlite-orm'
import { query } from 'react-native-ts-sqlite-orm'
Case-sensitive: Query with capital Q. Also requires Entity for table mapping.
DbContext
import { DbContext } from 'react-native-ts-sqlite-orm'
const DbContext = require('react-native-ts-sqlite-orm').DbContext
ESM-only; no CommonJS require pattern supported.
encryption
import { encryption } from 'react-native-ts-sqlite-orm'
import { Encrypt } from 'react-native-ts-sqlite-orm'
Export name is lowercase 'encryption', not 'Encrypt'.

Shows defining an Entity class, initializing DbContext with a driver, saving an entity, and querying with a condition using the Query builder.

import { Entity, Query, DbContext } from 'react-native-ts-sqlite-orm'; // Define an entity class User extends Entity { static get tableName() { return 'users'; } id: number = 0; name: string = ''; } // Initialize DbContext (assuming a SQLite driver is installed) const db = new DbContext({ driver: 'react-native-sqlite-storage', database: 'test.db' }); // Insert a user const user = new User(); user.name = 'Alice'; await db.save(user); // Query users const query = new Query(User); const results = await query.where(u => u.name === 'Alice').toArray(); console.log(results);
Debug
Known issues
gotchaDbContext requires an external SQLite driver (e.g., react-native-sqlite-storage or expo-sqlite) to be installed separately.
fix
Install one of the supported drivers: npm install react-native-sqlite-storage or expo-sqlite.
affects: >=0.0.0
gotchaEntity class must have a static getter `tableName` that returns the database table name.
fix
Add `static get tableName() { return 'your_table_name'; }` to your entity class.
affects: >=0.0.0
gotchaThe library is ESM-only; CommonJS require() will not work.
fix
Use import statements instead of require(). Ensure your tsconfig has "module": "esnext" or similar.
affects: >=0.0.0
gotchaQuery results are plain objects, not Entity instances, unless you manually map them.
fix
If you need Entity instances, use the `get` method or iterate and construct entities manually.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'react-native-sqlite-storage'
The SQLite driver is a peer dependency but not installed.
fix
Run: npm install react-native-sqlite-storage (or expo-sqlite) depending on your project.
TypeError: Entity is not a constructor
Entity was imported incorrectly (default import instead of named).
fix
Use `import { Entity } from 'react-native-ts-sqlite-orm'`.
Property 'tableName' does not exist on type 'typeof User'
The Entity subclass is missing the static `tableName` getter.
fix
Add `static get tableName() { return 'users'; }` inside the User class.
Cannot use import statement outside a module
The project is not configured for ES modules.
fix
Add "type": "module" to package.json or ensure tsconfig.module is set to "commonjs" incorrectly (should be "esnext").
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
react-native-sqlite-storageoptionalOptional: needed for native SQLite on React Native (if using this backend).
expo-sqliteoptionalOptional: alternative backend for Expo projects.
Agent activity
9 hits · last 30 days
node
8
Resources
react-native-ts-sqlite-orm — npm install react-native-ts-sqlite-orm · libregistry