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 556a6639
authored
May 04, 2013
by
Martin Aspeli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Topologically sorted iterator for DAOs taking dependencies into account
1 parent
10ec7ff6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletions
lib/dao-factory-manager.js
package.json
lib/dao-factory-manager.js
View file @
556a663
var
Toposort
=
require
(
'toposort-class'
)
module
.
exports
=
(
function
()
{
var
DAOFactoryManager
=
function
(
sequelize
)
{
this
.
daos
=
[]
...
...
@@ -31,5 +33,34 @@ module.exports = (function() {
return
this
.
daos
})
/**
* Iterate over DAOs in an order suitable for e.g. creating tables. Will
* take foreign key constraints into account so that dependencies are visited
* before dependents.
*/
DAOFactoryManager
.
prototype
.
forEachDAO
=
function
(
iterator
)
{
var
daos
=
{}
,
sorter
=
new
Toposort
()
this
.
daos
.
forEach
(
function
(
dao
)
{
daos
[
dao
.
tableName
]
=
dao
var
deps
=
[]
for
(
var
attrName
in
dao
.
rawAttributes
)
{
if
(
dao
.
rawAttributes
.
hasOwnProperty
(
attrName
))
{
if
(
dao
.
rawAttributes
[
attrName
].
references
)
{
deps
.
push
(
dao
.
rawAttributes
[
attrName
].
references
)
}
}
}
sorter
.
add
(
dao
.
tableName
,
deps
)
})
sorter
.
sort
().
reverse
().
forEach
(
function
(
name
)
{
iterator
(
daos
[
name
])
})
}
return
DAOFactoryManager
})()
package.json
View file @
556a663
...
...
@@ -36,7 +36,8 @@
"moment"
:
"~1.7.0"
,
"commander"
:
"~0.6.0"
,
"generic-pool"
:
"1.0.9"
,
"dottie"
:
"0.0.6-1"
"dottie"
:
"0.0.6-1"
,
"toposort-class"
:
"0.1.4"
},
"devDependencies"
:
{
"jasmine-node"
:
"1.5.0"
,
...
...
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