{"id":19165723,"url":"https://github.com/loopbackio/loopback-connector-cassandra","last_synced_at":"2026-02-13T01:11:50.629Z","repository":{"id":42965825,"uuid":"40493199","full_name":"loopbackio/loopback-connector-cassandra","owner":"loopbackio","description":"Cassandra connector for the LoopBack framework.","archived":false,"fork":false,"pushed_at":"2023-12-15T05:47:43.000Z","size":166,"stargazers_count":13,"open_issues_count":3,"forks_count":22,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-19T22:02:49.436Z","etag":null,"topics":["cassandra","connector","loopback"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loopbackio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-10T16:27:34.000Z","updated_at":"2022-03-24T00:24:56.000Z","dependencies_parsed_at":"2024-11-09T09:30:00.929Z","dependency_job_id":"c2d43baa-e037-4763-bb3c-6e6e74803253","html_url":"https://github.com/loopbackio/loopback-connector-cassandra","commit_stats":null,"previous_names":["strongloop/loopback-connector-cassandra"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-cassandra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-cassandra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-cassandra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-cassandra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loopbackio","download_url":"https://codeload.github.com/loopbackio/loopback-connector-cassandra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252874892,"owners_count":21817923,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cassandra","connector","loopback"],"created_at":"2024-11-09T09:29:08.271Z","updated_at":"2025-10-04T10:23:36.078Z","avatar_url":"https://github.com/loopbackio.png","language":"JavaScript","readme":"# loopback-connector-cassandra\n\nThe official Cassandra Connector module for [loopback-datasource-juggler](http://docs.strongloop.com/loopback-datasource-juggler/).\n\n\u003cdiv class=\"gh-only\"\u003ePlease also see \u003ca href=\"http://loopback.io/doc/en/lb3/Cassandra-connector.html\"\u003eLoopBack Cassandra Connector\u003c/a\u003e in LoopBack documentation.\n\u003c/div\u003e\n\n## Installation\n\nIn your application root directory, enter this command to install the connector:\n\n```sh\nnpm install loopback-connector-cassandra --save\n```\n\nThis installs the module from npm and adds it as a dependency to the application's `package.json` file.\n\nIf you create a Cassandra data source using the data source generator as described below, you don't have to do this, since the generator will run `npm install` for you.\n\n## Creating a Cassandra data source\n\nUse the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a Cassandra data source to your application.  Select `Cassandra` connector as follows:\n```\n$ lb datasource\n? Enter the data-source name: mycass\n? Select the connector for mycass: \n  IBM Cloudant DB (supported by StrongLoop) \n  IBM DB2 for z/OS (supported by StrongLoop) \n  IBM WebSphere eXtreme Scale key-value connector (supported by StrongLoop) \n❯ Cassandra (supported by StrongLoop) \n  Redis key-value connector (supported by StrongLoop) \n  MongoDB (supported by StrongLoop) \n  MySQL (supported by StrongLoop) \n(Move up and down to reveal more choices)\n```\nThe generator will then prompt for the database server hostname, port, and other settings\nrequired to connect to a Cassandra database.  It will also run the `npm install` command for you.\n```\n$ lb datasource\n? Enter the data-source name: mycass\n? Select the connector for mycass: Cassandra (supported by StrongLoop)\nConnector-specific configuration:\n? host: localhost\n? port: 9042\n? user: \n? password: \n? database: test\n? connectTimeout(ms): 30000\n? readTimeout(ms): 30000\n? Install loopback-connector-cassandra@^1.0.0 Yes\nloopback-connector-cassandra@1.0.0 node_modules/loopback-connector-cassandra\n...\n```\n\nThe entry in the application's `/server/datasources.json` will look like this:\n```javascript\n\"mycass\": {\n  \"host\": \"localhost\",\n  \"port\": 9042,\n  \"database\": \"test\",\n  \"password\": \"\",\n  \"name\": \"mycass\",\n  \"user\": \"\",\n  \"connectTimeout\": 30000,\n  \"readTimeout\": 30000,\n  \"connector\": \"cassandra\"\n}\n```\n\nEdit `datasources.json` to add any other additional properties supported by [`cassandra-driver`](https://github.com/datastax/nodejs-driver).\n\n## Type mappings\n\nSee [LoopBack types](http://loopback.io/doc/en/lb3/LoopBack-types.html) for details on LoopBack's data types.\n\n### LoopBack to/from Cassandra types\n\nIn addition to the standard data types such as String, Boolean, and Number, several Cassandra specific types are supported as shown in the table blow.\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eLoopBack Type\u003c/th\u003e\n      \u003cth\u003eCassandra Type\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e    \n    \u003ctr\u003e\n      \u003ctd\u003eUuid\u003c/td\u003e\n      \u003ctd\u003eUUID\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eTimeUuid\u003c/td\u003e\n      \u003ctd\u003eTIMEUUID\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eTuple\u003c/td\u003e\n      \u003ctd\u003eTUPLE\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n## Primary Keys\n\n### Auto generated partition keys\n\nIn case no `id` is defined, LoopBack adds ***id*** with Cassandra connector's default type: `Uuid`.\n\nLoopBack notation:\n\n```javascript\nzipCodes = db.define('zipCodes', {\n  state: String,\n  zipCode: Number,\n  });\n```\n\nCql equivalent:\n\n```sql\nCREATE TABLE zipCodes (\n   state TEXT,\n   zipCode INT,\n   id UUID,\n   PRIMARY KEY (id)\n);\n```\n\n### User defined partition keys\n\nLoopBack notation:\n\nWhen `id: true` is defined, LoopBack does not add `id` and uses it as a partition key.\n\n```javascript\ncustomers = db.define('customers', {\n  name: String,\n  state: String,\n  zipCode: Number,\n  userId: {type: 'TimeUuid', id: true},\n  });\n```\n\nCql equivalent:\n\n```sql\nCREATE TABLE customers (\n   name TEXT,\n   state TEXT,\n   zipCode INT,\n   userId TIMEUUID,\n   PRIMARY KEY (userId)\n);\n```\n\n### Compound partition keys\n\nLoopBack notation:\n\n`id` value can be either boolean or number (base 1).  Compound partition key is created by combining the ones with number in ascending order\nthen boolean.  In case conflict, first-come first-served.\n\n```javascript\ncustomers = db.define('customers', {\n  isSignedUp: {type: Boolean, id: 2},\n  state: String,\n  contactSalesRep: {type: String, id: true},\n  zipCode: Number,\n  userId: {type: Number, id: 1},\n  });\n```\n\nCql equivalent:\n\n```sql\nCREATE TABLE customers (\n   isSignedUp BOOLEAN,\n   state TEXT,\n   contactSalesRep TEXT,\n   zipCode INT,\n   userId INT,\n   PRIMARY KEY ((userId, isSignedUp, contactSalesRep))\n);\n```\n\n## Clustering keys and Sorting\n\nCassandra stores data on each node according to the hashed TOKEN value of the partition key in the range that the node is responsible for.\nSince hashed TOKEN values are generally random, `find` with `limit: 10` filter will return apparently random 10 (or less) rows.\nThe Cassandra connector supports on-disk sorting by setting `clustering key` as ASCending or DESCending at table creation time.\n`order` filter is ignored.  Since sorting is done on node by node basis, the returned result is property sorted only when the partition key is specified.\n\nFor example, in case you want to find the most recently added row, create a table with time-based column as a clustering key with DESC property.\nThen, use `find` with `limit: 1` or `findOne`.\n\nConcrete example is as follows assuming all the rows fall in the same partition range.\nNote that `clusteringKeys` is defined as an array because the order of the sorting keys is important:\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eisSignedUp\u003c/th\u003e\n      \u003cth\u003estate\u003c/th\u003e\n      \u003cth\u003econtactSalesRep\u003c/th\u003e\n      \u003cth\u003ezipCode\u003c/th\u003e\n      \u003cth\u003euserId\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e    \n    \u003ctr\u003e\n      \u003ctd\u003etrue\u003c/td\u003e\n      \u003ctd\u003eArizona\u003c/td\u003e\n      \u003ctd\u003eTed Johnson\u003c/td\u003e\n      \u003ctd\u003e85003\u003c/td\u003e\n      \u003ctd\u003e2003\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003etrue\u003c/td\u003e\n      \u003ctd\u003eArizona\u003c/td\u003e\n      \u003ctd\u003eDavid Smith\u003c/td\u003e\n      \u003ctd\u003e85002\u003c/td\u003e\n      \u003ctd\u003e16002\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003etrue\u003c/td\u003e\n      \u003ctd\u003eArizona\u003c/td\u003e\n      \u003ctd\u003eMary Parker\u003c/td\u003e\n      \u003ctd\u003e85001\u003c/td\u003e\n      \u003ctd\u003e15001\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003etrue\u003c/td\u003e\n      \u003ctd\u003eCalifornia\u003c/td\u003e\n      \u003ctd\u003eDavid Smith\u003c/td\u003e\n      \u003ctd\u003e90001\u003c/td\u003e\n      \u003ctd\u003e21002\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003etrue\u003c/td\u003e\n      \u003ctd\u003eColorado\u003c/td\u003e\n      \u003ctd\u003eMary Parker\u003c/td\u003e\n      \u003ctd\u003e80002\u003c/td\u003e\n      \u003ctd\u003e2010\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003etrue\u003c/td\u003e\n      \u003ctd\u003eColorado\u003c/td\u003e\n      \u003ctd\u003eJane Miller\u003c/td\u003e\n      \u003ctd\u003e80001\u003c/td\u003e\n      \u003ctd\u003e12002\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003etrue\u003c/td\u003e\n      \u003ctd\u003eNevada\u003c/td\u003e\n      \u003ctd\u003eTed Johnson\u003c/td\u003e\n      \u003ctd\u003e75173\u003c/td\u003e\n      \u003ctd\u003e28006\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\nLoopBack notation:\n\nCassandra connector supports clustering key as a custom option.  Sorting order can be associated with clustering keys as `ASC` or `DESC`.\n\n```javascript\ncustomers = db.define('customers', {\n  isSignedUp: {type: Boolean, id: true},\n  state: String,\n  contactSalesRep: String,\n  zipCode: Number,\n  userId: Number,\n  }, {\n  cassandra: {\n    clusteringKeys: ['state', 'zipCode DESC'],\n    },\n  });\n```\n\nCql equivalent:\n\n```sql\nCREATE TABLE customers (\n   isSignedUp BOOLEAN,\n   state TEXT,\n   contactSalesRep TEXT,\n   zipCode INT,\n   userId INT,\n   PRIMARY KEY (isSignedUp, state, zipCode)\n) WITH CLUSTERING ORDER BY (state ASC, zipCode DESC);\n```\n\n## Secondary Indexes\n\nAdditional searchable fields can be defined as secondary indexes.  For example, in case the table `customers` below is defined with `name` as just `{type: String}`,\n then `find` with `where: {name: \"Martin Taylor\"}` filter will fail.  However, `find` with `where: {namee: \"Martin Taylor\"}` filter will succeed on the table defined with `index: true` as follows:\n\n\nLoopBack notation:\n\n```javascript\ncustomers = db.define('customers', {\n  name: {type: String, index: true},\n  userId: {type: Number, id: true},\n  });\n```\n\nCql equivalent:\n\n```sql\nCREATE TABLE customers (\n   name TEXT,\n   userId INT,\n   PRIMARY KEY (userId)\n);\nCREATE INDEX ON customers (name);\n```\n\n## V1 Limitations\n\nBecause of the Cassandra architecture, Cassandra connector V1 supports `where` and `limit`.\nOther filter conditions are not supported.\n\n### `order` filter not supported\n\nUse clustering keys for sorting.  The database side sorting determines the order or rows to be return\nwhen ordering matters such as `where limit` or `findOne`.  Ad hoc sorting with `sort` filter is not supported.\n\n### `or` filter not supported\n\n`and` is supported, but `or` is not in `where` filter.\n\n### `offset` is not supported\n\nPagination is not supported in V1.\n\n## Running tests\n\n### Own instance\nIf you have a local or remote Cassandra instance and would like to use that to run the test suite, use the following command:\n- Linux\n```bash\nCASSANDRA_HOST=\u003cHOST\u003e CASSANDRA_PORT=\u003cPORT\u003e CASSANDRA_KEYSPACE=\u003cKEYSPACE\u003e CI=true npm test\n```\n- Windows\n```bash\nSET CASSANDRA_HOST=\u003cHOST\u003e\nSET CASSANDRA_PORT=\u003cPORT\u003e\nSET CASSANDRA_KEYSPACE=\u003cKEYSPACE\u003e\nSET CI=true\nnpm test\n```\n\n### Docker\nIf you do not have a local Cassandra instance, you can also run the test suite with very minimal requirements.\n- Assuming you have [Docker](https://docs.docker.com/engine/installation/) installed, run the following script which would spawn a Cassandra instance on your local:\n```bash\nsource setup.sh \u003cHOST\u003e \u003cPORT\u003e \u003cKEYSPACE\u003e\n```\nwhere `\u003cHOST\u003e`, `\u003cPORT\u003e` and `\u003cKEYSPACE\u003e` are optional parameters. The default values are `localhost`, `9042` and `test` respectively.\n- Run the test:\n```bash\nnpm test\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopbackio%2Floopback-connector-cassandra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floopbackio%2Floopback-connector-cassandra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopbackio%2Floopback-connector-cassandra/lists"}