Git Product home page Git Product logo

masumsoft / express-cassandra Goto Github PK

View Code? Open in Web Editor NEW
228.0 17.0 67.0 1.53 MB

Cassandra ORM/ODM/OGM for NodeJS with support for Apache Cassandra, ScyllaDB, Datastax Enterprise, Elassandra & JanusGraph.

Home Page: http://express-cassandra.readthedocs.io

License: GNU Lesser General Public License v3.0

JavaScript 100.00%
cassandra orm nodejs odm node dse apache-cassandra datastax janusgraph elasticsearch

express-cassandra's People

Contributors

alexiswilke avatar alexleventer avatar amftech512 avatar annahassel avatar dependabot[bot] avatar dukei avatar face avatar ignacio-badiola avatar jindai1783 avatar masumsoft avatar mikestaub avatar mrusme avatar nopjia avatar pierreis avatar sparkida avatar taufique71 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

express-cassandra's Issues

Not really an issue...but

Hello,

Not really an issue, but wondered how I would create a composite key (like a one to many relationship).

I want to try and map Artists and Albums - so with an album have the key made up of the artist id and the album id. Would you be able to explain this in your examples?

Really appreciate any help you can provide.

Enjoy your weekend :)

Updating list using update command

Hey, I wanted to know if we can update a list, i.e, add an element at the end of the list by using update command in the orm which i verified can be done from the cqlsh shell using the update command. We can obviously do it by finding the row, adding the changes we want and saving back the row, just wondering if we can achieve this using the update command.

unconfigured table schema_keyspaces

I'm using cassandra version 3.0.3. And when im running the node server im getting this error: apollo.model.tablecreation.dbschemaquery: Error while retrieveing Schema of DB Table "ResponseError: unconfigured table schema_keyspaces".
I need some help with this, Is this a compatibility isssue??

DropTableSchemaOnChange

Hi! I wanted to know if we set this option to true in ormOptions do we lose the data in the table every time there is a change in the schema??

Improve test coverage

The current state of test coverage is not in good condition. Improve the test coverage to grow confidence in the codebase.

Table is not being created when column type is counter

Given I have schema:

const ShareLikeCounterByUser = {
  fields: {
    id: {
      type: "uuid",
      default: {"$db_function": "uuid()"}
    },
    name: "varchar",
    photo: "varchar",
    like: "counter",
    share: "counter",
    facebook_id: "varchar",
    work: "varchar",
    created: {
      type: "date",
      default: {"$db_function": "toTimestamp(now())"}
    }
  },
  key: ["facebook_id", "created"],
  indexes: ["facebook_id", "created"],
  table_name: "share_like_counter_by_user"
};

export default ShareLikeCounterByUser;

table is not created in C* but library does not return any errors.
screen shot 2016-07-08 at 10 17 20

But when I comment counters

   // like: "counter",
   // share: "counter",

table is beaing created in C*
screen shot 2016-07-08 at 10 17 43

Am I doing something wrong?

Question: Is it possible to add "toJSON" method for "BaseModel"?

e.g. if I return model to client I see object like this:

Object {
  _validators: Object
  id:"473198a5-e3c9-4f70-ae0b-a4e9b6b64284"
  name:"name"
  __proto__:Object
}

but I want something like this:

{
  "id": "473198a5-e3c9-4f70-ae0b-a4e9b6b64284",
  "name": "name"
}

so is it possible to add method that provides easy way to do this? I can make PR for it.

settings for multi node cluster

Hey, I just wanted to know what should be contactPoints field in clientOptions be? Should it have ip addresses of all the nodes or only seed nodes ?

Support for CRUD hooks

It would be great if the ORM supported crud hook functions like the following:

before_save()
after_save()
before_update()
after_update()
before_delete()
after_delete()

User can define the functions if he wants to process something depending on the CRUD event.

UDT getting saved every time my application restarts.

I have defined my udts in app.js file under orm options which gets called every time the application reloads. I get this error User defined type 'type_name' already exists. Is there a way to turn off the mechanism to add udts once it is created. Right now I am running my script containing udt definitions manually.

Specify SELECT * for materialized view columns

Hi,

When creating a materialized view using CQL it is possible to specify SELECT * FROM <table_name> for the columns to use instead of specifying each column. Can you add a similar feature to express-cassandra? e.g. allow specifying select: ["*"] or select: "*"

Thanks!

Virtual not working

I am using SimpleModel.js as reference and declaring my virtual, but it is not returning me anything.

TTL for materialized views

Hi, i was wondering if we could set a default_time_to_live for a materialized view similar to the one we set while creating a table. I tried it myself in cqlsh with no luck but i could not find any document saying we couldn't do it.

Unable to do range query on timestamp

Given I have this query:

    const query = {
      brand_name: 'Test21',
      created: { '$gt': '2016-06-06' },
    };
    UserLike.find(query, {select: ['created']}, (err, likes) => {
      if (err) reject(err);
      console.log("likes: ", likes);
    })

wherecreated is a timestamp in Cassandra, I am unable to get greather than values.
In the console I am getting likes: undefined

Is it possible to get range between two dates in this library. I can't find it in documentation

Get response on save

Is there a way to get back the object saved using .save() function. I am getting info, columns and pageState in the response object right now.

Sample Query

user.save(function(err, user) {if(!err) res.json(user)})

Express Cassandra Version: 1.0.3
Cassandra: 3.0.7

Schema from Database not validating Type when it has a Reversed type

from line 388 from base_model.js
db_schema.fields[row.column_name] = TYPE_MAP.find_type_by_dbvalidator(row.validator);
returns null when row.validator = "org.apache.cassandra.db.marshal.ReversedType(org.apache.cassandra.db.marshal.TimestampType)"

This is cause when the table is created like this.

CREATE TABLE logs ( id1 text, id2 text, logdate timestamp, content text, user_name text, PRIMARY KEY (id1, id1, logdate) ) WITH CLUSTERING ORDER BY (id2 ASC, logdate DESC);

My simple fix to this is

TYPE_MAP.find_type_by_dbvalidator = function(val){
//decompose composite types
var decomposed = val ? val.split(/[(,)]/) : [''];

for (var d in decomposed){
    for(var t in this){
        if (this[t].dbvalidator == decomposed[d])
            return t;
    }
}

return null;

};

Doesn't connect to database

Hello, I am unable to connect to my database. The models are not being charged.
The code snippet does not run:

`async.each(list, function(file, callback) {

                var fileName = self.directory + '/' + file;
                if(fileName.indexOf('Model') == -1) {
                    callback();
                    return;
                }

                var modelName = self._translateFileNameToModelName(file);

                if(modelName) {
                    var modelSchema = require(fileName);
                    self.modelInstance[modelName] = self.orm.add_model(
                        modelName.toLowerCase(),
                        modelSchema,
                        function(err, result){
                            if(err) {
                                callback(err);
                            }
                            else callback();
                        }
                    );
                }
                else {
                    callback();
                }

            }`

Follow my snippet code:

`var models = require('express-cassandra');

var options = {
clientOptions: {
contactPoints: ['localhost'],
protocolOptions: { port: 9042 },
keyspace: 'chatplace',
queryOptions: {consistency: models.consistencies.one}
},
ormOptions: {
defaultReplicationStrategy : {
class: 'SimpleStrategy',
replication_factor: 1
},
dropTableOnSchemaChange: false,
createKeyspace: true
}
}

models.setDirectory( pathRootApp + '/models').bind(options);`

debug mode

Hi there, is there anyway we can run cassandra in debug mode through the orm ??

Add option to specify table name

When exporting a module the table name is based off the name of the js file. It would be nice to have the option of specifying the table name when exporting a module.

Improve documentation

Enrich the documentation more with examples and feature clarifications. Instead of single page readme, create multiple page topic wise documentation with easy navigation.

Migrations

Does this project supports migrations?
How can I add column to Cassandra, without dropping schema?

Unable to query with Uuid

I get an error when I try to query with a Uuid object. My workaround is I would have to convert it to a string then query with that.

When I do this:

models.instance.Project.find({ owner: user.id }, function(err, projs) {
  // code
});

I get the following error:

{ [apollo.model.find.invalidop: Invalid field relation: unknown operator: "buffer"] name: 'apollo.model.find.invalidop' }

Support for static columns

Are static columns supported? If not could you add support for specifying a list of static columns on a table?

Table names containing capital letters are converted to lowercase

This is the code I use to initialize my schema:

import ExpressCassandra from 'express-cassandra'

import CassandraOptions from './CassandraOptions'


const cassandra = ExpressCassandra.createClient( {
    clientOptions: CassandraOptions, // Options are pre-set in a separate part of the application, they are correct
    ormOptions: {
        defaultReplicationStrategy : {
            class: 'SimpleStrategy',
            replication_factor: 1
        },
        dropTableOnSchemaChange: false,
        createKeyspace: true
    }
} )

var MyTableSchema = cassandra.loadSchema( 'MyTable', {
    fields: {
        MyTable_Name: 'text',
        MyTable_Password: 'text'
    },
    key: ['MyTable_Name']
});

cassandra.connect(function (err) {
    if (err) {
        console.log(err.message);
    } else {
        console.log(cassandra.modelInstance.MyTable);
        console.log(cassandra.modelInstance.MyTable === MyTableSchema);
    }
})

The application will be run against an existing database. First, I verify that the database does not have MyTable:

$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.3 | CQL spec 3.4.0 | Native protocol v4]
Use HELP for help.
cqlsh> use rebar;
cqlsh:rebar> describe tables;

"Compendium"               "Translaticiarum"      "AccountVerificationRequest"
"ExhibitionItemImage"      logs                   "ToDo"                      
"Villa"                    "ExhibitionItem"       "User"                      
"UserPassportIdentity"     "AccountConfirmation"
"RBPaymentsPaymentMethod"  "Ensayo"             

cqlsh:rebar> exit

Then I start the server that will execute the code above. Notice the last two lines are from the console.log statements executed upon success:

$ npm run dev-server

> [email protected] dev-server /Users/alex/Documents/Projects/Rebar
> better-npm-run dev-server

running better-npm-run in /Users/alex/Documents/Projects/Rebar
Executing script: dev-server

to be executed: nodemon --exec ./node_modules/.bin/babel-node -- ./server/server.js 
[nodemon] 1.10.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `./node_modules/.bin/babel-node ./server/server.js`
{ name: 'urb',
  version: '7.6.4.50',
  NODE_ENV: 'development',
  HOST: 'localhost',
  PORT: '4444',
  PUBLIC_URL: 'http://localhost:4444',
  process_title: '/usr/local/bin/node',
  process_pid: 3551,
  local_ip: '192.168.1.71',
  objectPersistence: 'cassandra',
  CASSANDRA_KEYSPACE: 'rebar',
  CASSANDRA_CONNECTION_POINTS: '127.0.0.1' }
{ [Function]
  super_: 
   { [Function]
     _properties: { name: null, schema: null },
     _set_properties: [Function],
     _validate: [Function],
     _get_validators: [Function],
     _ensure_connected: [Function],
     _execute_definition_query: [Function],
     _execute_batch: [Function],
     execute_batch: [Function],
     get_cql_client: [Function],
     _create_table: [Function],
     _create_table_query: [Function],
     _create_materialized_view_query: [Function],
     _create_index_query: [Function],
     _create_custom_index_query: [Function],
     _get_db_table_schema: [Function],
     _execute_table_query: [Function],
     _get_db_value_expression: [Function],
     _create_where_clause: [Function],
     _create_find_query: [Function],
     get_table_name: [Function],
     is_table_ready: [Function],
     init: [Function],
     syncDefinition: [Function],
     execute_query: [Function],
     execute_eachRow: [Function],
     _execute_table_eachRow: [Function],
     eachRow: [Function],
     execute_stream: [Function],
     _execute_table_stream: [Function],
     stream: [Function],
     find: [Function],
     findOne: [Function],
     update: [Function],
     delete: [Function],
     drop_mviews: [Function],
     drop_table: [Function] },
  _properties: 
   { name: 'mytable',
     schema: { fields: [Object], key: [Object] },
     keyspace: 'rebar',
     define_connection: 
      Client {
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: 0,
        options: [Object],
        connected: false,
        isShuttingDown: false,
        keyspace: 'rebar',
        metadata: [Object],
        hosts: null },
     cql: 
      Client {
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: 0,
        options: [Object],
        connected: false,
        isShuttingDown: false,
        keyspace: 'rebar',
        metadata: [Object],
        hosts: null },
     get_constructor: [Function: bound ],
     connect: [Function: bound ],
     dropTableOnSchemaChange: false,
     table_name: 'mytable',
     qualified_table_name: '"rebar".mytable' },
  _set_properties: [Function],
  _validate: [Function],
  _get_validators: [Function],
  _ensure_connected: [Function],
  _execute_definition_query: [Function],
  _execute_batch: [Function],
  execute_batch: [Function],
  get_cql_client: [Function],
  _create_table: [Function],
  _create_table_query: [Function],
  _create_materialized_view_query: [Function],
  _create_index_query: [Function],
  _create_custom_index_query: [Function],
  _get_db_table_schema: [Function],
  _execute_table_query: [Function],
  _get_db_value_expression: [Function],
  _create_where_clause: [Function],
  _create_find_query: [Function],
  get_table_name: [Function],
  is_table_ready: [Function],
  init: [Function],
  syncDefinition: [Function],
  execute_query: [Function],
  execute_eachRow: [Function],
  _execute_table_eachRow: [Function],
  eachRow: [Function],
  execute_stream: [Function],
  _execute_table_stream: [Function],
  stream: [Function],
  find: [Function],
  findOne: [Function],
  update: [Function],
  delete: [Function],
  drop_mviews: [Function],
  drop_table: [Function] }
true
^C

I stop the server and verify what was created:

$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.3 | CQL spec 3.4.0 | Native protocol v4]
Use HELP for help.
cqlsh> use rebar;
cqlsh:rebar> describe tables;

"Compendium"               "Translaticiarum"      "Ensayo"                    
"ExhibitionItemImage"      mytable                "AccountVerificationRequest"
"Villa"                    logs                   "ToDo"                      
"UserPassportIdentity"     "ExhibitionItem"       "User"                      
"RBPaymentsPaymentMethod"  "AccountConfirmation"

cqlsh:rebar> describe table mytable;

CREATE TABLE rebar.mytable (
    "MyTable_Name" text PRIMARY KEY,
    "MyTable_Password" text
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

cqlsh:rebar> 

Notice that capitalization is successfully preserved in field names, but not in table names.

Would it be a big change to add support for table names with capital letters? Seems like it has already been done for the field names and from my knowledge of CQL it would seem it's mostly a matter of adding double quotes around the name like "MyTable".

Support for authProvider option

I would like to be able to pass in the authProvider as an option like this...

import cassandra from 'express-cassandra';
import driver from 'cassandra-driver';
import config from '../config';

// configure the authProvider
const { contactPoints, cassandraUsername, cassandraPassword, keyspace } = config;
const authProvider = new driver.auth.PlainTextAuthProvider(cassandraUsername, cassandraPassword);

// export the cassandra connection
export default cassandra.createClient({
  clientOptions: {
    contactPoints,
    authProvider,
    keyspace
  }, etc...
});

Here is a pull request: #37
Thanks!
Evan

Complex Order by query giving errors

Hey, when i am trying complex order by during find query $orderby:{'$desc' : ['k1','k2']. it's giving this error : Error fetching events: apollo.model.find.dberror: Error during find query on DB -> ResponseError: Unsupported order by relation. I am specifying k1 and k2 in the same order they are in my keyspace and also i checked that there are no spelling mistakes. So is there anything i am missing here??

Streaming in cassandra

Hey, I was just wondering how we would go about in doing a streaming query similar to the one in mongo.

Null error in apollo_schemer.js

While setting a cassandra timeuuid field, I get a null object error in apollo_schemer.js
events.js:85
throw er; // Unhandled 'error' event
^
TypeError: Cannot read property 'virtual' of null
at Object.schemer.normalize_model_schema (/express-cassandra/lib/orm/apollo_schemer.js:43:43)

My Model is:
module.exports = {
fields: {
"email" : {"type": "text"},
"id" : { "type": "timeuuid"},
"body" : {"type": "text"}
},
"key" : [["email"],"id"]
};

Upon investigating I realized that the output schema from lodash.clone in apollo_schemer.js was changing the id value to null. I was able to create a workaround fix by catching the null value and changing it back to timeuuid.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.