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 fe301789
authored
Jul 26, 2015
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(describeTable) Detect primary key in describe table. Reroll of #3703
1 parent
538a095e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
23 additions
and
7 deletions
changelog.md
lib/dialects/mssql/query-generator.js
lib/dialects/mssql/query.js
lib/dialects/mysql/query.js
lib/dialects/postgres/query-generator.js
lib/dialects/postgres/query.js
test/integration/query-interface.test.js
changelog.md
View file @
fe30178
...
...
@@ -7,6 +7,7 @@
-
[
FIXED
]
Calling
`validateIncludedElements`
should not add an aliassed primary key multiple times
[
#4127
](
https://github.com/sequelize/sequelize/issues/4127
)
-
[
FEATURE
]
`addScope`
[
#3963
](
https://github.com/sequelize/sequelize/issues/3963
)
-
[
FIXED
]
Handle scoped model in includes properly
[
#3700
](
https://github.com/sequelize/sequelize/issues/3700
)
-
[
FEATURE
]
`describeTable`
now marks the primary key (Reroll of
[
#3703
](
https://github.com/sequelize/sequelize/pull/3703
)
)
# 3.4.1
-
[
FIXED
]
Fix belongs-to-many
`countAssociations`
- ambigious id when through model has id
...
...
lib/dialects/mssql/query-generator.js
View file @
fe30178
...
...
@@ -109,11 +109,16 @@ var QueryGenerator = {
"c.COLUMN_NAME AS 'Name',"
,
"c.DATA_TYPE AS 'Type',"
,
"c.IS_NULLABLE as 'IsNull',"
,
"COLUMN_DEFAULT AS 'Default'"
,
"COLUMN_DEFAULT AS 'Default',"
,
"tc.CONSTRAINT_TYPE AS 'Constraint'"
,
'FROM'
,
'INFORMATION_SCHEMA.TABLES t'
,
'INNER JOIN'
,
'INFORMATION_SCHEMA.COLUMNS c ON t.TABLE_NAME = c.TABLE_NAME'
,
'LEFT JOIN'
,
'INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu ON t.TABLE_NAME = cu.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME'
,
'LEFT JOIN'
,
'INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc ON t.TABLE_NAME = tc.TABLE_NAME AND cu.COLUMN_NAME = c.COLUMN_NAME AND tc.CONSTRAINT_TYPE = \'PRIMARY KEY\''
,
'WHERE t.TABLE_NAME ='
,
wrapSingleQuote
(
tableName
)
].
join
(
' '
);
...
...
lib/dialects/mssql/query.js
View file @
fe30178
...
...
@@ -125,13 +125,15 @@ Query.prototype.formatResults = function(data) {
}
else
if
(
this
.
isDescribeQuery
())
{
result
=
{};
data
.
forEach
(
function
(
_result
)
{
if
(
_result
.
Default
)
if
(
_result
.
Default
)
{
_result
.
Default
=
_result
.
Default
.
replace
(
"('"
,
''
).
replace
(
"')"
,
''
).
replace
(
/'/g
,
''
);
/* jshint ignore: line */
}
result
[
_result
.
Name
]
=
{
type
:
_result
.
Type
.
toUpperCase
(),
allowNull
:
(
_result
.
IsNull
===
'YES'
?
true
:
false
),
defaultValue
:
_result
.
Default
defaultValue
:
_result
.
Default
,
primaryKey
:
_result
.
Constraint
===
'PRIMARY KEY'
};
});
}
else
if
(
this
.
isShowIndexesQuery
())
{
...
...
lib/dialects/mysql/query.js
View file @
fe30178
...
...
@@ -80,7 +80,8 @@ Query.prototype.formatResults = function(data) {
result
[
_result
.
Field
]
=
{
type
:
_result
.
Type
.
toUpperCase
(),
allowNull
:
(
_result
.
Null
===
'YES'
),
defaultValue
:
_result
.
Default
defaultValue
:
_result
.
Default
,
primaryKey
:
_result
.
Key
===
'PRI'
};
});
}
else
if
(
this
.
isShowIndexesQuery
())
{
...
...
lib/dialects/postgres/query-generator.js
View file @
fe30178
...
...
@@ -103,11 +103,14 @@ var QueryGenerator = {
schema
=
'public'
;
}
var
query
=
'SELECT c.column_name as "Field", c.column_default as "Default", c.is_nullable as "Null", '
+
var
query
=
'SELECT
tc.constraint_type as "Constraint",
c.column_name as "Field", c.column_default as "Default", c.is_nullable as "Null", '
+
"CASE WHEN c.udt_name = 'hstore' "
+
'THEN c.udt_name ELSE c.data_type END as "Type", (SELECT array_agg(e.enumlabel) '
+
'FROM pg_catalog.pg_type t JOIN pg_catalog.pg_enum e ON t.oid=e.enumtypid WHERE t.typname=c.udt_name) AS "special" '
+
'FROM information_schema.columns c WHERE table_name = <%= table %> AND table_schema = <%= schema %>'
;
'FROM information_schema.columns c '
+
'LEFT JOIN information_schema.key_column_usage cu ON c.table_name = cu.table_name AND cu.column_name = c.column_name '
+
'LEFT JOIN information_schema.table_constraints tc ON c.table_name = tc.table_name AND cu.column_name = c.column_name AND tc.constraint_type = \'PRIMARY KEY\' '
+
' WHERE c.table_name = <%= table %> AND c.table_schema = <%= schema %> '
;
return
Utils
.
_
.
template
(
query
)({
table
:
this
.
escape
(
tableName
),
...
...
lib/dialects/postgres/query.js
View file @
fe30178
...
...
@@ -244,7 +244,8 @@ Query.prototype.run = function(sql) {
type
:
_result
.
Type
.
toUpperCase
(),
allowNull
:
(
_result
.
Null
===
'YES'
),
defaultValue
:
_result
.
Default
,
special
:
(
!!
_result
.
special
?
self
.
sequelize
.
queryInterface
.
QueryGenerator
.
fromArray
(
_result
.
special
)
:
[])
special
:
(
!!
_result
.
special
?
self
.
sequelize
.
queryInterface
.
QueryGenerator
.
fromArray
(
_result
.
special
)
:
[]),
primaryKey
:
_result
.
Constraint
===
'PRIMARY KEY'
};
if
(
result
[
_result
.
Field
].
type
===
'BOOLEAN'
)
{
...
...
test/integration/query-interface.test.js
View file @
fe30178
...
...
@@ -159,10 +159,13 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
expect
(
count
).
to
.
be
.
at
.
least
(
1
);
count
=
0
;
var
id
=
metadata
.
id
;
var
username
=
metadata
.
username
;
var
isAdmin
=
metadata
.
isAdmin
;
var
enumVals
=
metadata
.
enumVals
;
expect
(
id
.
primaryKey
).
to
.
be
.
ok
;
var
assertVal
=
'VARCHAR(255)'
;
switch
(
dialect
)
{
case
'postgres'
:
...
...
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