fix: misc

Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
This commit is contained in:
Muhammad Aaqil 2024-04-14 11:01:11 +05:00
parent a3cfe01ec8
commit 26608c89e2
2 changed files with 32 additions and 0 deletions

View File

@ -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

View File

@ -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;
@ -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 = \'\';')]);
});
});