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 59605e88
authored
Nov 10, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use new private method style
1 parent
77c55541
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
32 deletions
lib/query.js
lib/sequelize.js
lib/query.js
View file @
59605e8
var
Utils
=
require
(
"./utils"
)
var
Utils
=
require
(
"./utils"
)
var
Query
=
module
.
exports
=
function
(
client
,
callee
,
options
)
{
module
.
exports
=
(
function
()
{
var
Query
=
function
(
client
,
callee
,
options
)
{
var
self
=
this
var
self
=
this
this
.
client
=
client
this
.
client
=
client
this
.
callee
=
callee
this
.
callee
=
callee
this
.
options
=
options
||
{}
this
.
options
=
options
||
{}
this
.
bindClientFunction
=
function
(
err
)
{
self
.
onFailure
(
err
)
}
this
.
bindClientFunction
=
function
(
err
)
{
onFailure
.
call
(
self
,
err
)
}
}
}
Utils
.
addEventEmitter
(
Query
)
Utils
.
addEventEmitter
(
Query
)
Query
.
prototype
.
run
=
function
(
query
)
{
Query
.
prototype
.
run
=
function
(
query
)
{
var
self
=
this
var
self
=
this
this
.
sql
=
query
this
.
sql
=
query
this
.
bindClient
(
)
bindClient
.
call
(
this
)
if
(
this
.
options
.
logging
)
if
(
this
.
options
.
logging
)
console
.
log
(
'Executing: '
+
this
.
sql
)
console
.
log
(
'Executing: '
+
this
.
sql
)
this
.
client
.
query
(
this
.
sql
,
function
(
err
,
results
,
fields
)
{
this
.
client
.
query
(
this
.
sql
,
function
(
err
,
results
,
fields
)
{
err
?
self
.
onFailure
(
err
)
:
self
.
onSuccess
(
self
.
sql
,
results
,
fields
)
err
?
onFailure
.
call
(
self
,
err
)
:
onSuccess
.
call
(
self
,
self
.
sql
,
results
,
fields
)
}).
setMaxListeners
(
100
)
}).
setMaxListeners
(
100
)
return
this
return
this
}
}
Query
.
prototype
.
bindClient
=
function
()
{
var
bindClient
=
function
()
{
this
.
client
.
on
(
'error'
,
this
.
bindClientFunction
)
this
.
client
.
on
(
'error'
,
this
.
bindClientFunction
)
}
}
Query
.
prototype
.
unbindClient
=
function
()
{
var
unbindClient
=
function
()
{
this
.
client
.
removeListener
(
'error'
,
this
.
bindClientFunction
)
this
.
client
.
removeListener
(
'error'
,
this
.
bindClientFunction
)
}
}
Query
.
prototype
.
onSuccess
=
function
(
query
,
results
,
fields
)
{
var
onSuccess
=
function
(
query
,
results
,
fields
)
{
var
result
=
this
.
callee
var
result
=
this
.
callee
,
self
=
this
,
self
=
this
...
@@ -50,11 +52,14 @@ Query.prototype.onSuccess = function(query, results, fields) {
...
@@ -50,11 +52,14 @@ Query.prototype.onSuccess = function(query, results, fields) {
result
=
(
result
.
length
==
0
)
?
null
:
result
[
0
]
result
=
(
result
.
length
==
0
)
?
null
:
result
[
0
]
}
}
this
.
unbindClient
(
)
unbindClient
.
call
(
this
)
this
.
emit
(
'success'
,
result
)
this
.
emit
(
'success'
,
result
)
}
}
Query
.
prototype
.
onFailure
=
function
(
err
)
{
var
onFailure
=
function
(
err
)
{
this
.
unbindClient
(
)
unbindClient
.
call
(
this
)
this
.
emit
(
'failure'
,
err
,
this
.
callee
)
this
.
emit
(
'failure'
,
err
,
this
.
callee
)
}
}
return
Query
})()
lib/sequelize.js
View file @
59605e8
...
@@ -3,7 +3,8 @@ var Utils = require("./utils")
...
@@ -3,7 +3,8 @@ var Utils = require("./utils")
,
DataTypes
=
require
(
'./data-types'
)
,
DataTypes
=
require
(
'./data-types'
)
,
ModelManager
=
require
(
"./model-manager"
)
,
ModelManager
=
require
(
"./model-manager"
)
var
Sequelize
=
module
.
exports
=
function
(
database
,
username
,
password
,
options
)
{
module
.
exports
=
(
function
()
{
var
Sequelize
=
function
(
database
,
username
,
password
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
Utils
.
_
.
reject
(
options
,
function
(
_
,
key
)
{
Utils
.
_
.
reject
(
options
,
function
(
_
,
key
)
{
...
@@ -24,12 +25,12 @@ var Sequelize = module.exports = function(database, username, password, options)
...
@@ -24,12 +25,12 @@ var Sequelize = module.exports = function(database, username, password, options)
this
.
modelManager
=
new
ModelManager
(
this
)
this
.
modelManager
=
new
ModelManager
(
this
)
this
.
connectorManager
=
new
ConnectorManager
(
this
,
this
.
config
)
this
.
connectorManager
=
new
ConnectorManager
(
this
,
this
.
config
)
}
}
Sequelize
.
Utils
=
Utils
Sequelize
.
Utils
=
Utils
Sequelize
.
Utils
.
_
.
map
(
DataTypes
,
function
(
sql
,
accessor
)
{
Sequelize
[
accessor
]
=
sql
})
Sequelize
.
Utils
.
_
.
map
(
DataTypes
,
function
(
sql
,
accessor
)
{
Sequelize
[
accessor
]
=
sql
})
Sequelize
.
prototype
.
define
=
function
(
modelName
,
attributes
,
options
)
{
Sequelize
.
prototype
.
define
=
function
(
modelName
,
attributes
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
if
(
this
.
options
.
define
)
if
(
this
.
options
.
define
)
...
@@ -38,14 +39,14 @@ Sequelize.prototype.define = function(modelName, attributes, options) {
...
@@ -38,14 +39,14 @@ Sequelize.prototype.define = function(modelName, attributes, options) {
var
model
=
this
.
modelManager
.
addModel
(
new
ModelFactory
(
modelName
,
attributes
,
options
))
var
model
=
this
.
modelManager
.
addModel
(
new
ModelFactory
(
modelName
,
attributes
,
options
))
return
model
return
model
}
}
Sequelize
.
prototype
.
import
=
function
(
path
)
{
Sequelize
.
prototype
.
import
=
function
(
path
)
{
var
defineCall
=
require
(
path
)
var
defineCall
=
require
(
path
)
return
defineCall
(
this
,
DataTypes
)
return
defineCall
(
this
,
DataTypes
)
}
}
Sequelize
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
Sequelize
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
if
(
this
.
options
.
query
)
if
(
this
.
options
.
query
)
...
@@ -54,9 +55,9 @@ Sequelize.prototype.query = function(sql, callee, options) {
...
@@ -54,9 +55,9 @@ Sequelize.prototype.query = function(sql, callee, options) {
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
)
}
}
Sequelize
.
prototype
.
sync
=
function
(
options
)
{
Sequelize
.
prototype
.
sync
=
function
(
options
)
{
options
=
options
||
{}
options
=
options
||
{}
if
(
this
.
options
.
sync
)
if
(
this
.
options
.
sync
)
...
@@ -74,9 +75,9 @@ Sequelize.prototype.sync = function(options) {
...
@@ -74,9 +75,9 @@ Sequelize.prototype.sync = function(options) {
.
on
(
'failure'
,
function
(
err
)
{
eventEmitter
.
emit
(
'failure'
,
err
)
})
.
on
(
'failure'
,
function
(
err
)
{
eventEmitter
.
emit
(
'failure'
,
err
)
})
})
})
return
eventEmitter
.
run
()
return
eventEmitter
.
run
()
}
}
Sequelize
.
prototype
.
drop
=
function
()
{
Sequelize
.
prototype
.
drop
=
function
()
{
var
self
=
this
var
self
=
this
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
return
new
Utils
.
CustomEventEmitter
(
function
(
emitter
)
{
...
@@ -89,4 +90,7 @@ Sequelize.prototype.drop = function() {
...
@@ -89,4 +90,7 @@ Sequelize.prototype.drop = function() {
.
on
(
'success'
,
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
on
(
'success'
,
function
()
{
emitter
.
emit
(
'success'
,
null
)
})
.
on
(
'failure'
,
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
.
on
(
'failure'
,
function
(
err
)
{
emitter
.
emit
(
'failure'
,
err
)
})
}).
run
()
}).
run
()
}
}
return
Sequelize
})()
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