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 a8efaea4
authored
Mar 27, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
made addQuotes and removeQuotes parts of the QueryGenerator
1 parent
7139a630
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
18 deletions
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/query-generator.js
lib/dialects/mysql/query-generator.js
View file @
a8efaea
...
...
@@ -20,20 +20,20 @@ module.exports = (function() {
if
(
Utils
.
_
.
includes
(
dataType
,
'PRIMARY KEY'
))
{
primaryKeys
.
push
(
attr
)
attrStr
.
push
(
Utils
.
addTick
s
(
attr
)
+
" "
+
dataType
.
replace
(
/PRIMARY KEY/
,
''
))
attrStr
.
push
(
QueryGenerator
.
addQuote
s
(
attr
)
+
" "
+
dataType
.
replace
(
/PRIMARY KEY/
,
''
))
}
else
{
attrStr
.
push
(
Utils
.
addTick
s
(
attr
)
+
" "
+
dataType
)
attrStr
.
push
(
QueryGenerator
.
addQuote
s
(
attr
)
+
" "
+
dataType
)
}
}
}
var
values
=
{
table
:
Utils
.
addTick
s
(
tableName
),
table
:
QueryGenerator
.
addQuote
s
(
tableName
),
attributes
:
attrStr
.
join
(
", "
),
engine
:
options
.
engine
,
charset
:
(
options
.
charset
?
"DEFAULT CHARSET="
+
options
.
charset
:
""
)
}
,
pkString
=
primaryKeys
.
map
(
function
(
pk
)
{
return
Utils
.
addTick
s
(
pk
)
}).
join
(
", "
)
,
pkString
=
primaryKeys
.
map
(
function
(
pk
)
{
return
QueryGenerator
.
addQuote
s
(
pk
)
}).
join
(
", "
)
if
(
pkString
.
length
>
0
)
{
values
.
attributes
+=
", PRIMARY KEY ("
+
pkString
+
")"
...
...
@@ -47,7 +47,9 @@ module.exports = (function() {
var
query
=
"DROP TABLE IF EXISTS <%= table %>;"
return
Utils
.
_
.
template
(
query
)({
table
:
Utils
.
addTicks
(
tableName
)})
return
Utils
.
_
.
template
(
query
)({
table
:
QueryGenerator
.
addQuotes
(
tableName
)
})
},
renameTableQuery
:
function
(
before
,
after
)
{
...
...
@@ -118,12 +120,12 @@ module.exports = (function() {
,
table
=
null
options
=
options
||
{}
options
.
table
=
table
=
Array
.
isArray
(
tableName
)
?
tableName
.
map
(
function
(
tbl
){
return
Utils
.
addTicks
(
tbl
)
}).
join
(
", "
)
:
Utils
.
addTick
s
(
tableName
)
options
.
table
=
table
=
Array
.
isArray
(
tableName
)
?
tableName
.
map
(
function
(
tbl
){
return
QueryGenerator
.
addQuotes
(
tbl
)
}).
join
(
", "
)
:
QueryGenerator
.
addQuote
s
(
tableName
)
options
.
attributes
=
options
.
attributes
&&
options
.
attributes
.
map
(
function
(
attr
){
if
(
Array
.
isArray
(
attr
)
&&
attr
.
length
==
2
)
{
return
[
attr
[
0
],
Utils
.
addTick
s
(
attr
[
1
])].
join
(
' as '
)
return
[
attr
[
0
],
QueryGenerator
.
addQuote
s
(
attr
[
1
])].
join
(
' as '
)
}
else
{
return
attr
.
indexOf
(
Utils
.
TICK_CHAR
)
<
0
?
Utils
.
addTick
s
(
attr
)
:
attr
return
attr
.
indexOf
(
Utils
.
TICK_CHAR
)
<
0
?
QueryGenerator
.
addQuote
s
(
attr
)
:
attr
}
}).
join
(
", "
)
options
.
attributes
=
options
.
attributes
||
'*'
...
...
@@ -159,7 +161,7 @@ module.exports = (function() {
}
if
(
options
.
group
)
{
options
.
group
=
Array
.
isArray
(
options
.
group
)
?
options
.
group
.
map
(
function
(
grp
){
return
Utils
.
addTicks
(
grp
)}).
join
(
', '
)
:
Utils
.
addTick
s
(
options
.
group
)
options
.
group
=
Array
.
isArray
(
options
.
group
)
?
options
.
group
.
map
(
function
(
grp
){
return
QueryGenerator
.
addQuotes
(
grp
)}).
join
(
', '
)
:
QueryGenerator
.
addQuote
s
(
options
.
group
)
query
+=
" GROUP BY <%= group %>"
}
...
...
@@ -187,8 +189,8 @@ module.exports = (function() {
var
query
=
"INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);"
var
replacements
=
{
table
:
Utils
.
addTick
s
(
tableName
),
attributes
:
Object
.
keys
(
attrValueHash
).
map
(
function
(
attr
){
return
Utils
.
addTick
s
(
attr
)}).
join
(
","
),
table
:
QueryGenerator
.
addQuote
s
(
tableName
),
attributes
:
Object
.
keys
(
attrValueHash
).
map
(
function
(
attr
){
return
QueryGenerator
.
addQuote
s
(
attr
)}).
join
(
","
),
values
:
Utils
.
_
.
values
(
attrValueHash
).
map
(
function
(
value
){
return
Utils
.
escape
((
value
instanceof
Date
)
?
Utils
.
toSqlDate
(
value
)
:
value
)
}).
join
(
","
)
...
...
@@ -207,11 +209,11 @@ module.exports = (function() {
var
value
=
attrValueHash
[
key
]
,
_value
=
(
value
instanceof
Date
)
?
Utils
.
toSqlDate
(
value
)
:
value
values
.
push
(
Utils
.
addTick
s
(
key
)
+
"="
+
Utils
.
escape
(
_value
))
values
.
push
(
QueryGenerator
.
addQuote
s
(
key
)
+
"="
+
Utils
.
escape
(
_value
))
}
var
replacements
=
{
table
:
Utils
.
addTick
s
(
tableName
),
table
:
QueryGenerator
.
addQuote
s
(
tableName
),
values
:
values
.
join
(
","
),
where
:
QueryGenerator
.
getWhereConditions
(
where
)
}
...
...
@@ -225,7 +227,7 @@ module.exports = (function() {
var
query
=
"DELETE FROM <%= table %> WHERE <%= where %> LIMIT <%= limit %>"
var
replacements
=
{
table
:
Utils
.
addTick
s
(
tableName
),
table
:
QueryGenerator
.
addQuote
s
(
tableName
),
where
:
QueryGenerator
.
getWhereConditions
(
where
),
limit
:
Utils
.
escape
(
options
.
limit
)
}
...
...
@@ -243,11 +245,11 @@ module.exports = (function() {
var
value
=
attrValueHash
[
key
]
,
_value
=
(
value
instanceof
Date
)
?
Utils
.
toSqlDate
(
value
)
:
value
values
.
push
(
Utils
.
addTicks
(
key
)
+
"="
+
Utils
.
addTick
s
(
key
)
+
" + "
+
Utils
.
escape
(
_value
))
values
.
push
(
QueryGenerator
.
addQuotes
(
key
)
+
"="
+
QueryGenerator
.
addQuote
s
(
key
)
+
" + "
+
Utils
.
escape
(
_value
))
}
var
replacements
=
{
table
:
Utils
.
addTick
s
(
tableName
),
table
:
QueryGenerator
.
addQuote
s
(
tableName
),
values
:
values
.
join
(
","
),
where
:
QueryGenerator
.
getWhereConditions
(
where
)
}
...
...
@@ -342,7 +344,7 @@ module.exports = (function() {
var
value
=
hash
[
key
]
//handle qualified key names
var
_key
=
key
.
split
(
'.'
).
map
(
function
(
col
){
return
Utils
.
addTick
s
(
col
)}).
join
(
"."
)
var
_key
=
key
.
split
(
'.'
).
map
(
function
(
col
){
return
QueryGenerator
.
addQuote
s
(
col
)}).
join
(
"."
)
,
_value
=
null
if
(
Array
.
isArray
(
value
))
{
...
...
@@ -357,7 +359,7 @@ module.exports = (function() {
// is value an object?
//using as sentinel for join column => value
_value
=
value
.
join
.
split
(
'.'
).
map
(
function
(
col
){
return
Utils
.
addTick
s
(
col
)
}).
join
(
"."
)
_value
=
value
.
join
.
split
(
'.'
).
map
(
function
(
col
){
return
QueryGenerator
.
addQuote
s
(
col
)
}).
join
(
"."
)
result
.
push
([
_key
,
_value
].
join
(
"="
))
}
else
{
_value
=
Utils
.
escape
(
value
)
...
...
@@ -432,6 +434,14 @@ module.exports = (function() {
}
return
fields
},
addQuotes
:
function
(
s
,
quoteChar
)
{
return
Utils
.
addTicks
(
s
,
quoteChar
)
},
removeQuotes
:
function
(
s
,
quoteChar
)
{
return
Utils
.
removeTicks
(
s
,
quoteChar
)
}
}
...
...
lib/dialects/postgres/query-generator.js
View file @
a8efaea
This diff is collapsed.
Click to expand it.
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