Registry / database / expo-sqlite-eloquent-orm

expo-sqlite-eloquent-orm

JSON →
library0.10.6jsnpmunverified

Expo SQLite Eloquent ORM v0.10.6 is a lightweight, fluent ORM wrapper for expo-sqlite in React Native/Expo apps, inspired by Laravel's Eloquent. It provides a query builder, model-based CRUD, relationships, attribute casting, and a migration system. Updated regularly on npm, it competes with other SQLite wrappers by offering a Laravel-like API. Released under MIT license, it requires expo-sqlite ~13.4.0, React ^18.2.0, and React Native ^0.73.2.

npm install expo-sqlite-eloquent-orm
INSTALL
IMPORT
SIG · EXPO-SQLITE-ELOQUE
E
expo-sqlite-eloquent-orm
databasejavascriptv0.10.6
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.

Model
import { Model } from 'expo-sqlite-eloquent-orm'
const { Model } = require('expo-sqlite-eloquent-orm')
The library is ESM-first and ships TypeScript types. Named export.
Casts
import type { Casts } from 'expo-sqlite-eloquent-orm'
import { Casts } from 'expo-sqlite-eloquent-orm'
Casts is a TypeScript type, not a runtime value. Use import type for type-only imports.
ModelAttributes
import type { ModelAttributes } from 'expo-sqlite-eloquent-orm'
import { ModelAttributes } from 'expo-sqlite-eloquent-orm'
ModelAttributes is a TypeScript type interface.

Defines a User model with attribute casting, creates table, inserts, finds, updates, and queries records using the ORM.

import { Model } from 'expo-sqlite-eloquent-orm'; class User extends Model { static tableName = 'users'; casts = { is_admin: 'boolean', metadata: 'json', }; } async function example() { // Create the users table await User.executeSql( `CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, email TEXT, is_admin INTEGER DEFAULT 0, metadata TEXT DEFAULT '{}')`, [] ); // Insert a new user await User.insert({ name: 'Alice', email: 'alice@example.com', is_admin: true, metadata: { theme: 'dark' } }); // Find user by id const user = await User.find(1); console.log(user?.name); // Alice console.log(user?.is_admin); // true (cast from integer) console.log(user?.metadata); // { theme: 'dark' } (cast from JSON string) // Update user if (user) { await user.update({ name: 'Alice Smith' }); } // Query with where const admins = await User.where('is_admin', 1).get(); console.log(admins.length); } example();
Debug
Known issues
breakingIn version 0.5.0, the `table` static method was removed in favor of a `tableName` static property on Model subclasses.
fix
Define a static `tableName` property in your model class instead of calling `Model.table('name')`.
affects: <0.5.0
deprecatedThe `executeSql` static method is intended for raw SQL; prefer the query builder for most operations.
fix
Use methods like `insert`, `where`, `get` for common operations.
affects: >=0.1.0
gotchaThe `casts` property must be defined as an instance property (not static) and specified as `'number' | 'boolean' | 'string' | 'json'` strings. Incorrect casting types can cause runtime errors.
fix
Define `casts` as an object in the class instance, e.g., `casts = { age: 'number', is_active: 'boolean' }`.
affects: >=0.1.0
gotchaRelations (`hasOne`, `hasMany`, `belongsTo`, `belongsToMany`) are instance methods and must be called on a model instance, not statically.
fix
Call `user.hasMany(Post)` on an instance, not `User.hasMany(Post)`.
affects: >=0.1.0
gotchaThe `find` method returns `null` when no record is found, not `undefined`.
fix
Check for `null` explicitly, e.g., `const user = await User.find(1); if (user !== null) { ... }`.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'tableName')
Model subclass does not define a static `tableName` property.
fix
Add `static tableName = 'your_table';` to your model class.
Error: Invalid cast type: 'number'
The `casts` property uses an incorrect type string (e.g., 'number' instead of 'number').
fix
Ensure cast type strings are exactly one of: 'number', 'boolean', 'string', 'json'.
Error: get() method called without defining table or query
Calling `get()` without first setting a table or query (e.g., missing `static tableName` or `where` clause).
fix
Always define a table name via `static tableName` in your model or use `User.table('users')` before `get()`.
Upgrade
Version history
0.10.6latest on npm
Audit
Dependencies
expo-sqliterequiredRequired peer dependency for SQLite database access in Expo/React Native.
reactrequiredRequired peer dependency for React Native environment.
react-nativerequiredRequired peer dependency for React Native environment.
Agent activity
9 hits · last 30 days
node
8
Resources
expo-sqlite-eloquent-orm — npm install expo-sqlite-eloquent-orm · libregistry