Registry / database / expo-sqlite-orm

expo-sqlite-orm

JSON →
library2.2.0jsnpmunverified

Simple ORM for Expo SQLite, providing a lightweight abstraction layer over expo-sqlite for React Native apps. Version 2.2.0 is the latest stable release, with no recent updates or defined release cadence. It supports TypeScript, migrations, and typical CRUD operations. Differentiators include a minimalistic API, column mapping with type safety, and support for complex queries with WHERE clauses. However, it only works on iOS and Android, not on web. The package is relatively small and may not be actively maintained.

npm install expo-sqlite-orm
INSTALL
IMPORT
SIG · EXPO-SQLITE-ORM
E
expo-sqlite-orm
databasejavascriptv2.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.

Repository
import { Repository } from 'expo-sqlite-orm'
const { Repository } = require('expo-sqlite-orm')
ESM import is standard; CommonJS require may work but is not typical for Expo/React Native projects.
Migrations
import { Migrations } from 'expo-sqlite-orm'
import Migrations from 'expo-sqlite-orm'
Named import, not default. TypeScript definitions are included.
columnTypes
import { columnTypes } from 'expo-sqlite-orm'
import { ColumnTypes } from 'expo-sqlite-orm'
Exported as lowercase 'columnTypes', not PascalCase.
ColumnMapping
import { ColumnMapping } from 'expo-sqlite-orm'
TypeScript type export, used for defining column schema.
IStatement
import { IStatement } from 'expo-sqlite-orm'
TypeScript interface for defining migration statements as a dictionary.

Basic setup: define a model, create a repository, run migrations, insert and query data.

import { Repository, Migrations, columnTypes, ColumnMapping, IStatement, sql } from 'expo-sqlite-orm'; interface Animal { id: number; name: string; color: string; age: number; } const columnMapping: ColumnMapping<Animal> = { id: { type: columnTypes.INTEGER, primary_key: true, autoincrement: true }, name: { type: columnTypes.TEXT, not_null: true }, color: { type: columnTypes.TEXT }, age: { type: columnTypes.INTEGER }, }; const statements: IStatement = { '1_create_animals': sql`CREATE TABLE animals ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, color TEXT, age INTEGER );`, }; const dbName = 'myDatabase'; const migrations = new Migrations(dbName, statements); const repository = new Repository(dbName, 'animals', columnMapping); async function setup() { await migrations.migrate(); const animal = await repository.insert({ name: 'Fluffy', color: 'White', age: 3 }); console.log('Inserted:', animal); const animals = await repository.query({ where: { age: { gte: 1 } } }); console.log('Animals:', animals); }
Debug
Known issues
gotchaWeb platform is not supported; only iOS and Android.
fix
Do not use in web-based Expo projects.
affects: >=0.0.0
breakingExpo SQLite peer dependency version must be ^14.0.3; other versions may cause incompatibility.
fix
Ensure expo-sqlite is at version ^14.0.3 in package.json.
affects: >=2.0.0
gotchaColumn mapping 'primary_key' and 'autoincrement' must be explicitly set for auto-incrementing primary keys.
fix
Always set 'primary_key: true' and 'autoincrement: true' on the id column.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find name 'sql'
Missing import of the `sql` tagged template literal from expo-sqlite-orm.
fix
Import `sql` from 'expo-sqlite-orm'.
Property 'migrate' does not exist on type 'Migrations'
The Migrations class uses an async method `migrate()` but TypeScript might not infer correctly due to version mismatch.
fix
Ensure you are using the correct import and that the Migrations instance is created after the statements object.
TypeError: Cannot read property 'then' of undefined
The insert method returns a Promise; make sure to await it or use .then() correctly.
fix
Use `await repository.insert(...)` or call `.then()` on the returned promise.
Undefined is not an object (evaluating 'repository.find')
The Repository instance may not be initialized properly or the database/table names are incorrect.
fix
Verify databaseName and tableName arguments to Repository constructor.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
expo-sqliterequiredpeer dependency; provides the underlying SQLite database for Expo
Agent activity
5 hits · last 30 days
node
4
Resources
expo-sqlite-orm — npm install expo-sqlite-orm · libregistry