Registry / database / tyb-express-cassandra

tyb-express-cassandra

JSON →
library1.9.3jsnpmunverified

Express-Cassandra is a framework-independent Cassandra Object Models (ORM) for NodeJS that wraps the DataStax DSE driver (based on cassandra-driver). Version 1.9.3 supports Cassandra 3.x with features like CRUD operations, data type validations, materialized views, secondary/custom/SASI indexes, user-defined types, batch operations, hook functions, automatic migrations, and promise support via Async suffixed functions. It is compatible with Express, Restify, Hapi, Koa, and more. Note: legacy Cassandra 2.x users must use version 0.5.4. The ORM is built on a highly modified version of apollo-cassandra.

npm install tyb-express-cassandra
INSTALL
IMPORT
SIG · TYB-EXPRESS-CASSAN
T
tyb-express-cassandra
databasejavascriptv1.9.3
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.

default
import models from 'express-cassandra'
const models = require('express-cassandra');
Default export is the model container. Use import models from 'express-cassandra' (ESM). For CommonJS, use const models = require('express-cassandra');
Model
import { Model } from 'express-cassandra'
const { Model } = require('express-cassandra');
Named export for creating model definitions. Not commonly needed; usual pattern is to call models.connect() and then models.load().
types
import { types } from 'express-cassandra'
Exports Cassandra data types (e.g., types.TimeUuid) for use in model schemas.

Initializes the ORM, connects to a local Cassandra instance, defines a User model, saves a record using promises.

const models = require('express-cassandra'); models.setDirectory(__dirname + '/models').bind({ clientOptions: { contactPoints: ['127.0.0.1'], protocolOptions: { port: 9042 }, keyspace: 'mykeyspace' }, ormOptions: { defaultReplicationStrategy: { class: 'SimpleStrategy', replication_factor: 1 }, migration: 'safe' } }); const User = models.load('User', { fields: { id: { type: 'uuid', default: { $db_function: 'uuid()' } }, name: { type: 'text' }, email: { type: 'text' } }, key: ['id'] }); models.connect(function(err) { if (err) throw err; const user = new User({ name: 'John', email: 'john@example.com' }); user.saveAsync().then(() => console.log('User saved')); });
Debug
Known issues
breakingVersion 1.0 switched from cassandra-driver to dse-driver, breaking compatibility with older Cassandra versions and changing API methods.
fix
Migrate to dse-driver API or use express-cassandra@0.5.4 for Cassandra 2.x.
affects: >=1.0.0
deprecatedThe .save() callback-based method is deprecated; use .saveAsync() which returns a promise.
fix
Replace .save() with .saveAsync() and handle with then/catch or async/await.
affects: >=1.0.0
gotchaDefault export is a factory function, not the ORM instance itself. Calling require('express-cassandra') returns a function you must invoke with configuration.
fix
Use const models = require('express-cassandra')() or const models = require('express-cassandra').connect({...}).
affects: >=1.0.0
gotchaMigration mode 'alter' can drop columns automatically. Use 'safe' to avoid unintended schema changes.
fix
Set ormOptions.migration: 'safe' in the bind() call.
affects: >=1.0.0
gotchaThe package name on npm is 'express-cassandra', but the GitHub repository is 'tyb-express-cassandra'. Ensure you install the correct one.
fix
npm install express-cassandra (not tyb-express-cassandra).
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'dse-driver'
The package 'dse-driver' is a peer dependency that must be installed separately.
fix
npm install dse-driver
TypeError: models.load is not a function
Default export is a function; you must call it with .bind() or .connect() before using .load().
fix
Correct usage: const models = require('express-cassandra'); models = models.bind({...}); then models.load('User', schema);
All host(s) tried for query failed. First host tried, 127.0.0.1:9042: Error: connect ECONNREFUSED 127.0.0.1:9042
Cassandra is not running or not reachable at the specified contact point.
fix
Ensure Cassandra is started on 127.0.0.1:9042, or update contactPoints and port in clientOptions.
Upgrade
Version history
1.9.3latest on npm
Audit
Dependencies
dse-driverrequiredOfficial DataStax driver for Apache Cassandra and DSE; provides all Cassandra connectivity
Agent activity
19 hits · last 30 days
node
14
Meta
2
OpenAI (training)
1
Resources
tyb-express-cassandra — npm install tyb-express-cassandra · libregistry