Registry / database / openrecord

openrecord

JSON →
library2.11.1jsnpmunverified

OpenRecord is an ActiveRecord-inspired ORM for Node.js that supports SQLite3, MySQL, PostgreSQL, Oracle, REST APIs, LDAP, and ActiveDirectory. The current stable version is 2.11.1, released infrequently with no fixed cadence. Key differentiators: automatic model definition from database schema, built-in GraphQL support, and a plugin system for extensibility. It uses a store-based architecture and supports async/await natively. Ships TypeScript definitions.

npm install openrecord
INSTALL
IMPORT
SIG · OPENRECORD
O
openrecord
databasejavascriptv2.11.1
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.

Store
const Store = require('openrecord/store/sqlite3')
const Store = require('openrecord')
You must require the specific store adapter (e.g., sqlite3, mysql, postgres). The main openrecord module does not provide a default store.
Store
import Store from 'openrecord/store/sqlite3'
import { Store } from 'openrecord/store/sqlite3'
ESM import uses default import. Named import will be undefined. ES modules supported.
Model
const { Model } = require('openrecord')
The Model base class can be imported for custom model definitions. It is also accessible via store.Model() after store creation.
store.Model
const store = new Store({...}); const Post = store.Model('Post')
new Store.Model('Post')
Model classes are accessed via store instance, not directly from the Store constructor. store.Model() returns a model class.

Shows SQLite3 store initialization, finding a record by primary key, querying with a where clause, creating and saving a record, and deleting a record.

const Store = require('openrecord/store/sqlite3'); const store = new Store({ file: './my-posts-db.sqlite3', autoLoad: true }); store.ready(async () => { const post = await store.Model('Post').find(1); console.log(post.toJSON()); const posts = await store.Model('Post').where({ title: { contains: 'hello' }}).all(); console.log(posts.map(p => p.title)); const newPost = store.Model('Post').create({ title: 'New Post', content: 'Hello world' }); await newPost.save(); console.log('Created post with id:', newPost.id); await newPost.delete(); });
Debug
Known issues
gotchaStore must be instantiated with `autoLoad: true` to automatically load model definitions from database table schemas.
fix
Ensure `autoLoad: true` is set in Store options if you want automatic schema reflection.
affects: >=2.0.0
gotchaModel attributes are not defined until the store is ready or after a query is executed. Accessing attributes before store.ready() may throw.
fix
Wrap all model interactions inside `store.ready()` callback or after awaiting `store.ready()`.
affects: >=2.0.0
deprecatedUsing `require('openrecord')` directly without a store adapter is deprecated and will warn.
fix
Use `require('openrecord/store/sqlite3')` or equivalent store adapter.
affects: >=2.0.0
gotchaThe `.find()` method expects a primary key value; if no primary key is defined in the table, it may throw.
fix
Ensure the database table has a primary key column, or use `.where()` to filter.
affects: >=2.0.0
gotchaESM import must be default import: `import Store from 'openrecord/store/sqlite3'` not named.
fix
Use default import syntax.
affects: >=2.0.0
Errors
Common errors & fixes
Error: Cannot find module 'openrecord/store/sqlite3'
Missing the database driver dependency (e.g., better-sqlite3 for SQLite3, mysql for MySQL, pg for PostgreSQL).
fix
Install the corresponding database driver: npm install better-sqlite3 (or mysql, pg, etc.).
TypeError: store.Model is not a function
Attempting to call store.Model before store has finished initializing. store.ready() must be awaited.
fix
Move store.Model calls inside store.ready() callback or after await store.ready().
Error: SQLITE_ERROR: no such table: Post
The database file does not contain a table named 'Post', or autoLoad is not set to true.
fix
Ensure the database has the expected table, or set autoLoad: true and ensure the table name matches the model name (case-sensitive).
Error: Cannot read property 'id' of undefined
The .find() method returned null because no record with that primary key exists.
fix
Check if the record exists before accessing properties, e.g., if (post) { console.log(post.id); }.
ReferenceError: require is not defined
Using ES modules (type: "module" in package.json) but trying to use CommonJS require.
fix
Use import syntax: import Store from 'openrecord/store/sqlite3';
Upgrade
Version history
2.11.1latest on npm
Audit
Dependencies
openrecordoptionalSupporting SQLite3 store
openrecordoptionalSupporting MySQL store
openrecordoptionalSupporting PostgreSQL store
openrecordoptionalSupporting Oracle store
openrecordoptionalSupporting REST store
openrecordoptionalSupporting LDAP store
Agent activity
5 hits · last 30 days
node
4
Resources
openrecord — npm install openrecord · libregistry