express-cassandra
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1580,2 +1580,11 @@ var util = require('util'), | ||
BaseModel.prototype.toJSON = function toJSON() { | ||
var object = {}; | ||
var schema = this.constructor._properties.schema; | ||
for(var field in schema.fields) { | ||
object[field] = this[field]; | ||
} | ||
return object; | ||
}; | ||
module.exports = BaseModel; |
{ | ||
"name": "express-cassandra", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "async": "^1.0.0", |
@@ -821,2 +821,4 @@ [![Build Status](https://travis-ci.org/masumsoft/express-cassandra.svg)](https://travis-ci.org/masumsoft/express-cassandra) | ||
Note that, result objects here in callback will be model instances. So you may do operations like `john.save`, `john.delete` etc on the result object directly. If you want to extract the raw javascript object values from a model instance, you may use the toJSON method like `john.toJSON()`. | ||
In the above example it will perform the query `SELECT * FROM person WHERE name='john'` but `find()` allows you to perform even more complex queries on cassandra. You should be aware of how to query cassandra. Every error will be reported to you in the `err` argument, while in `people` you'll find instances of `Person`. | ||
@@ -823,0 +825,0 @@ |
@@ -922,2 +922,33 @@ var models = require('../index'); | ||
describe('#toJSON returns object with model fields only',function(){ | ||
it('should return the object for new model instance', function() { | ||
var simple = new models.instance.Simple({foo:"bar"}); | ||
simple.toJSON().should.deep.eq({ | ||
foo: "bar", | ||
bar: "baz" | ||
}); | ||
JSON.stringify(simple).should.eq('{"foo":"bar","bar":"baz"}'); | ||
should.exist(simple._validators); | ||
}); | ||
it('should return the object for fetched model', function(done) { | ||
var simple = new models.instance.Simple({foo:"bar"}); | ||
simple.save(function save(err){ | ||
if(err) throw err; | ||
models.instance.Simple.findOne({}, function findOne(err, simpleModel){ | ||
simpleModel.toJSON().should.deep.eq({ | ||
foo: "bar", | ||
bar: "baz" | ||
}); | ||
JSON.stringify(simpleModel).should.eq('{"foo":"bar","bar":"baz"}'); | ||
should.exist(simpleModel._validators); | ||
simpleModel.delete(function del(err){ | ||
if(err) throw err; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('#close cassandra connection',function(){ | ||
@@ -924,0 +955,0 @@ it('should close connection to cassandra without errors', function(done) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
218442
17
3615
1303