From 400614a8c961c086b66418aa296178abb7ed27bf Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Thu, 18 Apr 2013 22:58:21 +0400 Subject: [PATCH 1/5] Fix injection --- lib/mysql.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mysql.js b/lib/mysql.js index 01b2ad5..2f09bec 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -178,7 +178,7 @@ MySQL.prototype.toDatabase = function (prop, val) { } } if (!prop) return val; - if (prop.type.name === 'Number') return val; + if (prop.type.name === 'Number') return Number(val); if (prop.type.name === 'Date') { if (!val) return 'NULL'; if (!val.toUTCString) { From 6c5666e23e4fd979ac7427ae69f6dcbec3c8d3ef Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Mon, 22 Apr 2013 08:40:12 +0400 Subject: [PATCH 2/5] Add checking for undefined in buildWhere --- lib/mysql.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mysql.js b/lib/mysql.js index 2f09bec..5cc6e3f 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -261,9 +261,9 @@ MySQL.prototype.all = function all(model, filter, callback) { Object.keys(conds).forEach(function (key) { var keyEscaped = '`' + key.replace(/\./g, '`.`') + '`' var val = self.toDatabase(props[key], conds[key]); - if (conds[key] === null) { + if (conds[key] === null || conds[key] === undefined) { cs.push(keyEscaped + ' IS NULL'); - } else if (conds[key].constructor.name === 'Object') { + } else if (conds[key] && conds[key].constructor.name === 'Object') { var condType = Object.keys(conds[key])[0]; var sqlCond = keyEscaped; if ((condType == 'inq' || condType == 'nin') && val.length == 0) { From 4612ba275d2dfd2d854287aec1560914f419e8df Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Mon, 22 Apr 2013 08:41:41 +0400 Subject: [PATCH 3/5] 0.0.1-6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ba4d17..f70fa46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jugglingdb-mysql", - "version": "0.0.1-5", + "version": "0.0.1-6", "description": "MySQL adapter for JugglingDB", "main": "index.js", "scripts": { From efb82378190a78c5796918edf38598a3bf091020 Mon Sep 17 00:00:00 2001 From: Fabien Allanic Date: Tue, 30 Apr 2013 11:04:57 -0700 Subject: [PATCH 4/5] Fixed typo in the require statement --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c69cd2a..8446daa 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ To use it you need `jugglingdb@0.2.x`. 2. Use: ```javascript - var Schema = require('jugglingbd').Schema; + var Schema = require('jugglingdb').Schema; var schema = new Schema('mysql', { database: 'myapp_test', username: 'root' From 87bf863a0a1872d200468b0230111cedeebccea2 Mon Sep 17 00:00:00 2001 From: dgsan Date: Thu, 6 Jun 2013 12:25:20 -0600 Subject: [PATCH 5/5] Update README.md Some initial documentation of `dataType` usage. --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/README.md b/README.md index 8446daa..60a0687 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,46 @@ To use it you need `jugglingdb@0.2.x`. ## Running tests npm test + +## Using the `dataType` field/column option with MySQL + +The jugglingdb MySQL adapter now supports using the `dataType` column/property attribute to specify what MySQL column type is used for many jugglingdb types. + +The following type-dataType combinations are supported (incomplete): +* Number + * integer types + * tinyint + * smallint + * mediumint + * int + * bigint + * use the 'limit' option to alter the display width + * example: + `{ count : { type: Number, dataType: 'smallInt' }}` + * floating point types + * float + * double + * use the `precision` and `scale` options to specify custom precision. Default is (16,8). + * example: + `{ average : { type: Number, dataType: 'float', precision: 20, scale: 4 }}` + * fixed-point exact value types + * decimal + * numeric + * use the `precision` and `scale` options to specify custom precision. Default is (9,2). + * these aren't likely to function as true fixed-point. + * example: + `{ stdDev : { type: Number, dataType: 'decimal', precision: 12, scale: 8 }}` +* String / Schema.Text / Schema.JSON + * varchar + * char + * text + * mediumtext + * tinytext + * longtext +* Date + * datetime + * timestamp + ## MIT License