Registry / database / earthtoday-express-cassandra

earthtoday-express-cassandra

JSON →
library2.5.0jsnpmunverified

Express-Cassandra v2.5.0 is a Cassandra ORM/ODM/OGM for Node.js with support for Elassandra & JanusGraph. It provides object-oriented mapping to Cassandra tables, automatic index syncing with Elasticsearch via Elassandra, and graph management via JanusGraph. Compatible with Cassandra 3.x, DataStax Enterprise, and DSE Graph. Model-driven schema creation, CRUD operations, queries, streaming, batching, hooks, and migrations are built-in. Uses the DataStax Cassandra driver by default or the DSE driver if installed. Maintained since 2015 with monthly releases.

npm install earthtoday-express-cassandra
INSTALL
IMPORT
SIG · EARTHTODAY-EXPRESS
E
earthtoday-express-cassandra
databasejavascriptv2.5.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.

ExpressCassandra
const models = require('express-cassandra');
import models from 'express-cassandra';
The library is CJS-only; ESM imports will fail.
modelInstance
const MyModel = models.loadSchema('MyModel', schemaDefinition);
const MyModel = new models.Model('MyModel', schemaDefinition);
Models are loaded via loadSchema, not constructed directly.
orm
const orm = require('express-cassandra')({ clientOptions: { contactPoints: ['127.0.0.1'] } });
const orm = require('express-cassandra').connect({ contactPoints: ['127.0.0.1'] });
Instantiate by calling the exported function; there is no .connect() method.

Initialize the ORM with a Cassandra connection, load models from a directory, and save a new user record asynchronously.

const models = require('express-cassandra'); models.setDirectory(__dirname + '/models').bind({ clientOptions: { contactPoints: [process.env.CASSANDRA_HOST || '127.0.0.1'], protocolOptions: { port: 9042 }, keyspace: 'my_keyspace', queryOptions: { consistency: models.consistencies.one } }, ormOptions: { defaultReplicationStrategy: { class: 'SimpleStrategy', replication_factor: 1 }, migration: 'safe', createKeyspace: true } }, function(err) { if (err) console.error(err); else { const User = models.instance.User; const user = new User({ name: 'John', email: 'john@example.com' }); user.saveAsync().then(() => console.log('Saved')).catch(console.error); } });
Debug
Known issues
breakingIn v2.0.0, the `save`, `update`, and `delete` methods were changed to return promises when suffixed with `Async`; the synchronous versions now return the model instance.
fix
Use the `Async` suffix (e.g., `saveAsync()`) for promise behavior, or omit it for the old-style callbacks.
affects: >=2.0.0 <2.0.0
deprecatedThe `find` method without a callback is deprecated in v2.4.0; use `findAsync` instead.
fix
Replace `model.find(query)` with `model.findAsync(query)` to get a promise.
affects: >=2.4.0
gotchaSchema changes do not auto-migrate by default; you must set `migration: 'safe'` or `'alter'` in ormOptions.
fix
Set `migration: 'safe'` (no data loss) or `'alter'` (may drop columns) in ormOptions.
affects: all
gotchaCassandra driver version must be compatible; using a newer driver may break connections.
fix
Keep `cassandra-driver` at a version recommended by express-cassandra (currently 4.x).
affects: all
Errors
Common errors & fixes
Error: No hosts available for the control connection
Cassandra server is not running or contact points are incorrect.
fix
Ensure Cassandra is running on the specified host/port and contactPoints is set correctly.
Example: contactPoints: ['localhost']
TypeError: models.loadSchema is not a function
Incorrect usage of the ORM instance; loadSchema is available on the orm instance, not the required module.
fix
After initializing, use `models.instance.MyModel` or call `loadSchema` on the ORM instance returned by the constructor.
Error: Keyspace 'my_keyspace' does not exist
The keyspace has not been created and `createKeyspace` option is false (default).
fix
Set `createKeyspace: true` in ormOptions or create the keyspace manually with CQL.
Upgrade
Version history
2.5.0latest on npm
Audit
Dependencies
cassandra-driverrequiredCore dependency for Cassandra connectivity
dse-driveroptionalOptional driver for DataStax Enterprise compatibility
Agent activity
7 hits · last 30 days
node
6
Resources
earthtoday-express-cassandra — npm install earthtoday-express-cassandra · libregistry