* https://github.com/jugglingdb/mysql-adapter: Update README.md Fixed typo in the require statement 0.0.1-6 Add checking for undefined in buildWhere Fix injection
This commit is contained in:
commit
b04d9466ef
42
README.md
42
README.md
|
@ -22,7 +22,7 @@ To use it you need `jugglingdb@0.2.x`.
|
||||||
2. Use:
|
2. Use:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
var Schema = require('jugglingbd').Schema;
|
var Schema = require('jugglingdb').Schema;
|
||||||
var schema = new Schema('mysql', {
|
var schema = new Schema('mysql', {
|
||||||
database: 'myapp_test',
|
database: 'myapp_test',
|
||||||
username: 'root'
|
username: 'root'
|
||||||
|
@ -33,6 +33,46 @@ To use it you need `jugglingdb@0.2.x`.
|
||||||
|
|
||||||
npm test
|
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
|
## MIT License
|
||||||
|
|
||||||
```text
|
```text
|
||||||
|
|
|
@ -196,7 +196,7 @@ MySQL.prototype.toDatabase = function (prop, val) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!prop) return 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 (prop.type.name === 'Date') {
|
||||||
if (!val) return 'NULL';
|
if (!val) return 'NULL';
|
||||||
if (!val.toUTCString) {
|
if (!val.toUTCString) {
|
||||||
|
@ -279,9 +279,9 @@ MySQL.prototype.all = function all(model, filter, callback) {
|
||||||
Object.keys(conds).forEach(function (key) {
|
Object.keys(conds).forEach(function (key) {
|
||||||
var keyEscaped = '`' + key.replace(/\./g, '`.`') + '`'
|
var keyEscaped = '`' + key.replace(/\./g, '`.`') + '`'
|
||||||
var val = self.toDatabase(props[key], conds[key]);
|
var val = self.toDatabase(props[key], conds[key]);
|
||||||
if (conds[key] === null) {
|
if (conds[key] === null || conds[key] === undefined) {
|
||||||
cs.push(keyEscaped + ' IS NULL');
|
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 condType = Object.keys(conds[key])[0];
|
||||||
var sqlCond = keyEscaped;
|
var sqlCond = keyEscaped;
|
||||||
if ((condType == 'inq' || condType == 'nin') && val.length == 0) {
|
if ((condType == 'inq' || condType == 'nin') && val.length == 0) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "jugglingdb-mysql",
|
"name": "jugglingdb-mysql",
|
||||||
"version": "0.0.1-5",
|
"version": "0.0.1-6",
|
||||||
"description": "MySQL adapter for JugglingDB",
|
"description": "MySQL adapter for JugglingDB",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in New Issue