From 77b2c401f809b328110c5d2257f9687e87e3335d Mon Sep 17 00:00:00 2001 From: Muhammad Aaqil Date: Tue, 21 May 2024 15:51:45 +0500 Subject: [PATCH] fix: discover properties with json type Signed-off-by: Muhammad Aaqil --- lib/discovery.js | 2 ++ test/mysql.discover.test.js | 16 ++++++++++++++++ test/schema.sql | 1 + 3 files changed, 19 insertions(+) diff --git a/lib/discovery.js b/lib/discovery.js index f5b4d435..6c53216b 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -382,6 +382,8 @@ function mixinDiscovery(MySQL, mysql) { case 'BOOL': case 'BOOLEAN': return 'Boolean'; + case 'JSON': + return 'object'; case 'ENUM': return columnType; default: diff --git a/test/mysql.discover.test.js b/test/mysql.discover.test.js index f2bcd4ac..9da8060e 100644 --- a/test/mysql.discover.test.js +++ b/test/mysql.discover.test.js @@ -299,6 +299,22 @@ describe('Discover and handle enum', function() { }); }); +describe('Discover models with JSON type columns', function() { + let schema; + before(function(done) { + db.discoverSchema('INVENTORY', {owner: 'STRONGLOOP'}, function(err, schema_) { + schema = schema_; + done(err); + }); + }); + it('should validate JSON as an object type for INVENTORY', function() { + assert.ok(/STRONGLOOP/i.test(schema.options.mysql.schema)); + assert.strictEqual(schema.options.mysql.table, 'INVENTORY'); + assert.strictEqual(schema.name, 'Inventory'); + assert.strictEqual(schema.properties.details.type, 'object'); + }); +}); + describe('Discover and build models', function() { let models; before(function(done) { diff --git a/test/schema.sql b/test/schema.sql index 589b3d1b..f80ff03e 100644 --- a/test/schema.sql +++ b/test/schema.sql @@ -78,6 +78,7 @@ CREATE TABLE `INVENTORY` ( `LOCATION_ID` varchar(20) NOT NULL, `AVAILABLE` int(11) DEFAULT NULL, `TOTAL` int(11) DEFAULT NULL, + `DETAILS` json DEFAULT NULL, `ACTIVE` BOOLEAN DEFAULT TRUE, `DISABLED` BIT(1) DEFAULT 0, `ENABLED` CHAR(1) DEFAULT 'Y',