Skip to content

Commit

Permalink
fix: type coerce
Browse files Browse the repository at this point in the history
  • Loading branch information
jannyHou committed Jul 5, 2019
1 parent 3acf326 commit 3e12745
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
36 changes: 36 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_USER": "root",
"MYSQL_PASSWORD": "pass",
"MYSQL_PORT": 3307,
"MYSQL_DATABASE": "testdb"
},
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/index.js"
}
]
}
13 changes: 6 additions & 7 deletions lib/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ MySQL.prototype.fromColumnValue = function(prop, val) {
lat: val.y,
};
break;
case 'ObjectID':
val = new prop.type(val);
break;
case 'Buffer':
val = prop.type(val);
break;
case 'List':
case 'Array':
case 'Object':
Expand All @@ -453,13 +459,6 @@ MySQL.prototype.fromColumnValue = function(prop, val) {
}
break;
default:
if (!Array.isArray(prop.type) && !prop.type.modelName) {
// Do not convert array and model types
// In juggler 4.x, it requires `new prop.type(val)`,
// but it breaks the Enum factory, since it's not written
// in a Class flavor
val = new prop.type(val);
}
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/mysql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const List = require('loopback-datasource-juggler/lib/list');

var Post, PostWithStringId, PostWithUniqueTitle, PostWithNumId, Student, db;

// Mock up mongodb ObjectID
// // Mock up mongodb ObjectID
function ObjectID(id) {
if (!(this instanceof ObjectID)) {
return new ObjectID(id);
Expand Down

0 comments on commit 3e12745

Please sign in to comment.