Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 7ccbb1ea
authored
Mar 09, 2019
by
Sushant
Committed by
GitHub
Mar 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(query-interface): reject with error for describeTable (#10528)
1 parent
454cf48e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
9 deletions
lib/query-interface.js
test/integration/query-interface/describeTable.test.js
lib/query-interface.js
View file @
7ccbb1e
...
@@ -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
;
});
});
}
}
...
...
test/integration/query-interface/describeTable.test.js
View file @
7ccbb1e
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment