Registry / database / js-core-data

js-core-data

JSON →
library1.10.0jsnpmunverified

js-core-data (v1.10.0) is a JavaScript ORM inspired by Apple's CoreData. It simplifies data modeling, version migration, entity management, and persistence by providing a context-based interface similar to CoreData, adapted for server environments. Supports SQLite, MySQL, and PostgreSQL via separate database drivers. Release cadence is low; last update was several years ago. Key differentiator: uses CoreData-like patterns (managed object contexts, relationships, inverse relationships) not found in typical JavaScript ORMs. Suitable for Node.js projects needing an ActiveRecord-style ORM with automated schema syncing.

npm install js-core-data
INSTALL
IMPORT
SIG · JS-CORE-DATA
J
js-core-data
databasejavascriptv1.10.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.

CoreData
import CoreData from 'js-core-data'
var CoreData = require('js-core-data').default
Library ships CJS; default export via require works, but no named exports exist.
default import
const CoreData = require('js-core-data')
const { CoreData } = require('js-core-data')
CommonJS usage; the main export is a constructor function, not a named export.
TypeScript usage
import CoreData from 'js-core-data'; // No type definitions provided
import { CoreData } from 'js-core-data'
No official TypeScript types; use @types/js-core-data or define types manually.

Demonstrates setting up an in-memory SQLite database, defining entities with relationships, syncing schema, creating a context, manipulating objects, and saving.

const CoreData = require('js-core-data'); const db = new CoreData('sqlite://:memory:'); const User = db.define('User', { username: 'string' }); const Company = db.define('Company', { name: 'string' }); db.defineRelationship(User, Company, 'company', { inverse: 'users' }); db.defineRelationship(Company, User, 'users', { inverse: 'company', toMany: true }); db.syncSchema({ force: true }).then(() => { const context = db.createContext(); const user1 = context.create('User', { username: 'user1' }); const user2 = context.create('User', { username: 'user2' }); const company = context.create('Company', { name: 'test company' }); user1.setCompany(company); company.addUser(user2); context.save().then(() => { console.log('Data saved'); context.destroy(); }); }).catch(err => console.error(err));
Debug
Known issues
gotchaDatabase driver packages must be installed separately.
fix
npm install --save mysql (or sqlite3, pg)
affects: >=1.0.0
breakingIn v1.6.0, `defineRelationship` signature changed. The third parameter was changed from 'object' to 'string'.
fix
Update to use string for relationship name: e.g., `defineRelationship(User, Company, 'company', {...})`
affects: <1.6.0
deprecatedThe `syncSchema` method's `force` option is deprecated in favor of `dropTables: true`.
fix
Use `{ dropTables: true }` instead of `{ force: true }`.
affects: >=1.8.0
gotchaContext methods `create`, `save`, and `destroy` are asynchronous and return Promises.
fix
Always await or chain .then() on these methods.
affects: >=1.0.0
gotchaRelationship methods like `addUser` are generated dynamically; misnaming them causes runtime errors.
fix
Ensure relationship names match exactly: e.g., `company.addUser(user2)` works if 'users' relationship is defined with `toMany: true`.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'sqlite3'
Database driver not installed.
fix
Run: npm install --save sqlite3
TypeError: db.define is not a function
Incorrect import (e.g., using named import instead of default).
fix
Use const CoreData = require('js-core-data'); then new CoreData(...)
Error: schema sync failed - Table 'users' already exists
Calling syncSchema without force or dropTables after initial creation.
fix
Use syncSchema({ dropTables: true }) to drop and recreate tables.
ValidationError: required field 'username' missing
Entity defined with required attribute but not provided.
fix
Provide all required fields when creating or update entity with missing fields.
Upgrade
Version history
1.10.0latest on npm
Audit
Dependencies
mysqloptionalRequired for MySQL database support
sqlite3optionalRequired for SQLite database support
pgoptionalRequired for PostgreSQL database support
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
js-core-data — npm install js-core-data · libregistry