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 701b9724
authored
Dec 09, 2011
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created index: done
1 parent
0027dfae
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
6 deletions
lib/connectors/mysql/query-generator.js
spec/query-generator.mysql.spec.js
lib/connectors/mysql/query-generator.js
View file @
701b972
var
Utils
=
require
(
"../../utils"
)
,
util
=
require
(
"util"
)
var
QueryGenerator
=
module
.
exports
=
{
/*
...
...
@@ -185,17 +186,42 @@ var QueryGenerator = module.exports = {
},
addIndexQuery
:
function
(
tableName
,
attributes
,
options
)
{
var
transformedAttributes
=
attributes
.
map
(
function
(
attribute
)
{
if
(
typeof
attribute
==
'string'
)
return
attribute
else
{
var
result
=
""
if
(
!
attribute
.
attribute
)
throw
new
Error
(
'The following index attribute has no attribute: '
+
util
.
inspect
(
attribute
))
result
+=
attribute
.
attribute
if
(
attribute
.
length
)
result
+=
'('
+
attribute
.
length
+
')'
if
(
attribute
.
order
)
result
+=
' '
+
attribute
.
order
return
result
}
})
var
onlyAttributeNames
=
attributes
.
map
(
function
(
attribute
)
{
return
(
typeof
attribute
==
'string'
)
?
attribute
:
attribute
.
attribute
})
options
=
Utils
.
_
.
extend
({
indicesType
:
null
,
indexName
:
Utils
.
_
.
underscored
(
tableName
+
'_'
+
attribut
es
.
join
(
'_'
)),
indexName
:
Utils
.
_
.
underscored
(
tableName
+
'_'
+
onlyAttributeNam
es
.
join
(
'_'
)),
parser
:
null
},
options
||
{})
return
Utils
.
_
.
compact
([
"CREATE"
,
options
.
indicesType
||
null
,
"INDEX"
,
options
.
indexName
,
options
.
indexType
?
'USING '
+
options
.
indexType
:
undefined
,
"ON"
,
tableName
,
attributes
.
join
(
', '
)
,
options
.
parser
?
"WITH PARSER "
+
options
.
parser
:
undefined
"CREATE"
,
options
.
indicesType
,
"INDEX"
,
options
.
indexName
,
(
options
.
indexType
?
(
'USING '
+
options
.
indexType
)
:
undefined
)
,
"ON"
,
tableName
,
'('
+
transformedAttributes
.
join
(
', '
)
+
')'
,
(
options
.
parser
?
"WITH PARSER "
+
options
.
parser
:
undefined
)
]).
join
(
' '
)
...
...
spec/query-generator.mysql.spec.js
View file @
701b972
...
...
@@ -127,7 +127,20 @@ describe('QueryGenerator', function() {
'addIndexQuery'
:
[
{
arguments
:
[
'User'
,
[
'username'
,
'isAdmin'
]],
expectation
:
'CREATE INDEX user_username_is_admin ON User username, isAdmin'
expectation
:
'CREATE INDEX user_username_is_admin ON User (username, isAdmin)'
},
{
arguments
:
[
'User'
,
[
{
attribute
:
'username'
,
length
:
10
,
order
:
'ASC'
},
'isAdmin'
]
],
expectation
:
"CREATE INDEX user_username_is_admin ON User (username(10) ASC, isAdmin)"
},
{
arguments
:
[
'User'
,
[
'username'
,
'isAdmin'
],
{
parser
:
'foo'
,
indicesType
:
'FULLTEXT'
,
indexName
:
'bar'
}
],
expectation
:
"CREATE FULLTEXT INDEX bar ON User (username, isAdmin) WITH PARSER foo"
}
],
...
...
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