Registry / database / an-expo-sqlite-orm

an-expo-sqlite-orm

JSON →
library1.0.16jsnpmunverified

A lightweight ORM for Expo SQLite (expo-sqlite) that provides a model-based approach to database operations in React Native apps. Version 1.0.16 supports CRUD, filtering, pagination, search, and nested relations via TypeScript generics. It is designed specifically for Expo managed workflows and relies on expo-sqlite as a peer dependency. Key differentiators include a simple class-based schema definition, a fluent query API (filter, update, delete, paginate), and automatic table creation/initialization. The library is actively maintained with a focus on Expo SDK compatibility.

npm install an-expo-sqlite-orm
INSTALL
IMPORT
SIG · AN-EXPO-SQLITE-ORM
A
an-expo-sqlite-orm
databasejavascriptv1.0.16
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.

SQLiteModel
import { SQLiteModel } from 'an-expo-sqlite-orm'
const { SQLiteModel } = require('an-expo-sqlite-orm')
The package is ESM-only (no CJS support). Named imports must be used.
initDatabase
import { initDatabase } from 'an-expo-sqlite-orm'
import initDatabase from 'an-expo-sqlite-orm'
initDatabase is a named export, not default.
SQLiteModelSchema
import { SQLiteModelSchema } from 'an-expo-sqlite-orm'
TypeScript type for schema definition. Also available as named export.

Defines a Task model using SQLiteModel, initializes the database, and performs a create operation.

import { SQLiteModel, SQLiteModelSchema, initDatabase } from 'an-expo-sqlite-orm'; interface TaskFields { title: string; done: boolean; } interface TaskSchema { fields: TaskFields; children: {}; parents: {}; } class TaskModel extends SQLiteModel<TaskSchema> { tableName = 'task'; getSchema(): SQLiteModelSchema<TaskSchema> { return { fields: { title: { type: 'TEXT' }, done: { type: 'BOOLEAN' }, }, children: {}, parents: {}, }; } } const models = [new TaskModel()]; initDatabase(models).then(() => { const task = new TaskModel(); task.objects.create({ title: 'Test', done: false }).run().then(item => { console.log('Created:', item); }); });
Debug
Known issues
breakingThe .run() method must be called on every query (e.g., create().run(), filter().update().run()). Omitting .run() will not execute the query and may lead to unexpected behavior.
fix
Always append .run() to any query chain, and then handle the Promise.
affects: >=1.0.0
deprecatedThe resetDatabase function deletes all data. Use with caution.
fix
Only call resetDatabase() intentionally during development. In production, avoid it.
affects: >=1.0.0
gotchaThe package relies on expo-sqlite (global singleton). Ensure expo-sqlite is installed and properly linked before using the ORM.
fix
Run 'npx expo install expo-sqlite' and rebuild the project.
affects: >=1.0.0
gotchaWhen using TypeScript, the generic type for SQLiteModel must match the schema. Mismatched generics can cause runtime errors.
fix
Ensure the schema interface matches the getSchema() return type exactly.
affects: >=1.0.0
gotchaThe .search() method requires the field to have useInSearch: true in the schema. If omitted, search will fail.
fix
Add useInSearch: true to the field definition in getSchema().
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'run')
Calling .run() on a null/undefined object, possibly because a previous query never resolved or the database was not initialized.
fix
Use .catch() on every .run() promise to handle errors, and ensure initDatabase() resolves before running queries.
Error: Table 'todo' already exists
Calling initDatabase() multiple times or using resetDatabase() incorrectly.
fix
Avoid calling initDatabase() more than once. Use a flag or state to track initialization.
TypeError: Cannot read property 'filter' of undefined
The model's objects property is undefined because the table was not created or the model was not registered with initDatabase.
fix
Ensure the model is included in the array passed to initDatabase().
Upgrade
Version history
1.0.16latest on npm
Audit
Dependencies
expo-sqliterequiredRequired as the underlying SQLite driver for React Native/Expo.
expooptionalMay be required for Expo SDK compatibility, though not a direct dependency.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
an-expo-sqlite-orm — npm install an-expo-sqlite-orm · libregistry