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 5992de73
authored
Mar 03, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added test for destruction of keys with dots when doing raw queries
1 parent
a377f267
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
56 additions
and
14 deletions
docs/data.json
docs/files/lib_dialects_abstract_query.js.html
docs/files/lib_sequelize.js.html
lib/dialects/abstract/query.js
lib/utils.js
spec/sequelize.spec.js
docs/data.json
View file @
5992de7
...
...
@@ -216,13 +216,13 @@
},
{
"file"
:
"lib/dialects/abstract/query.js"
,
"line"
:
3
33
,
"line"
:
3
45
,
"description"
:
"The function takes the result of the query execution and groups
\n
the associated data by the callee.
\n\n
Example:
\n
groupDataByCalleeFactory([
\n
{
\n
callee: { some: 'data', id: 1 },
\n
association: { foo: 'bar', id: 1 }
\n
}, {
\n
callee: { some: 'data', id: 1 },
\n
association: { foo: 'bar', id: 2 }
\n
}, {
\n
callee: { some: 'data', id: 1 },
\n
association: { foo: 'bar', id: 3 }
\n
}
\n
])
\n\n
Result:
\n
Something like this:
\n\n
[
\n
{
\n
callee: { some: 'data', id: 1 },
\n
association: [
\n
{ foo: 'bar', id: 1 },
\n
{ foo: 'bar', id: 2 },
\n
{ foo: 'bar', id: 3 }
\n
]
\n
}
\n
]"
,
"class"
:
"QueryInterface"
},
{
"file"
:
"lib/dialects/abstract/query.js"
,
"line"
:
393
,
"line"
:
405
,
"description"
:
"This function will prepare the result of select queries with joins."
,
"params"
:
[
{
...
...
@@ -407,11 +407,11 @@
},
{
"message"
:
"Missing item type
\n
The function takes the result of the query execution and groups
\n
the associated data by the callee.
\n\n
Example:
\n
groupDataByCalleeFactory([
\n
{
\n
callee: { some: 'data', id: 1 },
\n
association: { foo: 'bar', id: 1 }
\n
}, {
\n
callee: { some: 'data', id: 1 },
\n
association: { foo: 'bar', id: 2 }
\n
}, {
\n
callee: { some: 'data', id: 1 },
\n
association: { foo: 'bar', id: 3 }
\n
}
\n
])
\n\n
Result:
\n
Something like this:
\n\n
[
\n
{
\n
callee: { some: 'data', id: 1 },
\n
association: [
\n
{ foo: 'bar', id: 1 },
\n
{ foo: 'bar', id: 2 },
\n
{ foo: 'bar', id: 3 }
\n
]
\n
}
\n
]"
,
"line"
:
" lib/dialects/abstract/query.js:3
33
"
"line"
:
" lib/dialects/abstract/query.js:3
45
"
},
{
"message"
:
"Missing item type
\n
This function will prepare the result of select queries with joins."
,
"line"
:
" lib/dialects/abstract/query.js:
393
"
"line"
:
" lib/dialects/abstract/query.js:
405
"
},
{
"message"
:
"Missing item type
\n
Search for an instance."
,
...
...
docs/files/lib_dialects_abstract_query.js.html
View file @
5992de7
...
...
@@ -334,10 +334,22 @@ module.exports = (function() {
}
var handleSelectQuery = function(results) {
var result = null
, self = this;
var result = null
if (this.options.raw) {
result = results.map(Dot.transform)
result = results.map(function(result) {
var o = {}
for (var key in result) {
if (result.hasOwnProperty(key)) {
o[key] = result[key]
}
}
return o
})
result = result.map(Dot.transform)
} else if (this.options.hasJoin === true) {
result = prepareJoinData.call(this, results)
result = groupDataByCalleeFactory.call(this, result).map(function(result) {
...
...
docs/files/lib_sequelize.js.html
View file @
5992de7
...
...
@@ -233,7 +233,10 @@ module.exports = (function() {
}
Sequelize.prototype.query = function(sql, callee, options) {
if (arguments.length === 3) {
if (arguments.length === 4) {
values.unshift(sql)
sql = Utils.format(values)
} else if (arguments.length === 3) {
options = options
} else if (arguments.length === 2) {
options = {}
...
...
lib/dialects/abstract/query.js
View file @
5992de7
...
...
@@ -242,10 +242,22 @@ module.exports = (function() {
}
var
handleSelectQuery
=
function
(
results
)
{
var
result
=
null
,
self
=
this
;
var
result
=
null
if
(
this
.
options
.
raw
)
{
result
=
results
.
map
(
Dot
.
transform
)
result
=
results
.
map
(
function
(
result
)
{
var
o
=
{}
for
(
var
key
in
result
)
{
if
(
result
.
hasOwnProperty
(
key
))
{
o
[
key
]
=
result
[
key
]
}
}
return
o
})
result
=
result
.
map
(
Dot
.
transform
)
}
else
if
(
this
.
options
.
hasJoin
===
true
)
{
result
=
prepareJoinData
.
call
(
this
,
results
)
result
=
groupDataByCalleeFactory
.
call
(
this
,
result
).
map
(
function
(
result
)
{
...
...
lib/utils.js
View file @
5992de7
...
...
@@ -36,11 +36,13 @@ var Utils = module.exports = {
util
.
inherits
(
_class
,
require
(
'events'
).
EventEmitter
)
},
TICK_CHAR
:
'`'
,
addTicks
:
function
(
s
)
{
return
Utils
.
TICK_CHAR
+
Utils
.
removeTicks
(
s
)
+
Utils
.
TICK_CHAR
addTicks
:
function
(
s
,
tickChar
)
{
tickChar
=
tickChar
||
Utils
.
TICK_CHAR
return
tickChar
+
Utils
.
removeTicks
(
s
,
tickChar
)
+
tickChar
},
removeTicks
:
function
(
s
)
{
return
s
.
replace
(
new
RegExp
(
Utils
.
TICK_CHAR
,
'g'
),
""
)
removeTicks
:
function
(
s
,
tickChar
)
{
tickChar
=
tickChar
||
Utils
.
TICK_CHAR
return
s
.
replace
(
new
RegExp
(
tickChar
,
'g'
),
""
)
},
escape
:
function
(
s
)
{
return
SqlString
.
escape
(
s
,
true
,
"local"
).
replace
(
/
\\
"/g
,
'"'
)
...
...
spec/sequelize.spec.js
View file @
5992de7
...
...
@@ -107,7 +107,7 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() {
}.
bind
(
this
))
})
if
(
dialect
==
'mysql'
)
if
(
dialect
==
'mysql'
)
{
it
(
'executes stored procedures'
,
function
(
done
)
{
this
.
sequelize
.
query
(
this
.
insertQuery
).
success
(
function
()
{
this
.
sequelize
.
query
(
'DROP PROCEDURE IF EXISTS foo'
).
success
(
function
()
{
...
...
@@ -122,6 +122,9 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() {
}.
bind
(
this
))
}.
bind
(
this
))
})
}
else
{
console
.
log
(
'FIXME: I want to be supported in this dialect as well :-('
)
}
it
(
'uses the passed DAOFactory'
,
function
(
done
)
{
this
.
sequelize
.
query
(
this
.
insertQuery
).
success
(
function
()
{
...
...
@@ -131,6 +134,16 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() {
}.
bind
(
this
))
}.
bind
(
this
))
})
it
(
'destructs dot separated attributes when doing a raw query'
,
function
(
done
)
{
var
tickChar
=
(
dialect
===
'postgres'
)
?
'"'
:
'`'
,
sql
=
"select 1 as "
+
Utils
.
addTicks
(
'foo.bar.baz'
,
tickChar
)
this
.
sequelize
.
query
(
sql
,
null
,
{
raw
:
true
}).
success
(
function
(
result
)
{
expect
(
result
).
toEqual
([
{
foo
:
{
bar
:
{
baz
:
1
}
}
}
])
done
()
})
})
})
describe
(
'define'
,
function
()
{
...
...
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