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 12fd2280
authored
Nov 10, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored instance methods of sequelize
1 parent
c29500a3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
48 deletions
lib/sequelize.js
lib/sequelize.js
View file @
12fd228
...
...
@@ -25,71 +25,68 @@ var Sequelize = module.exports = function(database, username, password, options)
this
.
modelManager
=
new
ModelManager
(
this
)
this
.
connectorManager
=
new
ConnectorManager
(
this
,
this
.
config
)
}
Sequelize
.
Utils
=
Utils
Sequelize
.
Utils
.
_
.
map
(
DataTypes
,
function
(
sql
,
accessor
)
{
Sequelize
[
accessor
]
=
sql
})
var
instanceMethods
=
{
define
:
function
(
modelName
,
attributes
,
options
)
{
options
=
options
||
{}
Sequelize
.
prototype
.
define
=
function
(
modelName
,
attributes
,
options
)
{
options
=
options
||
{}
if
(
this
.
options
.
define
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
define
)
if
(
this
.
options
.
define
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
define
)
var
model
=
this
.
modelManager
.
addModel
(
new
ModelFactory
(
modelName
,
attributes
,
options
))
var
model
=
this
.
modelManager
.
addModel
(
new
ModelFactory
(
modelName
,
attributes
,
options
))
return
model
},
return
model
}
import
:
function
(
path
)
{
var
defineCall
=
require
(
path
)
return
defineCall
(
this
,
DataTypes
)
},
Sequelize
.
prototype
.
import
=
function
(
path
)
{
var
defineCall
=
require
(
path
)
return
defineCall
(
this
,
DataTypes
)
}
query
:
function
(
sql
,
callee
,
options
)
{
options
=
options
||
{}
Sequelize
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
options
=
options
||
{}
if
(
this
.
options
.
query
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
query
)
if
(
this
.
options
.
query
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
query
)
options
.
logging
=
this
.
options
.
hasOwnProperty
(
'logging'
)
?
this
.
options
.
logging
:
true
options
.
logging
=
this
.
options
.
hasOwnProperty
(
'logging'
)
?
this
.
options
.
logging
:
true
return
this
.
connectorManager
.
query
(
sql
,
callee
,
options
)
},
return
this
.
connectorManager
.
query
(
sql
,
callee
,
options
)
}
sync
:
function
(
options
)
{
options
=
options
||
{}
Sequelize
.
prototype
.
sync
=
function
(
options
)
{
options
=
options
||
{}
if
(
this
.
options
.
sync
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
sync
)
if
(
this
.
options
.
sync
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
sync
)
var
self
=
this
var
eventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
var
chainer
=
new
Utils
.
QueryChainer
var
self
=
this
var
eventEmitter
=
new
Utils
.
CustomEventEmitter
(
function
()
{
var
chainer
=
new
Utils
.
QueryChainer
self
.
modelManager
.
models
.
forEach
(
function
(
model
)
{
chainer
.
add
(
model
.
sync
(
options
))
})
self
.
modelManager
.
models
.
forEach
(
function
(
model
)
{
chainer
.
add
(
model
.
sync
(
options
))
})
chainer
.
run
()
.
on
(
'success'
,
function
()
{
eventEmitter
.
emit
(
'success'
,
null
)
})
.
on
(
'failure'
,
function
(
err
)
{
eventEmitter
.
emit
(
'failure'
,
err
)
})
})
return
eventEmitter
.
run
()
},
chainer
.
run
()
.
on
(
'success'
,
function
()
{
eventEmitter
.
emit
(
'success'
,
null
)
})
.
on
(
'failure'
,
function
(
err
)
{
eventEmitter
.
emit
(
'failure'
,
err
)
})
})
return
eventEmitter
.
run
()
}
drop
:
function
()
{
var
self
=
this
Sequelize
.
prototype
.
drop
=
function
()
{
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
chainer
=
new
Utils
.
QueryChainer
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
var
chainer
=
new
Utils
.
QueryChainer
self
.
modelManager
.
models
.
forEach
(
function
(
model
)
{
chainer
.
add
(
model
.
drop
())
})
self
.
modelManager
.
models
.
forEach
(
function
(
model
)
{
chainer
.
add
(
model
.
drop
())
})
chainer
.
run
()
.
on
(
'success'
,
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
on
(
'failure'
,
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}).
run
()
}
chainer
.
run
()
.
on
(
'success'
,
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
on
(
'failure'
,
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}).
run
()
}
Sequelize
.
Utils
.
_
.
map
(
DataTypes
,
function
(
sql
,
accessor
)
{
Sequelize
[
accessor
]
=
sql
})
Sequelize
.
Utils
.
_
.
map
(
instanceMethods
,
function
(
fct
,
name
)
{
Sequelize
.
prototype
[
name
]
=
fct
})
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