Registry / database / react-native-sqlite-orm

react-native-sqlite-orm

JSON →
library1.0.0jsnpmunverified

A simple ORM utility for React Native apps using SQLite, built on top of react-native-sqlite-storage. Version 1.0.0 provides a Rails-inspired active record pattern with model definitions, CRUD operations, query builder, and raw SQL execution. Works on iOS and Android but not web. Key differentiators: lightweight, supports column types, defaults, unique constraints, and paginated queries. Integrates with Expo SQLite or direct react-native-sqlite-storage. Notable: exports from 'expo-sqlite-orm' despite package name, and uses class-based models with static getters.

npm install react-native-sqlite-orm
INSTALL
IMPORT
SIG · REACT-NATIVE-SQLIT
R
react-native-sqlite-orm
databasejavascriptv1.0.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.

BaseModel
import { BaseModel } from 'expo-sqlite-orm'
import { BaseModel } from 'react-native-sqlite-orm'
The package exports from 'expo-sqlite-orm' despite the npm package name being 'react-native-sqlite-orm'. This is a known issue.
types
import { types } from 'expo-sqlite-orm'
import { types } from 'react-native-sqlite-orm'
Same as BaseModel, import from 'expo-sqlite-orm'.
DatabaseLayer
import DatabaseLayer from 'expo-sqlite-orm/src/DatabaseLayer'
DatabaseLayer is not exported from the main entry; must be imported from the src path.

Defines an Animal model with SQLite ORM, creates table, saves a record, and retrieves it.

import SQLite from 'react-native-sqlite-storage'; import { BaseModel, types } from 'expo-sqlite-orm'; class Animal extends BaseModel { constructor(obj) { super(obj); } static get database() { return async () => SQLite.openDatabase({ name: 'database.db' }); } static get tableName() { return 'animals'; } static get columnMapping() { return { id: { type: types.INTEGER, primary_key: true }, name: { type: types.TEXT, not_null: true }, }; } } async function example() { await Animal.createTable(); const newAnimal = new Animal({ name: 'Bob' }); await newAnimal.save(); const animal = await Animal.find(1); console.log(animal.name); } example();
Debug
Known issues
breakingPackage exports are from 'expo-sqlite-orm', not 'react-native-sqlite-orm'. Importing from 'react-native-sqlite-orm' will fail.
fix
Use `import { BaseModel } from 'expo-sqlite-orm'`
affects: >=1.0.0
gotchaDatabaseLayer class is not exported from the main module; must import from 'expo-sqlite-orm/src/DatabaseLayer', which may be fragile with bundler configs.
fix
Import DatabaseLayer from the source path directly, or avoid using it if possible.
affects: >=1.0.0
gotchaOnly supports iOS and Android. Web is not supported and will throw errors.
fix
Use a platform check to exclude web or choose a web-compatible alternative.
affects: >=1.0.0
gotchaPrimary key must be named 'id', otherwise it's not supported.
fix
Always name your primary key column 'id'.
affects: >=1.0.0
gotchaThe package name on npm is 'react-native-sqlite-orm' but all documentation and source references use 'expo-sqlite-orm'. This inconsistency may cause confusion.
fix
Be aware that the package is installed as 'react-native-sqlite-orm' but imported as 'expo-sqlite-orm'.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'expo-sqlite-orm'
Package is installed as 'react-native-sqlite-orm' but import path is 'expo-sqlite-orm'
fix
Install the package with `npm install react-native-sqlite-orm` or `yarn add react-native-sqlite-orm`. Then use import from 'expo-sqlite-orm'.
TypeError: _expoSqliteOrm.BaseModel is not a constructor
Importing from 'react-native-sqlite-orm' instead of 'expo-sqlite-orm'
fix
Change import to `import { BaseModel } from 'expo-sqlite-orm'`
Undefined is not an object (evaluating '_expoSqliteOrm.BaseModel...')
Import path is incorrect, likely mixing up package name and export name
fix
Use correct import: `import { BaseModel } from 'expo-sqlite-orm'`
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
react-native-sqlite-storagerequiredPeer dependency for SQLite database operations
Agent activity
9 hits · last 30 days
node
8
Resources
react-native-sqlite-orm — npm install react-native-sqlite-orm · libregistry