From a34d277ef8ae1ab8a4beea6af8436891dd7caaa9 Mon Sep 17 00:00:00 2001 From: "Amir M. Mahmoudi" Date: Sat, 4 Feb 2012 14:55:07 +0330 Subject: [PATCH 1/5] Add some features to advanced queries --- lib/adapters/mysql.js | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/adapters/mysql.js b/lib/adapters/mysql.js index 5f66b195..d25d771a 100644 --- a/lib/adapters/mysql.js +++ b/lib/adapters/mysql.js @@ -104,7 +104,13 @@ MySQL.prototype.toDatabase = function (prop, val) { return this.toDatabase(prop, val[0]) + ' AND ' + this.toDatabase(prop, val[1]); - } + } else if (operator == 'inq' || operator == 'nin') { + if (!(val.propertyIsEnumerable('length')) && typeof val === 'object' && typeof val.length === 'number') { //if value is array + return val.join(','); + } else { + return val; + } + } } if (prop.type.name === 'Number') return val; if (prop.type.name === 'Date') { @@ -205,22 +211,31 @@ MySQL.prototype.all = function all(model, filter, callback) { var sqlCond = keyEscaped; switch (condType) { case 'gt': - sqlCond += ' > '; - break; + sqlCond += ' > '; + break; case 'gte': - sqlCond += ' >= '; - break; + sqlCond += ' >= '; + break; case 'lt': - sqlCond += ' < '; - break; + sqlCond += ' < '; + break; case 'lte': - sqlCond += ' <= '; - break; + sqlCond += ' <= '; + break; case 'between': - sqlCond += ' BETWEEN '; - break; + sqlCond += ' BETWEEN '; + break; + case 'inq': + sqlCond += ' IN '; + break; + case 'nin': + sqlCond += ' NOT IN '; + break; + case 'neq': + sqlCond + ' != '; + break; } - sqlCond += val; + sqlCond += (condType == 'inq' || condType == 'nin') ? '(' + val + ')' : val; cs.push(sqlCond); } else { cs.push(keyEscaped + ' = ' + val); From 5547a3acbe75eb36518b7c1e0a9d4d3773362233 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Fri, 3 Feb 2012 04:15:01 +0800 Subject: [PATCH 2/5] Add alias for skip/offet (mongoose) --- lib/adapters/mongoose.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/adapters/mongoose.js b/lib/adapters/mongoose.js index 8c83df43..0f4f69d9 100644 --- a/lib/adapters/mongoose.js +++ b/lib/adapters/mongoose.js @@ -145,6 +145,8 @@ MongooseAdapter.prototype.all = function all(model, filter, callback) { } if (filter.skip) { query.skip(filter.skip); + } else if (filter.offset) { + query.skip(filter.offset); } query.exec(function (err, data) { if (err) return callback(err); From a23e3b66e69218ec15cce99de73c50964db02002 Mon Sep 17 00:00:00 2001 From: Shunsuke Watanabe Date: Sat, 4 Feb 2012 21:25:39 +0800 Subject: [PATCH 3/5] modify README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f87096e2..dbaa20f8 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Feel free to vote and comment on cards (tickets/issues), if you want to join tea ```javascript var Schema = require('./jugglingdb').Schema; -var s = new Schema('redis'); +var schema = new Schema('redis', {port: 6379}); //port number depends on your configuration // define models var Post = schema.define('Post', { title: { type: String, length: 255 }, @@ -48,7 +48,7 @@ Post.belongsTo(User, {as: 'author', foreignKey: 'userId'}); // post.author() -- sync getter when called without params // post.author(user) -- setter when called with object -s.automigrate(); // required only for mysql NOTE: it will drop User and Post tables +schema.automigrate(); // required only for mysql NOTE: it will drop User and Post tables // work with models: var user = new User; From 04cbad35fdcf2bcf3c609d0edbd9b08f20fe650e Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Sat, 4 Feb 2012 22:17:27 +0800 Subject: [PATCH 4/5] Remove unnecesare code from test helper --- package.json | 2 +- test/spec_helper.js | 22 ---------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/package.json b/package.json index 76f2c4c5..fb12162d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jugglingdb", "author": "Anatoliy Chakkaev", "description": "ORM for every database: redis, mysql, neo4j, mongodb, postgres, sqlite", - "version": "0.0.8", + "version": "0.1.0", "repository": { "url": "https://github.com/1602/jugglingdb" }, diff --git a/test/spec_helper.js b/test/spec_helper.js index e103306c..5e02b7f0 100644 --- a/test/spec_helper.js +++ b/test/spec_helper.js @@ -46,25 +46,3 @@ function check_external_exports() { 'require("spec_helper").init(exports); called'); } -// add assertions - -var assert = require(require('module')._resolveFilename('../support/nodeunit')[0].replace(/index\.js$/, 'lib/assert')); - -// Check response status code 200 OK -assert.status200 = function (response, message) { - if (response.statusCode !== 200) { - assert.fail(response.statusCode, 200, message || 'Status code is not 200', '===', assert.status200); - } -} - -// Check redirection -assert.redirect = function (response, path, message) { - if (response.statusCode !== 302) { - assert.fail(response.statusCode, 302, 'Status code is not 302', '===', assert.redirect); - } - var realPath = require('url').parse(response.headers.location).pathname; - if (realPath !== path) { - assert.fail(realPath, path, message || 'Wrong location', '===', assert.redirect); - } -} - From 7569a923c811364dedf14848b0d4eab5cbd0448a Mon Sep 17 00:00:00 2001 From: "Amir M. Mahmoudi" Date: Mon, 6 Feb 2012 22:22:13 +0330 Subject: [PATCH 5/5] Fixing some bugs, which fix default values and length of fields in mysql adapter --- lib/adapters/mysql.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/adapters/mysql.js b/lib/adapters/mysql.js index d25d771a..064c7997 100644 --- a/lib/adapters/mysql.js +++ b/lib/adapters/mysql.js @@ -105,7 +105,7 @@ MySQL.prototype.toDatabase = function (prop, val) { ' AND ' + this.toDatabase(prop, val[1]); } else if (operator == 'inq' || operator == 'nin') { - if (!(val.propertyIsEnumerable('length')) && typeof val === 'object' && typeof val.length === 'number') { //if value is array + if (!(val.propertyIsEnumerable('length')) && typeof val === 'object' && typeof val.length === 'number') { //if value is array return val.join(','); } else { return val; @@ -413,17 +413,24 @@ MySQL.prototype.propertySettingsSQL = function (model, prop) { }; function datatype(p) { + var dt = ''; switch (p.type.name) { case 'String': - return 'VARCHAR(' + (p.limit || 255) + ')'; + dt = 'VARCHAR(' + (p.limit || 255) + ')'; + break; case 'Text': - return 'TEXT'; + dt = 'TEXT'; + break; case 'Number': - return 'INT(11)'; + dt = 'INT(' + (p.limit || 11) + ')'; + break; case 'Date': - return 'DATETIME'; + dt = 'DATETIME'; + break; case 'Boolean': - return 'TINYINT(1)'; - } -} - + dt = 'TINYINT(1)'; + break; + } + dt += (typeof p.default !== 'undefined') ? ' DEFAULT ' + p.default.toString() : ''; + return dt; +} \ No newline at end of file