New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cassandra-orm

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cassandra-orm - npm Package Compare versions

Comparing version 0.0.2 to 0.0.4

test/specs/accessors.js

4

lib/Connection.js

@@ -5,3 +5,3 @@ var helenus = require('helenus'),

var events = require('./index').events,
var cassandra = require('./index'),
CQLWriter = require('./CQLWriter');

@@ -19,3 +19,3 @@

this.client.on('error', function (error) {
events.emit('error', error);
cassandra.events.emit('error', error);
});

@@ -22,0 +22,0 @@

@@ -46,2 +46,3 @@ var Schema = require('./Schema');

def.createKeyspace = function (name, strategy, options) {

@@ -256,3 +257,2 @@ strategy = strategy || 'SimpleStrategy';

var schema = this.schema,
fields = this.tableFields(),
values = [],

@@ -262,7 +262,5 @@ names = [];

Object.keys(data).forEach(function (name) {
//if (fields[name]) {
names.push(this.escapeName(name));
names.push(this.escapeName(name));
values.push(schema.toDatabase(data[name], name));
//}
values.push(schema.toDatabase(data[name], name));
}.bind(this));

@@ -269,0 +267,0 @@

@@ -68,2 +68,3 @@ var async = require('async'),

if (fields[name]) {
// TODO: move this default code into Schema
if (fields[name].default !== undefined) {

@@ -93,3 +94,3 @@ if (schema.info.primaryKeys.indexOf(name) === -1) {

// TODO: validations
// TODO: validations, and setters
});

@@ -238,2 +239,13 @@

this.count = function (conds, limit, offset, callback, consistency) {
callback = callback || offset || limit;
offset = offset === callback ? undefined : offset;
limit = limit === callback ? undefined : limit;
return this.execute(this.cql.count(conds, limit, offset, consistency), function (err, rows) {
safeApply(callback, [err, err ? undefined : this.fromDatabase(rows, true)[0].count], this);
});
};
this.fromDatabase = function (rows, raw) {

@@ -244,5 +256,7 @@ var schema = this.schema;

return rows.map(function (row) {
if (!row) return null;
var results = [];
rows.forEach(function (row) {
if (!row || row.count === 0) return;
var data = {};

@@ -254,15 +268,6 @@

return raw ? data : new Model(data, true);
results.push(raw ? data : new Model(data, true));
});
};
this.count = function (conds, limit, offset, callback, consistency) {
callback = callback || offset || limit;
offset = offset === callback ? undefined : offset;
limit = limit === callback ? undefined : limit;
return this.execute(this.cql.count(conds, limit, offset, consistency), function (err, rows) {
safeApply(callback, [err, err ? undefined : this.fromDatabase(rows, true)[0].count], this);
});
return results;
};

@@ -368,3 +373,3 @@

// TODO: validations
// TODO: validation methods
});

@@ -25,8 +25,10 @@ var clss = require('clss');

return this.cleanFields();
return this.cleanFields(info.fields);
};
def.cleanFields = function (fields) {
fields = fields || this.info.fields;
if (!fields) return this;
var that = this;
Object.keys(fields).forEach(function (name) {

@@ -42,8 +44,8 @@ fields[name] = cleanField(fields[name]);

if (Array.isArray(field.type)) {
field = {type: Array, contains: field.type[0]};
field = {type: Array, contains: that.cleanFields(field.type[0])};
}
if (field.type && !field.type.name) field.type = {name: field.type};
if (typeof field.type === 'string') field.type = {name: field.type};
if (!field.type.name) delete fields[name];
else if (!field.type.name) that.cleanFields(field.type);

@@ -55,2 +57,4 @@ return field;

def.givePrimaryKeys = function () {
// TODO: this should work like defaults work in Model
if (typeof this.info.givePrimaryKeys === 'function') {

@@ -81,2 +85,4 @@ return this.info.givePrimaryKeys.apply(this, arguments);

def.fixDataType = function (typeName) {
// TODO: this should be moved to CQLWriter
switch (typeName) {

@@ -110,2 +116,4 @@ case 'UUID': return 'uuid';

def.toDatabase = function (value, name, fields) {
// TODO: maybe this should goto CQLWriter
fields = fields || this.info.fields;

@@ -120,3 +128,3 @@

if (!value.getTime) value = new Date(value);
return value.getUTCTime ? value.getUTCTime() : value.getTime();
return value.getTime();

@@ -126,2 +134,4 @@ case 'double': return value || 0;

case 'boolean': return !!value;
case 'text':

@@ -134,4 +144,2 @@ switch (field.type.name) {

}
//return "'" + JSON.stringify(value || '') + "'";
}

@@ -143,2 +151,4 @@

def.fromDatabase = function (value, name, fields) {
// TODO: maybe this should goto Model
fields = fields || this.info.fields;

@@ -150,6 +160,6 @@

switch (type) {
case 'timestamp': return new Date(value.toString().replace(/GMT.*$/, 'GMT'));
case 'timestamp': return new Date(value.toString());//.replace(/GMT.*$/, 'GMT'));
case 'uuid':
return value;
return value.toString();

@@ -164,11 +174,11 @@ case 'boolean':

}
//return JSON.parse(value);
}
try {
return JSON.parse(value);
} catch (err) {
return value;
}
value = JSON.parse(value);
} catch (err) {}
// TODO: getters
return value;
};

@@ -175,0 +185,0 @@ });

@@ -6,3 +6,3 @@ {

"license": "",
"version": "0.0.2",
"version": "0.0.4",
"repository": "",

@@ -19,3 +19,4 @@ "description": "",

"devDependencies": {
"spc": "0.0.2"
"spc": "0.0.3",
"require-stars": "0.0.1"
},

@@ -22,0 +23,0 @@ "scripts": {

@@ -0,9 +1,12 @@

require('require-stars')();
module.exports = require('spc').describe('Cassandra ORM:', function () {
var cassandra = require('../');
before(function (end) {
before(function () {
should();
});
before(function (end) {
this.options = {
keyspace: 'orm_test',
log: !true

@@ -15,3 +18,11 @@ };

after(function (end) {
beforeEach(function (end) {
cassandra.connection.execute('CREATE KEYSPACE orm_test;', function (err) {
if (err) return end(err);
cassandra.connection.execute('USE orm_test;', end);
});
})
afterEach(function (end) {
cassandra.connection.execute('DROP KEYSPACE orm_test;', function (err) {

@@ -24,12 +35,5 @@ if (err) return end(err);

add(
require('./crud'),
require('./datatypes'),
require('./relationships'),
require('./validations'),
require('./connection'),
require('./other')
);
add.apply(null, require('require-stars/flat')(require('./specs/**')));
});
require('spc/reporter/dot')(module.exports);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc