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 be10f0bc
authored
Feb 26, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pg support for eager loading
1 parent
f096d9be
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
44 deletions
lib/dialects/postgres/connector-manager.js
lib/dialects/postgres/query-generator.js
spec/dao-factory.spec.js
spec/dao.spec.js
lib/dialects/postgres/connector-manager.js
View file @
be10f0b
...
...
@@ -31,7 +31,9 @@ module.exports = (function() {
}
var
query
=
new
Query
(
this
.
client
,
this
.
sequelize
,
callee
,
options
||
{})
self
.
pendingQueries
+=
1
return
query
.
run
(
sql
)
.
success
(
function
()
{
self
.
endQuery
.
call
(
self
)
})
.
error
(
function
()
{
self
.
endQuery
.
call
(
self
)
})
...
...
lib/dialects/postgres/query-generator.js
View file @
be10f0b
...
...
@@ -233,49 +233,27 @@ module.exports = (function() {
if
(
options
.
include
)
{
var
optAttributes
=
[
options
.
table
+
'.*'
]
for
(
var
daoName
in
options
.
include
)
{
if
(
options
.
include
.
hasOwnProperty
(
daoName
))
{
var
dao
=
options
.
include
[
daoName
]
,
daoFactory
=
dao
.
daoFactoryManager
.
getDAO
(
tableName
,
{
attribute
:
'tableName'
})
,
_tableName
=
addQuotes
(
dao
.
tableName
)
,
association
=
dao
.
getAssociation
(
daoFactory
)
if
(
association
.
connectorDAO
)
{
var
foreignIdentifier
=
Object
.
keys
(
association
.
connectorDAO
.
rawAttributes
).
filter
(
function
(
attrName
)
{
return
(
!!
attrName
.
match
(
/.+Id$/
)
||
!!
attrName
.
match
(
/.+_id$/
))
&&
(
attrName
!==
association
.
identifier
)
})[
0
]
query
+=
' LEFT OUTER JOIN '
+
addQuotes
(
association
.
connectorDAO
.
tableName
)
+
' ON '
query
+=
addQuotes
(
association
.
connectorDAO
.
tableName
)
+
'.'
query
+=
addQuotes
(
foreignIdentifier
)
+
'='
query
+=
addQuotes
(
table
)
+
'.'
+
addQuotes
(
'id'
)
query
+=
' LEFT OUTER JOIN '
+
addQuotes
(
dao
.
tableName
)
+
' ON '
query
+=
addQuotes
(
dao
.
tableName
)
+
'.'
query
+=
addQuotes
(
'id'
)
+
'='
query
+=
addQuotes
(
association
.
connectorDAO
.
tableName
)
+
'.'
+
addQuotes
(
association
.
identifier
)
}
else
{
query
+=
' LEFT OUTER JOIN '
+
addQuotes
(
dao
.
tableName
)
+
' ON '
query
+=
addQuotes
(
association
.
associationType
===
'BelongsTo'
?
dao
.
tableName
:
tableName
)
+
'.'
query
+=
addQuotes
(
association
.
identifier
)
+
'='
query
+=
addQuotes
(
association
.
associationType
===
'BelongsTo'
?
tableName
:
dao
.
tableName
)
+
'.'
+
addQuotes
(
'id'
)
}
var
aliasAssoc
=
daoFactory
.
getAssociationByAlias
(
daoName
)
,
aliasName
=
!!
aliasAssoc
?
addQuotes
(
daoName
)
:
_tableName
optAttributes
=
optAttributes
.
concat
(
Object
.
keys
(
dao
.
attributes
).
map
(
function
(
attr
)
{
return
''
+
[
_tableName
,
addQuotes
(
attr
)].
join
(
'.'
)
+
' AS "'
+
removeQuotes
([
aliasName
,
attr
].
join
(
'.'
))
+
'"'
})
)
}
}
options
.
include
.
forEach
(
function
(
include
)
{
var
attributes
=
Object
.
keys
(
include
.
daoFactory
.
attributes
).
map
(
function
(
attr
)
{
var
template
=
Utils
.
_
.
template
(
'"<%= table %>"."<%= attr %>" AS "<%= as %>.<%= attr %>"'
)
return
template
({
table
:
include
.
daoFactory
.
tableName
,
as
:
include
.
as
,
attr
:
attr
})
})
optAttributes
=
optAttributes
.
concat
(
attributes
)
var
joinQuery
=
' LEFT OUTER JOIN "<%= table %>" ON "<%= tableLeft %>"."<%= attrLeft %>" = "<%= tableRight %>"."<%= attrRight %>"'
query
+=
Utils
.
_
.
template
(
joinQuery
)({
table
:
include
.
daoFactory
.
tableName
,
tableLeft
:
((
include
.
association
.
associationType
===
'BelongsTo'
)
?
include
.
daoFactory
.
tableName
:
tableName
),
attrLeft
:
'id'
,
tableRight
:
((
include
.
association
.
associationType
===
'BelongsTo'
)
?
tableName
:
include
.
daoFactory
.
tableName
),
attrRight
:
include
.
association
.
identifier
})
})
options
.
attributes
=
optAttributes
.
join
(
', '
)
}
...
...
spec/dao-factory.spec.js
View file @
be10f0b
This diff is collapsed.
Click to expand it.
spec/dao.spec.js
View file @
be10f0b
if
(
typeof
require
===
'function'
)
{
if
(
typeof
require
===
'function'
)
{
const
buster
=
require
(
"buster"
)
,
Helpers
=
require
(
'./buster-helpers'
)
,
dialect
=
Helpers
.
getTestDialect
()
...
...
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