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 9c1e7348
authored
Apr 18, 2012
by
sdepold
Browse files
Options
Browse Files
Download
Plain Diff
use new config syntax in jasmine tests
2 parents
c5c1bb74
c99789f4
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
94 additions
and
31 deletions
lib/dialects/mysql/connector-manager.js
lib/sequelize.js
package.json
spec-jasmine/config/config.js
spec-jasmine/mysql/associations.has-many.spec.js
spec-jasmine/mysql/associations.spec.js
spec-jasmine/mysql/connector-manager.spec.js
spec-jasmine/mysql/dao-factory.spec.js
spec-jasmine/mysql/query-generator.spec.js
spec/config.js
spec/sqlite/dao.spec.js
lib/dialects/mysql/connector-manager.js
View file @
9c1e734
var
Query
=
require
(
"./query"
)
var
Pooling
=
require
(
'generic-pool'
)
,
Query
=
require
(
"./query"
)
,
Utils
=
require
(
"../../utils"
)
,
Utils
=
require
(
"../../utils"
)
,
without
=
function
(
arr
,
elem
)
{
return
arr
.
filter
(
function
(
e
)
{
return
e
!=
elem
})
}
,
without
=
function
(
arr
,
elem
)
{
return
arr
.
filter
(
function
(
e
)
{
return
e
!=
elem
})
}
...
@@ -11,13 +12,33 @@ module.exports = (function() {
...
@@ -11,13 +12,33 @@ module.exports = (function() {
this
.
queue
=
[]
this
.
queue
=
[]
this
.
activeQueue
=
[]
this
.
activeQueue
=
[]
this
.
maxConcurrentQueries
=
(
this
.
config
.
maxConcurrentQueries
||
50
)
this
.
maxConcurrentQueries
=
(
this
.
config
.
maxConcurrentQueries
||
50
)
this
.
poolCfg
=
this
.
config
.
pool
if
(
this
.
poolCfg
)
{
//the user has requested pooling, so create our connection pool
if
(
!
this
.
poolCfg
.
maxConnections
)
{
this
.
poolCfg
.
maxConnections
=
10
}
var
self
=
this
this
.
pool
=
Pooling
.
Pool
({
name
:
'sequelize-mysql'
,
create
:
function
(
done
)
{
connect
(
self
,
done
)
},
destroy
:
function
(
client
)
{
disconnect
(
null
,
client
)
},
max
:
self
.
poolCfg
.
maxConnections
,
idleTimeoutMillis
:
self
.
poolCfg
.
maxIdleTime
})
}
}
}
Utils
.
_
.
extend
(
ConnectorManager
.
prototype
,
require
(
"../connector-manager"
).
prototype
)
Utils
.
_
.
extend
(
ConnectorManager
.
prototype
,
require
(
"../connector-manager"
).
prototype
)
var
isConnecting
=
false
var
isConnecting
=
false
ConnectorManager
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
ConnectorManager
.
prototype
.
query
=
function
(
sql
,
callee
,
options
)
{
if
(
!
this
.
isConnected
)
this
.
connect
()
if
(
!
this
.
isConnected
&&
!
this
.
pool
)
this
.
connect
()
var
queueItem
=
{
var
queueItem
=
{
query
:
new
Query
(
this
.
client
,
callee
,
options
||
{}),
query
:
new
Query
(
this
.
client
,
callee
,
options
||
{}),
...
@@ -32,53 +53,91 @@ module.exports = (function() {
...
@@ -32,53 +53,91 @@ module.exports = (function() {
ConnectorManager
.
prototype
.
connect
=
function
()
{
ConnectorManager
.
prototype
.
connect
=
function
()
{
var
self
=
this
var
self
=
this
// in case database is slow to connect, prevent orphaning the client
// in case database is slow to connect, prevent orphaning the client
if
(
this
.
isConnecting
)
{
if
(
this
.
isConnecting
||
this
.
pool
)
{
return
return
}
}
this
.
client
=
require
(
"mysql"
).
createClient
({
connect
(
self
,
function
(
err
,
client
)
{
user
:
this
.
config
.
username
,
self
.
client
=
client
password
:
this
.
config
.
password
,
return
host
:
this
.
config
.
host
,
port
:
this
.
config
.
port
,
database
:
this
.
config
.
database
})
})
return
this
.
client
.
setMaxListeners
(
this
.
maxConcurrentQueries
)
this
.
isConnecting
=
false
}
}
ConnectorManager
.
prototype
.
disconnect
=
function
()
{
ConnectorManager
.
prototype
.
disconnect
=
function
()
{
var
self
=
this
if
(
this
.
client
)
this
.
client
.
end
(
function
()
{
disconnect
(
this
,
this
.
client
)
}
// private
var
disconnect
=
function
(
self
,
client
)
{
client
.
end
(
function
()
{
var
intervalObj
=
null
var
intervalObj
=
null
var
cleanup
=
function
()
{
var
cleanup
=
function
()
{
var
retryCt
=
0
var
retryCt
=
0
// make sure to let client finish before calling destroy
// make sure to let client finish before calling destroy
if
(
!
self
.
hasNoConnections
)
{
if
(
self
&&
!
self
.
hasNoConnections
)
{
return
return
}
}
// needed to prevent mysql connection leak
// needed to prevent mysql connection leak
self
.
client
.
destroy
()
client
.
destroy
()
self
.
client
=
null
if
(
self
&&
self
.
client
)
{
self
.
client
=
null
}
clearInterval
(
intervalObj
)
clearInterval
(
intervalObj
)
}
}
intervalObj
=
setInterval
(
cleanup
,
10
)
intervalObj
=
setInterval
(
cleanup
,
10
)
cleanup
()
cleanup
()
return
})
})
}
}
// private
var
connect
=
function
(
self
,
done
)
{
var
client
=
require
(
"mysql"
).
createClient
({
user
:
self
.
config
.
username
,
password
:
self
.
config
.
password
,
host
:
self
.
config
.
host
,
port
:
self
.
config
.
port
,
database
:
self
.
config
.
database
})
client
.
setMaxListeners
(
self
.
maxConcurrentQueries
)
self
.
isConnecting
=
false
done
(
null
,
client
)
return
}
var
enqueue
=
function
(
queueItem
)
{
var
enqueue
=
function
(
queueItem
)
{
if
(
this
.
activeQueue
.
length
<
this
.
maxConcurrentQueries
)
{
if
(
this
.
activeQueue
.
length
<
this
.
maxConcurrentQueries
)
{
this
.
activeQueue
.
push
(
queueItem
)
this
.
activeQueue
.
push
(
queueItem
)
execQueueItem
.
call
(
this
,
queueItem
)
if
(
this
.
pool
)
{
var
self
=
this
this
.
pool
.
acquire
(
function
(
err
,
client
)
{
if
(
err
)
{
queueItem
.
query
.
emit
(
'failure'
,
err
)
return
}
//we set the client here, asynchronously, when getting a pooled connection
//allowing the ConnectorManager.query method to remain synchronous
queueItem
.
query
.
client
=
client
queueItem
.
client
=
client
execQueueItem
.
call
(
self
,
queueItem
)
return
})
}
else
{
execQueueItem
.
call
(
this
,
queueItem
)
}
}
else
{
}
else
{
this
.
queue
.
push
(
queueItem
)
this
.
queue
.
push
(
queueItem
)
}
}
}
}
var
dequeue
=
function
(
queueItem
)
{
var
dequeue
=
function
(
queueItem
)
{
//return the item's connection to the pool
if
(
this
.
pool
)
{
this
.
pool
.
release
(
queueItem
.
client
)
}
this
.
activeQueue
=
without
(
this
.
activeQueue
,
queueItem
)
this
.
activeQueue
=
without
(
this
.
activeQueue
,
queueItem
)
}
}
...
@@ -108,7 +167,7 @@ module.exports = (function() {
...
@@ -108,7 +167,7 @@ module.exports = (function() {
.
success
(
function
(){
afterQuery
.
call
(
self
,
queueItem
)
})
.
success
(
function
(){
afterQuery
.
call
(
self
,
queueItem
)
})
.
error
(
function
(){
afterQuery
.
call
(
self
,
queueItem
)
})
.
error
(
function
(){
afterQuery
.
call
(
self
,
queueItem
)
})
queueItem
.
query
.
run
(
queueItem
.
sql
)
queueItem
.
query
.
run
(
queueItem
.
sql
,
queueItem
.
client
)
}
}
ConnectorManager
.
prototype
.
__defineGetter__
(
'hasNoConnections'
,
function
()
{
ConnectorManager
.
prototype
.
__defineGetter__
(
'hasNoConnections'
,
function
()
{
...
...
lib/sequelize.js
View file @
9c1e734
...
@@ -26,7 +26,8 @@ module.exports = (function() {
...
@@ -26,7 +26,8 @@ module.exports = (function() {
username
:
username
,
username
:
username
,
password
:
((
([
""
,
null
,
false
].
indexOf
(
password
)
>
-
1
)
||
(
typeof
password
==
'undefined'
))
?
null
:
password
),
password
:
((
([
""
,
null
,
false
].
indexOf
(
password
)
>
-
1
)
||
(
typeof
password
==
'undefined'
))
?
null
:
password
),
host
:
this
.
options
.
host
,
host
:
this
.
options
.
host
,
port
:
this
.
options
.
port
port
:
this
.
options
.
port
,
pool
:
this
.
options
.
pool
}
}
var
ConnectorManager
=
require
(
"./dialects/"
+
this
.
options
.
dialect
+
"/connector-manager"
)
var
ConnectorManager
=
require
(
"./dialects/"
+
this
.
options
.
dialect
+
"/connector-manager"
)
...
...
package.json
View file @
9c1e734
...
@@ -15,7 +15,8 @@
...
@@ -15,7 +15,8 @@
"lingo"
:
"0.0.x"
,
"lingo"
:
"0.0.x"
,
"validator"
:
"0.3.x"
,
"validator"
:
"0.3.x"
,
"moment"
:
"1.1.x"
,
"moment"
:
"1.1.x"
,
"commander"
:
"0.5.x"
"commander"
:
"0.5.x"
,
"generic-pool"
:
"1.0.9"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"jasmine-node"
:
"1.0.22"
,
"jasmine-node"
:
"1.0.22"
,
...
...
spec-jasmine/config/config.js
View file @
9c1e734
...
@@ -8,7 +8,8 @@ module.exports = {
...
@@ -8,7 +8,8 @@ module.exports = {
password
:
null
,
password
:
null
,
database
:
'sequelize_test'
,
database
:
'sequelize_test'
,
host
:
'127.0.0.1'
,
host
:
'127.0.0.1'
,
port
:
3306
port
:
3306
,
pool
:
{
maxConnections
:
5
,
maxIdleTime
:
30000
}
},
},
sqlite
:
{
sqlite
:
{
...
...
spec-jasmine/mysql/associations.has-many.spec.js
View file @
9c1e734
var
config
=
require
(
"../config/config"
)
var
config
=
require
(
"../config/config"
)
,
Sequelize
=
require
(
"../../index"
)
,
Sequelize
=
require
(
"../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
mysql
.
database
,
config
.
mysql
.
username
,
config
.
mysql
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
mysql
.
database
,
config
.
mysql
.
username
,
config
.
mysql
.
password
,
{
pool
:
config
.
mysql
.
pool
,
logging
:
false
})
,
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
,
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
describe
(
'HasMany'
,
function
()
{
describe
(
'HasMany'
,
function
()
{
...
...
spec-jasmine/mysql/associations.spec.js
View file @
9c1e734
var
config
=
require
(
"../config/config"
)
var
config
=
require
(
"../config/config"
)
,
Sequelize
=
require
(
"../../index"
)
,
Sequelize
=
require
(
"../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
mysql
.
database
,
config
.
mysql
.
username
,
config
.
mysql
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
mysql
.
database
,
config
.
mysql
.
username
,
config
.
mysql
.
password
,
{
pool
:
config
.
mysql
.
pool
,
logging
:
false
})
,
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
,
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
describe
(
'Associations'
,
function
()
{
describe
(
'Associations'
,
function
()
{
...
...
spec-jasmine/mysql/connector-manager.spec.js
View file @
9c1e734
var
config
=
require
(
"../config/config"
)
var
config
=
require
(
"../config/config"
)
,
Sequelize
=
require
(
"../../index"
)
,
Sequelize
=
require
(
"../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
mysql
.
database
,
config
.
mysql
.
username
,
config
.
mysql
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
mysql
.
database
,
config
.
mysql
.
username
,
config
.
mysql
.
password
,
{
pool
:
config
.
mysql
.
pool
,
logging
:
false
})
,
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
,
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
describe
(
'ConnectorManager'
,
function
()
{
describe
(
'ConnectorManager'
,
function
()
{
...
...
spec-jasmine/mysql/dao-factory.spec.js
View file @
9c1e734
var
config
=
require
(
"../config/config"
)
var
config
=
require
(
"../config/config"
)
,
Sequelize
=
require
(
"../../index"
)
,
Sequelize
=
require
(
"../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
mysql
.
database
,
config
.
mysql
.
username
,
config
.
mysql
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
mysql
.
database
,
config
.
mysql
.
username
,
config
.
mysql
.
password
,
{
pool
:
config
.
mysql
.
pool
,
logging
:
false
})
,
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
,
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
describe
(
'DAOFactory'
,
function
()
{
describe
(
'DAOFactory'
,
function
()
{
...
...
spec-jasmine/mysql/query-generator.spec.js
View file @
9c1e734
var
config
=
require
(
"../config/config"
)
var
config
=
require
(
"../config/config"
)
,
Sequelize
=
require
(
"../../index"
)
,
Sequelize
=
require
(
"../../index"
)
,
sequelize
=
new
Sequelize
(
config
.
mysql
.
database
,
config
.
mysql
.
username
,
config
.
mysql
.
password
,
{
logging
:
false
})
,
sequelize
=
new
Sequelize
(
config
.
mysql
.
database
,
config
.
mysql
.
username
,
config
.
mysql
.
password
,
{
pool
:
config
.
mysql
.
pool
,
logging
:
false
})
,
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
,
Helpers
=
new
(
require
(
"../config/helpers"
))(
sequelize
)
,
QueryGenerator
=
require
(
"../../lib/dialects/mysql/query-generator"
)
,
QueryGenerator
=
require
(
"../../lib/dialects/mysql/query-generator"
)
,
util
=
require
(
"util"
)
,
util
=
require
(
"util"
)
describe
(
'QueryGenerator'
,
function
()
{
describe
(
'QueryGenerator'
,
function
()
{
beforeEach
(
function
()
{
Helpers
.
sync
()
})
beforeEach
(
function
()
{
Helpers
.
sync
()
})
...
...
spec/config.js
View file @
9c1e734
...
@@ -2,5 +2,6 @@ module.exports = {
...
@@ -2,5 +2,6 @@ module.exports = {
username
:
"root"
,
username
:
"root"
,
password
:
null
,
password
:
null
,
database
:
'sequelize_test'
,
database
:
'sequelize_test'
,
host
:
'127.0.0.1'
host
:
'127.0.0.1'
,
pool
:
{
maxConnections
:
5
,
maxIdleTime
:
30000
}
}
}
spec/sqlite/dao.spec.js
View file @
9c1e734
if
(
typeof
require
===
'function'
)
{
if
(
typeof
require
===
'function'
)
{
const
buster
=
require
(
"buster"
)
const
buster
=
require
(
"buster"
)
,
Sequelize
=
require
(
"../../index"
)
,
Sequelize
=
require
(
"../../index"
)
,
config
=
require
(
"../config"
)
,
config
=
require
(
"../config"
)
}
}
...
...
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