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 d83ca3f7
authored
Jun 30, 2012
by
sdepold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed code duplication
1 parent
33bdb8f5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
70 deletions
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/query-generator.js
lib/dialects/sqlite/query-generator.js
lib/dialects/mysql/query-generator.js
View file @
d83ca3f
...
@@ -127,18 +127,10 @@ module.exports = (function() {
...
@@ -127,18 +127,10 @@ module.exports = (function() {
},
},
insertQuery
:
function
(
tableName
,
attrValueHash
)
{
insertQuery
:
function
(
tableName
,
attrValueHash
)
{
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
if
(
this
.
options
.
omitNull
)
{
_attrValueHash
=
{}
Utils
.
_
.
each
(
attrValueHash
,
function
(
val
,
key
)
{
if
(
val
!==
null
&&
val
!==
undefined
)
{
_attrValueHash
[
key
]
=
val
;
}
})
attrValueHash
=
_attrValueHash
}
var
replacements
=
{
var
replacements
=
{
table
:
Utils
.
addTicks
(
tableName
),
table
:
Utils
.
addTicks
(
tableName
),
attributes
:
Utils
.
_
.
keys
(
attrValueHash
).
map
(
function
(
attr
){
return
Utils
.
addTicks
(
attr
)}).
join
(
","
),
attributes
:
Utils
.
_
.
keys
(
attrValueHash
).
map
(
function
(
attr
){
return
Utils
.
addTicks
(
attr
)}).
join
(
","
),
...
@@ -150,22 +142,14 @@ module.exports = (function() {
...
@@ -150,22 +142,14 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
replacements
)
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
},
updateQuery
:
function
(
tableName
,
values
,
where
)
{
updateQuery
:
function
(
tableName
,
attrValueHash
,
where
)
{
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
if
(
this
.
options
.
omitNull
)
{
_attrValueHash
=
{}
Utils
.
_
.
each
(
values
,
function
(
val
,
key
)
{
if
(
val
!==
null
&&
val
!==
undefined
)
{
_attrValueHash
[
key
]
=
val
;
}
})
values
=
_attrValueHash
}
var
replacements
=
{
var
replacements
=
{
table
:
Utils
.
addTicks
(
tableName
),
table
:
Utils
.
addTicks
(
tableName
),
values
:
Utils
.
_
.
map
(
values
,
function
(
value
,
key
){
values
:
Utils
.
_
.
map
(
attrValueHash
,
function
(
value
,
key
){
return
Utils
.
addTicks
(
key
)
+
"="
+
Utils
.
escape
((
value
instanceof
Date
)
?
Utils
.
toSqlDate
(
value
)
:
value
)
return
Utils
.
addTicks
(
key
)
+
"="
+
Utils
.
escape
((
value
instanceof
Date
)
?
Utils
.
toSqlDate
(
value
)
:
value
)
}).
join
(
","
),
}).
join
(
","
),
where
:
QueryGenerator
.
getWhereConditions
(
where
)
where
:
QueryGenerator
.
getWhereConditions
(
where
)
...
...
lib/dialects/postgres/query-generator.js
View file @
d83ca3f
...
@@ -191,19 +191,10 @@ module.exports = (function() {
...
@@ -191,19 +191,10 @@ module.exports = (function() {
},
},
insertQuery
:
function
(
tableName
,
attrValueHash
)
{
insertQuery
:
function
(
tableName
,
attrValueHash
)
{
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>) RETURNING *;"
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
if
(
this
.
options
.
omitNull
)
{
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>) RETURNING *;"
_attrValueHash
=
{}
,
returning
=
[]
Utils
.
_
.
each
(
attrValueHash
,
function
(
val
,
key
)
{
if
(
val
!==
null
&&
val
!==
undefined
)
{
_attrValueHash
[
key
]
=
val
;
}
})
attrValueHash
=
_attrValueHash
}
var
returning
=
[]
Utils
.
_
.
forEach
(
attrValueHash
,
function
(
value
,
key
,
hash
)
{
Utils
.
_
.
forEach
(
attrValueHash
,
function
(
value
,
key
,
hash
)
{
if
(
tables
[
tableName
]
&&
tables
[
tableName
][
key
])
{
if
(
tables
[
tableName
]
&&
tables
[
tableName
][
key
])
{
...
@@ -227,22 +218,14 @@ module.exports = (function() {
...
@@ -227,22 +218,14 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
replacements
)
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
},
updateQuery
:
function
(
tableName
,
values
,
where
)
{
updateQuery
:
function
(
tableName
,
attrValueHash
,
where
)
{
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
if
(
this
.
options
.
omitNull
)
{
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
_attrValueHash
=
{}
Utils
.
_
.
each
(
values
,
function
(
val
,
key
)
{
if
(
val
!==
null
&&
val
!==
undefined
)
{
_attrValueHash
[
key
]
=
val
;
}
})
values
=
_attrValueHash
}
var
replacements
=
{
var
replacements
=
{
table
:
addQuotes
(
tableName
),
table
:
addQuotes
(
tableName
),
values
:
Utils
.
_
.
map
(
values
,
function
(
value
,
key
){
values
:
Utils
.
_
.
map
(
attrValueHash
,
function
(
value
,
key
){
return
addQuotes
(
key
)
+
"="
+
pgEscape
((
value
instanceof
Date
)
?
pgSqlDate
(
value
)
:
value
)
return
addQuotes
(
key
)
+
"="
+
pgEscape
((
value
instanceof
Date
)
?
pgSqlDate
(
value
)
:
value
)
}).
join
(
","
),
}).
join
(
","
),
where
:
QueryGenerator
.
getWhereConditions
(
where
)
where
:
QueryGenerator
.
getWhereConditions
(
where
)
...
...
lib/dialects/sqlite/query-generator.js
View file @
d83ca3f
...
@@ -16,7 +16,7 @@ var escape = function(str) {
...
@@ -16,7 +16,7 @@ var escape = function(str) {
module
.
exports
=
(
function
()
{
module
.
exports
=
(
function
()
{
var
QueryGenerator
=
{
var
QueryGenerator
=
{
options
:
{},
options
:
{},
createTableQuery
:
function
(
tableName
,
attributes
,
options
)
{
createTableQuery
:
function
(
tableName
,
attributes
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
...
@@ -44,18 +44,10 @@ module.exports = (function() {
...
@@ -44,18 +44,10 @@ module.exports = (function() {
},
},
insertQuery
:
function
(
tableName
,
attrValueHash
)
{
insertQuery
:
function
(
tableName
,
attrValueHash
)
{
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
;
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
;
if
(
this
.
options
.
omitNull
)
{
_attrValueHash
=
{}
Utils
.
_
.
each
(
attrValueHash
,
function
(
val
,
key
)
{
if
(
val
!==
null
&&
val
!==
undefined
)
{
_attrValueHash
[
key
]
=
val
;
}
})
attrValueHash
=
_attrValueHash
}
var
replacements
=
{
var
replacements
=
{
table
:
Utils
.
addTicks
(
tableName
),
table
:
Utils
.
addTicks
(
tableName
),
attributes
:
Utils
.
_
.
keys
(
attrValueHash
).
map
(
function
(
attr
){
return
Utils
.
addTicks
(
attr
)}).
join
(
","
),
attributes
:
Utils
.
_
.
keys
(
attrValueHash
).
map
(
function
(
attr
){
return
Utils
.
addTicks
(
attr
)}).
join
(
","
),
...
@@ -67,21 +59,14 @@ module.exports = (function() {
...
@@ -67,21 +59,14 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
replacements
)
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
},
updateQuery
:
function
(
tableName
,
values
,
where
)
{
updateQuery
:
function
(
tableName
,
attrValueHash
,
where
)
{
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
if
(
this
.
options
.
omitNull
)
{
_attrValueHash
=
{}
Utils
.
_
.
each
(
values
,
function
(
val
,
key
)
{
if
(
val
!==
null
&&
val
!==
undefined
)
{
_attrValueHash
[
key
]
=
val
;
}
})
values
=
_attrValueHash
}
var
replacements
=
{
var
replacements
=
{
table
:
Utils
.
addTicks
(
tableName
),
table
:
Utils
.
addTicks
(
tableName
),
values
:
Utils
.
_
.
map
(
values
,
function
(
value
,
key
){
values
:
Utils
.
_
.
map
(
attrValueHash
,
function
(
value
,
key
){
return
Utils
.
addTicks
(
key
)
+
"="
+
escape
((
value
instanceof
Date
)
?
Utils
.
toSqlDate
(
value
)
:
value
)
return
Utils
.
addTicks
(
key
)
+
"="
+
escape
((
value
instanceof
Date
)
?
Utils
.
toSqlDate
(
value
)
:
value
)
}).
join
(
","
),
}).
join
(
","
),
where
:
MySqlQueryGenerator
.
getWhereConditions
(
where
)
where
:
MySqlQueryGenerator
.
getWhereConditions
(
where
)
...
...
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