Skip to content

Commit

Permalink
fix: misc
Browse files Browse the repository at this point in the history
  • Loading branch information
aaqilniz committed Apr 14, 2024
1 parent a3cfe01 commit 0cce059
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,15 @@ function mixinDiscovery(MySQL, mysql) {
return sql;
};

/**
* Build query to determine is strict mode
*/

MySQL.prototype.buildQueryIsStrict = function() {
return 'SELECT @@GLOBAL.sql_mode LIKE \'%STRICT%\' AS globalStrictMode,' +
'@@SESSION.sql_mode LIKE \'%STRICT%\' AS sessionStrictMode;';
};

/**
* Discover foreign keys that reference to the primary key of this table
* @param {String} table The table name
Expand Down
23 changes: 23 additions & 0 deletions test/mysql.discover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'use strict';
process.env.NODE_ENV = 'test';
const should = require('should');
const async = require('async');

const assert = require('assert');
const DataSource = require('loopback-datasource-juggler').DataSource;
Expand Down Expand Up @@ -542,3 +543,25 @@ describe('Discover and build models', function() {
});
});
});

describe('Discover schema with strict mode on', function() {
let schema;
before(function(done) {
async.series([
db.execute('SET GLOBAL sql_mode = \'STRICT_ALL_TABLES\';'),
db.discoverSchema('INVENTORY', {owner: 'STRONGLOOP'}, function(err, schema_) {
schema = schema_;
done(err);
}),
]);
});
it('should return an LDL schema for INVENTORY with strict mode on', function() {
assert.strictEqual(schema.name, 'Inventory');
Object.keys(schema.properties).forEach(property => {
if (schema.properties.length) {
assert.strictEqual(property.jsonSchema.maxLength, property.length);
}
});
async.series([db.execute('SET GLOBAL sql_mode = \'\';')]);
});
});

0 comments on commit 0cce059

Please sign in to comment.