Skip to content

Commit bbda55f

Browse files
committed
feat: add query builder to determine strict mode
Signed-off-by: Muhammad Aaqil <[email protected]>
1 parent 858adf3 commit bbda55f

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/discovery.js

+9
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ function mixinDiscovery(MySQL, mysql) {
298298
return sql;
299299
};
300300

301+
/**
302+
* Build query to determine is strict mode
303+
*/
304+
305+
MySQL.prototype.buildQueryIsStrict = function() {
306+
return 'SELECT @@GLOBAL.sql_mode LIKE \'%STRICT%\' AS globalStrictMode,' +
307+
'@@SESSION.sql_mode LIKE \'%STRICT%\' AS sessionStrictMode;';
308+
};
309+
301310
/**
302311
* Discover foreign keys that reference to the primary key of this table
303312
* @param {String} table The table name

test/mysql.discover.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ describe('Discover LDL schema from a table', function() {
257257
});
258258
});
259259

260+
describe('Discover schema with strict mode on', function() {
261+
let schema;
262+
before(function(done) {
263+
db.discoverSchema('INVENTORY', {owner: 'STRONGLOOP'}, function(err, schema_) {
264+
schema = schema_;
265+
done(err);
266+
});
267+
});
268+
it('should return an LDL schema for INVENTORY with strict mode on', function() {
269+
assert.strictEqual(schema.name, 'Inventory');
270+
if (schema.properties.length) {
271+
assert.strictEqual(schema.properties.jsonSchema.maxLength, schema.properties.length);
272+
}
273+
});
274+
});
275+
260276
describe('Discover and handle enum', function() {
261277
let schema;
262278
before(function(done) {

test/schema.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `STRONGLOOP` /*!40100 DEFAULT CHARACTER SET utf8 */;
2525

2626
USE `STRONGLOOP`;
27-
27+
SET GLOBAL sql_mode = 'STRICT_ALL_TABLES';
2828
--
2929
-- Table structure for table `CUSTOMER`
3030
--

0 commit comments

Comments
 (0)