Merge pull request #23 from strongloop/feature/fix-issue-22
Fix the query for discovery with current user
This commit is contained in:
commit
296065d7fb
|
@ -35,7 +35,7 @@ function mixinDiscovery(MySQL) {
|
||||||
+ ' FROM information_schema.tables WHERE table_schema=\'' + owner + '\'', 'table_schema, table_name', options);
|
+ ' FROM information_schema.tables WHERE table_schema=\'' + owner + '\'', 'table_schema, table_name', options);
|
||||||
} else {
|
} else {
|
||||||
sqlTables = paginateSQL('SELECT \'table\' AS "type", table_name AS "name",'
|
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);
|
'table_name', options);
|
||||||
}
|
}
|
||||||
return sqlTables;
|
return sqlTables;
|
||||||
|
|
|
@ -3,10 +3,10 @@ require('should');
|
||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var DataSource = require('loopback-datasource-juggler').DataSource;
|
var DataSource = require('loopback-datasource-juggler').DataSource;
|
||||||
var db;
|
var db, config;
|
||||||
|
|
||||||
before(function () {
|
before(function () {
|
||||||
var config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
|
config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
|
||||||
config.database = 'STRONGLOOP';
|
config.database = 'STRONGLOOP';
|
||||||
db = new DataSource(require('../'), config);
|
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 () {
|
describe('Discover models excluding views', function () {
|
||||||
it('should return an array of only tables', function (done) {
|
it('should return an array of only tables', function (done) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue