Skip to content

Commit

Permalink
feat: add query builder to determine strict mode
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Aaqil <[email protected]>
  • Loading branch information
aaqilniz committed Apr 13, 2024
1 parent 858adf3 commit cfccab3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
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
16 changes: 16 additions & 0 deletions test/mysql.discover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ describe('Discover LDL schema from a table', function() {
});
});

describe('Discover schema with strict mode on', function() {
let schema;
before(function(done) {
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');
if(schema.properties.length) {
assert.strictEqual(schema.properties.jsonSchema.maxLength, schema.properties.length);
}
});
});

describe('Discover and handle enum', function() {
let schema;
before(function(done) {
Expand Down
2 changes: 1 addition & 1 deletion test/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `STRONGLOOP` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `STRONGLOOP`;

SET GLOBAL sql_mode = 'STRICT_ALL_TABLES';
--
-- Table structure for table `CUSTOMER`
--
Expand Down

0 comments on commit cfccab3

Please sign in to comment.