不要怂,就是干,撸起袖子干!

Commit 7ccbb1ea by Sushant Committed by GitHub

fix(query-interface): reject with error for describeTable (#10528)

1 parent 454cf48e
...@@ -466,18 +466,25 @@ class QueryInterface { ...@@ -466,18 +466,25 @@ class QueryInterface {
} }
const sql = this.QueryGenerator.describeTableQuery(tableName, schema, schemaDelimiter); const sql = this.QueryGenerator.describeTableQuery(tableName, schema, schemaDelimiter);
options = Object.assign({}, options, { type: QueryTypes.DESCRIBE });
return this.sequelize.query( return this.sequelize.query(sql, options).then(data => {
sql, /*
Object.assign({}, options, { type: QueryTypes.DESCRIBE }) * If no data is returned from the query, then the table name may be wrong.
).then(data => { * Query generators that use information_schema for retrieving table info will just return an empty result set,
// If no data is returned from the query, then the table name may be wrong. * it will not throw an error like built-ins do (e.g. DESCRIBE on MySql).
// Query generators that use information_schema for retrieving table info will just return an empty result set, */
// it will not throw an error like built-ins do (e.g. DESCRIBE on MySql).
if (_.isEmpty(data)) { if (_.isEmpty(data)) {
return Promise.reject(`No description found for "${tableName}" table. Check the table name and schema; remember, they _are_ case sensitive.`); throw new Error(`No description found for "${tableName}" table. Check the table name and schema; remember, they _are_ case sensitive.`);
} }
return data; return data;
}).catch(e => {
if (e.original && e.original.code === 'ER_NO_SUCH_TABLE') {
throw Error(`No description found for "${tableName}" table. Check the table name and schema; remember, they _are_ case sensitive.`);
}
throw e;
}); });
} }
......
...@@ -17,7 +17,6 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => { ...@@ -17,7 +17,6 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
}); });
describe('describeTable', () => { describe('describeTable', () => {
if (Support.sequelize.dialect.supports.schemas) { if (Support.sequelize.dialect.supports.schemas) {
it('reads the metadata of the table with schema', function() { it('reads the metadata of the table with schema', function() {
const MyTable1 = this.sequelize.define('my_table', { const MyTable1 = this.sequelize.define('my_table', {
...@@ -51,6 +50,12 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => { ...@@ -51,6 +50,12 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => {
}); });
} }
it('rejects when no data is available', function() {
return expect(
this.queryInterface.describeTable('_some_random_missing_table')
).to.be.rejectedWith('No description found for "_some_random_missing_table" table. Check the table name and schema; remember, they _are_ case sensitive.');
});
it('reads the metadata of the table', function() { it('reads the metadata of the table', function() {
const Users = this.sequelize.define('_Users', { const Users = this.sequelize.define('_Users', {
username: DataTypes.STRING, username: DataTypes.STRING,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!