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);
}
Errors
Common errors & fixes
Cannot find name 'sql'
Missing import of the `sql` tagged template literal from expo-sqlite-orm.
fixImport `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.
fixEnsure 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.
fixUse `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.
fixVerify databaseName and tableName arguments to Repository constructor.
Audit
Dependencies
expo-sqliterequiredpeer dependency; provides the underlying SQLite database for Expo