Skip to content

Commit

Permalink
fix: discover properties with json type
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
  • Loading branch information
aaqilniz authored and dhmlau committed May 23, 2024
1 parent 3ae4b5e commit 77b2c40
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ function mixinDiscovery(MySQL, mysql) {
case 'BOOL':
case 'BOOLEAN':
return 'Boolean';
case 'JSON':
return 'object';
case 'ENUM':
return columnType;
default:
Expand Down
16 changes: 16 additions & 0 deletions test/mysql.discover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions test/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 77b2c40

Please sign in to comment.