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 af294fb3
authored
Nov 22, 2014
by
Matt Broadstone
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove unused code in SqlGenerator
1 parent
9efcca74
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 additions
and
137 deletions
lib/dialects/mssql/sql-generator.js
lib/dialects/mssql/sql-generator.js
View file @
af294fb
...
...
@@ -534,140 +534,4 @@ module.exports = {
return
attrString
.
join
(
', '
);
},
getTopClause
:
function
(
limit
){
return
"TOP("
+
limit
+
")"
;
},
getCountClause
:
function
(
alias
,
columnName
){
return
[
"SELECT COUNT("
,
columnName
,
") AS"
,
quoteIdentifier
(
alias
)
].
join
(
' '
);
},
getSelectorClause
:
function
(
model
,
options
){
var
query
=
[
'SELECT'
];
//we have joins
if
(
options
.
limit
&&
!
options
.
offset
){
query
.
push
(
this
.
getTopClause
(
options
.
limit
));
}
//add join table
if
(
options
.
include
){
query
.
push
(
loadFieldsWithName
(
options
.
attributes
,
model
.
name
));
for
(
var
i
=
0
;
i
<
options
.
include
.
length
;
i
++
){
if
(
options
.
include
[
i
].
as
)
{
query
.
push
(
','
+
joinFields
(
options
.
include
[
i
].
model
.
rawAttributes
,
options
.
include
[
i
].
as
));
}
}
}
else
{
query
.
push
(
loadFieldsWithName
(
options
.
attributes
));
//query.push(loadFieldsWithName(model.rawAttributes));
}
return
query
.
join
(
' '
);
},
getFromClause
:
function
(
tableName
,
asValue
){
var
query
=
[
"FROM"
,
quoteIdentifier
(
tableName
)];
if
(
asValue
){
query
.
push
(
"AS"
);
query
.
push
(
quoteIdentifier
(
asValue
));
}
return
query
.
join
(
' '
);
},
getJoinClause
:
function
(
model
,
include
){
var
query
=
[];
var
primaryKey
=
quoteIdentifier
(
model
.
primaryKeyAttribute
);
var
joinType
=
include
.
required
?
'INNER JOIN'
:
'LEFT OUTER JOIN'
;
var
joinTable
=
include
.
as
?
include
.
as
:
include
.
model
.
name
;
var
manyJoinTable
=
joinTable
;
joinTable
=
quoteIdentifier
(
joinTable
);
var
tableName
=
quoteIdentifier
(
model
.
name
);
var
hasManyToMany
=
false
;
query
.
push
(
joinType
);
if
(
include
.
through
){
hasManyToMany
=
true
;
}
//this logic handles the join types
var
associationType
=
include
.
association
.
associationType
;
var
rootKey
,
joinKey
;
if
(
associationType
===
'BelongsTo'
){
rootKey
=
quoteIdentifier
(
include
.
association
.
foreignKey
);
joinKey
=
primaryKey
;
}
else
if
(
associationType
===
'HasMany'
){
rootKey
=
primaryKey
;
joinKey
=
quoteIdentifier
(
include
.
association
.
identifier
);
if
(
hasManyToMany
){
//indicates many to many
manyJoinTable
=
quoteIdentifier
(
joinTable
+
'.'
+
include
.
through
.
as
);
//console.log(include.through);
query
=
query
.
concat
([
"("
,
quoteIdentifier
(
include
.
through
.
model
.
name
)
,
"AS"
,
manyJoinTable
,
joinType
,
joinTable
,
"AS"
,
joinTable
,
"ON"
,
joinTable
+
'.'
+
quoteIdentifier
(
include
.
model
.
primaryKeyAttribute
),
"="
,
manyJoinTable
+
'.'
+
quoteIdentifier
(
include
.
through
.
model
.
primaryKeyAttribute
),
")"
]);
}
}
else
{
rootKey
=
primaryKey
;
//console.log('dang mang',associationType);
joinKey
=
quoteIdentifier
(
include
.
association
.
foreignKey
);
//console.log('asdfdsaf', rootKey);
}
if
(
!
hasManyToMany
){
query
.
push
(
quoteIdentifier
(
include
.
model
.
tableName
));
query
.
push
(
'AS'
);
query
.
push
(
joinTable
);
}
query
=
query
.
concat
([
'ON'
,
tableName
+
'.'
+
rootKey
,
'='
,
manyJoinTable
+
'.'
+
joinKey
]);
if
(
include
.
where
){
query
.
push
(
'AND'
);
query
.
push
(
this
.
formatWhereCondition
(
include
.
where
,
joinTable
));
}
return
query
.
join
(
' '
);
},
formatWhereCondition
:
function
(
where
,
tableName
){
var
query
=
[];
for
(
var
key
in
where
){
var
val
=
where
[
key
];
var
operator
=
'='
;
if
(
!
val
)
{
operator
=
'IS'
;
}
if
(
tableName
){
query
.
push
(
quoteIdentifier
(
tableName
)
+
'.'
+
quoteIdentifier
(
key
));
}
else
{
query
.
push
(
quoteIdentifier
(
key
));
}
query
.
push
(
operator
);
if
(
!
val
){
query
.
push
(
'NULL'
);
}
else
if
(
typeof
val
===
'number'
){
query
.
push
(
val
);
}
else
{
query
.
push
(
wrapSingleQuote
(
val
));
}
}
return
query
.
join
(
' '
);
},
getWhereClause
:
function
(
where
,
tableName
){
return
[
'WHERE'
,
this
.
formatWhereCondition
(
where
,
tableName
)
].
join
(
' '
);
}};
};
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