Skip to content

Commit 0cce059

Browse files
committed
fix: misc
1 parent a3cfe01 commit 0cce059

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
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

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'use strict';
77
process.env.NODE_ENV = 'test';
88
const should = require('should');
9+
const async = require('async');
910

1011
const assert = require('assert');
1112
const DataSource = require('loopback-datasource-juggler').DataSource;
@@ -542,3 +543,25 @@ describe('Discover and build models', function() {
542543
});
543544
});
544545
});
546+
547+
describe('Discover schema with strict mode on', function() {
548+
let schema;
549+
before(function(done) {
550+
async.series([
551+
db.execute('SET GLOBAL sql_mode = \'STRICT_ALL_TABLES\';'),
552+
db.discoverSchema('INVENTORY', {owner: 'STRONGLOOP'}, function(err, schema_) {
553+
schema = schema_;
554+
done(err);
555+
}),
556+
]);
557+
});
558+
it('should return an LDL schema for INVENTORY with strict mode on', function() {
559+
assert.strictEqual(schema.name, 'Inventory');
560+
Object.keys(schema.properties).forEach(property => {
561+
if (schema.properties.length) {
562+
assert.strictEqual(property.jsonSchema.maxLength, property.length);
563+
}
564+
});
565+
async.series([db.execute('SET GLOBAL sql_mode = \'\';')]);
566+
});
567+
});

0 commit comments

Comments
 (0)