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 91afa273
authored
Sep 02, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved connector logic into new class
1 parent
18cecf6c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
37 deletions
lib/sequelize/connector-manager.js
lib/sequelize/sequelize.js
lib/sequelize/connector-manager.js
0 → 100644
View file @
91afa27
var
ConnectorManager
=
module
.
exports
=
function
(
config
)
{
this
.
connectorCheckTimeoutId
=
null
this
.
client
=
null
this
.
config
=
config
}
ConnectorManager
.
prototype
.
connect
=
function
()
{
var
self
=
this
this
.
client
=
require
(
"mysql"
).
createClient
({
user
:
this
.
config
.
username
,
password
:
this
.
config
.
password
,
host
:
this
.
config
.
host
,
port
:
this
.
config
.
port
,
database
:
this
.
config
.
database
})
this
.
client
.
setMaxListeners
(
100
)
}
ConnectorManager
.
prototype
.
disconnect
=
function
()
{
var
self
=
this
this
.
client
.
end
(
function
()
{
self
.
client
=
null
self
.
connectorCheckTimeoutId
=
null
})
}
ConnectorManager
.
prototype
.
check
=
function
()
{
var
self
=
this
this
.
connectorCheckTimeoutId
&&
clearTimeout
(
this
.
connectorCheckTimeoutId
)
this
.
connectorCheckTimeoutId
=
setTimeout
(
function
()
{
if
(
self
.
client
&&
self
.
client
.
_queue
&&
(
self
.
client
.
_queue
.
length
===
0
))
self
.
disconnect
()
},
100
)
}
ConnectorManager
.
prototype
.
__defineGetter__
(
'isConnected'
,
function
()
{
return
(
this
.
client
!==
null
)
})
\ No newline at end of file
lib/sequelize/sequelize.js
View file @
91afa27
...
@@ -19,43 +19,11 @@ var Sequelize = module.exports = function(database, username, password, options)
...
@@ -19,43 +19,11 @@ var Sequelize = module.exports = function(database, username, password, options)
host
:
options
.
host
||
'localhost'
,
host
:
options
.
host
||
'localhost'
,
port
:
options
.
port
||
3306
port
:
options
.
port
||
3306
}
}
this
.
connector
CheckTimeoutId
=
null
this
.
connector
Manager
=
new
(
require
(
'./connector-manager'
))(
this
.
config
)
}
}
Sequelize
.
Utils
=
Utils
Sequelize
.
Utils
=
Utils
var
instanceMethods
=
{
var
instanceMethods
=
{
initConnector
:
function
()
{
var
self
=
this
this
.
client
=
require
(
"mysql"
).
createClient
({
user
:
this
.
config
.
username
,
password
:
this
.
config
.
password
,
host
:
this
.
config
.
host
,
port
:
this
.
config
.
port
,
database
:
this
.
config
.
database
})
this
.
client
.
setMaxListeners
(
100
)
},
freeConnector
:
function
()
{
var
self
=
this
this
.
client
.
end
(
function
()
{
self
.
client
=
null
self
.
connectorCheckTimeoutId
=
null
})
},
checkConnector
:
function
()
{
var
self
=
this
this
.
connectorCheckTimeoutId
&&
clearTimeout
(
this
.
connectorCheckTimeoutId
)
this
.
connectorCheckTimeoutId
=
setTimeout
(
function
()
{
if
(
self
.
client
&&
self
.
client
.
_queue
&&
(
self
.
client
.
_queue
.
length
===
0
))
self
.
freeConnector
()
},
500
)
},
define
:
function
(
modelName
,
attributes
,
options
)
{
define
:
function
(
modelName
,
attributes
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
...
@@ -75,16 +43,16 @@ var instanceMethods = {
...
@@ -75,16 +43,16 @@ var instanceMethods = {
options
=
options
||
{}
options
=
options
||
{}
if
(
this
.
options
.
queryOptions
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
queryOptions
)
if
(
this
.
options
.
queryOptions
)
options
=
Sequelize
.
Utils
.
merge
(
options
,
this
.
options
.
queryOptions
)
if
(
!
this
.
c
lient
)
this
.
initConnector
()
if
(
!
this
.
c
onnectorManager
.
isConnected
)
this
.
connectorManager
.
connect
()
options
.
logging
=
this
.
options
.
hasOwnProperty
(
'logging'
)
?
this
.
options
.
logging
:
true
options
.
logging
=
this
.
options
.
hasOwnProperty
(
'logging'
)
?
this
.
options
.
logging
:
true
var
self
=
this
var
self
=
this
,
query
=
new
Query
(
this
.
client
,
callee
,
options
).
run
(
sql
)
,
query
=
new
Query
(
this
.
c
onnectorManager
.
c
lient
,
callee
,
options
).
run
(
sql
)
query
query
.
on
(
'success'
,
function
(){
self
.
c
heckConnector
()
})
.
on
(
'success'
,
function
(){
self
.
c
onnectorManager
.
check
()
})
.
on
(
'failure'
,
function
(){
self
.
c
heckConnector
()
})
.
on
(
'failure'
,
function
(){
self
.
c
onnectorManager
.
check
()
})
return
query
return
query
},
},
...
...
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