simple-redis-model
Advanced tools
Comparing version
var assert = require('assert') | ||
// Converts camelCase and PascalCase to underscore_case | ||
var snakecaseString = function(str) { | ||
var uStr = str.substr(0,1).toLowerCase() + str.substr(1,str.length) | ||
return uStr.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase()}) | ||
} | ||
// params: | ||
@@ -10,2 +16,3 @@ // modelName: string describing the Model's name | ||
this.modelName = modelName | ||
this.modelNameCased = snakecaseString(modelName) | ||
this.attrs = (attrs instanceof Array) ? attrs : new Array() | ||
@@ -19,2 +26,3 @@ return this | ||
obj.id | ||
obj.modelName = this.modelName | ||
for(var a in attrs) obj[a] = attrs[a] | ||
@@ -25,6 +33,6 @@ return obj | ||
// Database Operations | ||
nextIdKey: function() { return "next" + this.modelName + "" }, | ||
idKey: function(id) { return this.modelName + "_" + "id:" + id }, | ||
nextIdKey: function() { return "next" + this.modelNameCased + "" }, | ||
idKey: function(id) { return this.modelNameCased + ":" + id }, | ||
idKeyForAttribute: function(id, attr) { return this.idKey(id) + ":" + attr }, | ||
modelCollectionKey: function(){ return this.modelName + "_ids" }, | ||
modelCollectionKey: function(){ return this.modelNameCased + "_ids" }, | ||
@@ -31,0 +39,0 @@ save: function(obj, callback){ |
{ | ||
"name": "simple-redis-model", | ||
"version": "0.1.1", | ||
"version": "0.1.3", | ||
"description": "Simple Redis ORM for Node.js.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/simple-redis-model.js", |
@@ -68,2 +68,6 @@ var chai = require('chai'), | ||
it("should have a modelName", function(){ | ||
customObj.modelName.should.eq("CustomModel") | ||
}) | ||
it("should instantiate without the attrs", function(){ | ||
@@ -113,3 +117,3 @@ customObj.should.not.have.ownProperty(attr1) | ||
it(".save() returns the object_id", function(){ | ||
objID.should.eq("CustomModel_id:1") | ||
objID.should.eq("custom_model:1") | ||
}) | ||
@@ -116,0 +120,0 @@ |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
8407
39.54%6
20%184
5.75%1
-50%66
Infinity%