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 d559bcfb
authored
Jul 15, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #211 from megshark/master
Add pooling support for postgres
2 parents
559069e4
d9781b31
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
7 deletions
lib/dialects/postgres/connector-manager.js
spec-jasmine/config/config.js
lib/dialects/postgres/connector-manager.js
View file @
d559bcf
var
Query
=
require
(
"./query"
)
,
Utils
=
require
(
"../../utils"
)
,
pg
=
require
(
"pg"
)
,
without
=
function
(
arr
,
elem
)
{
return
arr
.
filter
(
function
(
e
)
{
return
e
!=
elem
})
}
module
.
exports
=
(
function
()
{
...
...
@@ -7,6 +8,12 @@ module.exports = (function() {
this
.
sequelize
=
sequelize
this
.
client
=
null
this
.
config
=
config
||
{}
this
.
pooling
=
(
this
.
config
.
poolCfg
!=
null
&&
this
.
config
.
poolCfg
.
maxConnections
>
0
)
// set pooling parameters if specified
if
(
this
.
pooling
)
{
pg
.
defaults
.
poolSize
=
this
.
config
.
poolCfg
.
maxConnections
pg
.
defaults
.
poolIdleTimeout
=
this
.
config
.
poolCfg
.
maxIdleTime
}
this
.
disconnectTimeoutId
=
null
this
.
pendingQueries
=
0
this
.
maxConcurrentQueries
=
(
this
.
config
.
maxConcurrentQueries
||
50
)
...
...
@@ -44,12 +51,9 @@ module.exports = (function() {
this
.
isConnecting
=
true
this
.
isConnected
=
false
var
pg
=
require
(
"pg"
)
,
uri
=
this
.
sequelize
.
getQueryInterface
().
QueryGenerator
.
databaseConnectionUri
(
this
.
config
)
this
.
client
=
new
pg
.
Client
(
uri
)
var
uri
=
this
.
sequelize
.
getQueryInterface
().
QueryGenerator
.
databaseConnectionUri
(
this
.
config
)
this
.
client
.
connect
(
function
(
err
,
client
)
{
var
connectCallback
=
function
(
err
,
client
)
{
self
.
isConnecting
=
false
if
(
!
err
&&
client
)
{
client
.
query
(
"SET TIME ZONE 'UTC'"
)
...
...
@@ -60,7 +64,17 @@ module.exports = (function() {
}
else
{
this
.
client
=
null
}
})
}
if
(
this
.
pooling
)
{
// acquire client from pool
pg
.
connect
(
uri
,
connectCallback
)
}
else
{
//create one-off client
this
.
client
=
new
pg
.
Client
(
uri
)
this
.
client
.
connect
(
connectCallback
)
}
}
ConnectorManager
.
prototype
.
disconnect
=
function
()
{
...
...
spec-jasmine/config/config.js
View file @
d559bcf
...
...
@@ -19,7 +19,8 @@ module.exports = {
postgres
:
{
database
:
'sequelize_test'
,
username
:
"postgres"
,
port
:
5432
port
:
5432
,
pool
:
{
maxConnections
:
5
,
maxIdleTime
:
30
}
}
}
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