cql-builder
Simple Cassandra CQL Builder in Javascript
Installation
$ npm install --save cassandra-cql-builder
Usage
import { Insert, Select, Update, Delete, CqlBuilderError } from 'cassandra-cql-builder';
const result = Select().table('test_table', 'test_keyspace').build();
Insert
Generate insert query
const cql = Insert()
.table('test_table', 'test_keyspace')
.value('column1', 1)
.option('TTL', 86400)
.option('TIMESTAMP', 12345678)
.build();
Methods
- InsertBuilder.table(table, keyspace)
- InsertBuilder.value(field, value)
- InsertBuilder.option(option, value)
Select
Generate select query
const cql = Select()
.table('test_table', 'test_keyspace')
.field(['column1', 'column2'])
.field('column3')
.where('key1 = ?', 1000)
.where('key2 > ?', 2000)
.limit(5000)
.order('key1 DESC')
.where('key3 IN (?, ?)', 3000, 4000)
.option('TTL', 86400)
.build();
Methods
- SelectBuilder.table(table, keyspace)
- SelectBuilder.field(field)
- SelectBuilder.where(where, values)
- SelectBuilder.order(order)
- SelectBuilder.limit(limit)
Update
Generate update query
const cql = Update()
.table('test_table')
.set('column1', 1)
.where('key1 = ?', 'a')
.option('TTL', 3000)
.upsert(true)
.build();
Methods
- UpdateBuilder.table(table, keyspace)
- UpdateBuilder.set(field, value)
- UpdateBuilder.where(where, values)
- UpdateBuilder.upsert(upsert)
- UpdateBuilder.option(option, value)
Delete
Generate delete query
const cql = Delete()
.table('test_table')
.where('key1 = ?', 'a')
.field(['column1', 'column2'])
.option('TIMESTAMP', 12345678)
.build();
Methods
- DeleteBuilder.table(table, keyspace)
- DeleteBuilder.field(field)
- DeleteBuilder.where(where, values)
- DeleteBuilder.option(option, value)
Development
$ git clone git@github.com:ridibooks/cql-builder.git
$ cd cql-builder
$ npm install
Build
Webpack build using Babel (Not required in development.)
$ npm run build
Test
Tests using Jest
$ npm test