Skip to content

Commit 77b2c40

Browse files
aaqilnizdhmlau
authored andcommitted
fix: discover properties with json type
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
1 parent 3ae4b5e commit 77b2c40

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

lib/discovery.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ function mixinDiscovery(MySQL, mysql) {
382382
case 'BOOL':
383383
case 'BOOLEAN':
384384
return 'Boolean';
385+
case 'JSON':
386+
return 'object';
385387
case 'ENUM':
386388
return columnType;
387389
default:

test/mysql.discover.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,22 @@ describe('Discover and handle enum', function() {
299299
});
300300
});
301301

302+
describe('Discover models with JSON type columns', function() {
303+
let schema;
304+
before(function(done) {
305+
db.discoverSchema('INVENTORY', {owner: 'STRONGLOOP'}, function(err, schema_) {
306+
schema = schema_;
307+
done(err);
308+
});
309+
});
310+
it('should validate JSON as an object type for INVENTORY', function() {
311+
assert.ok(/STRONGLOOP/i.test(schema.options.mysql.schema));
312+
assert.strictEqual(schema.options.mysql.table, 'INVENTORY');
313+
assert.strictEqual(schema.name, 'Inventory');
314+
assert.strictEqual(schema.properties.details.type, 'object');
315+
});
316+
});
317+
302318
describe('Discover and build models', function() {
303319
let models;
304320
before(function(done) {

test/schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ CREATE TABLE `INVENTORY` (
7878
`LOCATION_ID` varchar(20) NOT NULL,
7979
`AVAILABLE` int(11) DEFAULT NULL,
8080
`TOTAL` int(11) DEFAULT NULL,
81+
`DETAILS` json DEFAULT NULL,
8182
`ACTIVE` BOOLEAN DEFAULT TRUE,
8283
`DISABLED` BIT(1) DEFAULT 0,
8384
`ENABLED` CHAR(1) DEFAULT 'Y',

0 commit comments

Comments
 (0)