Fix the query for discovery with current user

See https://github.com/strongloop/loopback-connector-mysql/issues/22
This commit is contained in:
Raymond Feng 2014-04-08 08:35:39 -07:00
parent f6a370921d
commit b0f636a4c4
2 changed files with 23 additions and 3 deletions

View File

@ -35,7 +35,7 @@ function mixinDiscovery(MySQL) {
+ ' FROM information_schema.tables WHERE table_schema=\'' + owner + '\'', 'table_schema, table_name', options);
} else {
sqlTables = paginateSQL('SELECT \'table\' AS "type", table_name AS "name",'
+ ' table_schema AS "owner" FROM information_schema.tables',
+ ' table_schema AS "owner" FROM information_schema.tables WHERE table_schema=SUBSTRING_INDEX(USER(),\'@\',1)',
'table_name', options);
}
return sqlTables;

View File

@ -3,10 +3,10 @@ require('should');
var assert = require('assert');
var DataSource = require('loopback-datasource-juggler').DataSource;
var db;
var db, config;
before(function () {
var config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
config.database = 'STRONGLOOP';
db = new DataSource(require('../'), config);
});
@ -37,6 +37,26 @@ describe('discoverModels', function () {
});
});
describe('Discover current user\'s tables', function () {
it('should return an array of tables for the current user', function (done) {
db.discoverModelDefinitions({
limit: 3
}, function (err, models) {
if (err) {
console.error(err);
done(err);
} else {
var views = false;
models.forEach(function (m) {
assert.equal(m.owner, config.username);
});
done(null, models);
}
});
});
});
describe('Discover models excluding views', function () {
it('should return an array of only tables', function (done) {