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 0d0e4c04
authored
Nov 26, 2012
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
only one write
1 parent
609295b0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
20 deletions
lib/dialects/mysql/connector-manager.js
lib/dialects/mysql/connector-manager.js
View file @
0d0e4c0
...
...
@@ -29,17 +29,8 @@ module.exports = (function() {
writes
=
0
;
// Init configs with options from config if not present
for
(
var
i
in
config
.
replication
.
reads
)
{
config
.
replication
.
reads
[
i
]
=
Utils
.
_
.
defaults
(
config
.
replication
.
reads
[
i
],
{
host
:
this
.
config
.
host
,
port
:
this
.
config
.
port
,
user
:
this
.
config
.
username
,
password
:
this
.
config
.
password
,
database
:
this
.
config
.
database
});
}
for
(
var
j
in
config
.
replication
.
writes
)
{
config
.
replication
.
writes
[
j
]
=
Utils
.
_
.
defaults
(
config
.
replication
.
writes
[
j
],
{
for
(
var
i
in
config
.
replication
.
read
)
{
config
.
replication
.
read
[
i
]
=
Utils
.
_
.
defaults
(
config
.
replication
.
read
[
i
],
{
host
:
this
.
config
.
host
,
port
:
this
.
config
.
port
,
user
:
this
.
config
.
username
,
...
...
@@ -47,11 +38,18 @@ module.exports = (function() {
database
:
this
.
config
.
database
});
}
config
.
replication
.
write
=
Utils
.
_
.
defaults
(
config
.
replication
.
write
,
{
host
:
this
.
config
.
host
,
port
:
this
.
config
.
port
,
user
:
this
.
config
.
username
,
password
:
this
.
config
.
password
,
database
:
this
.
config
.
database
});
// I'll make my own pool, with blackjack and hookers!
this
.
pool
=
{
release
:
function
(
client
)
{
if
(
client
.
queryType
==
'
SELECT
'
)
{
if
(
client
.
queryType
==
'
read
'
)
{
return
this
.
read
.
release
(
client
);
}
else
{
return
this
.
write
.
release
(
client
);
...
...
@@ -71,10 +69,11 @@ module.exports = (function() {
read
:
Pooling
.
Pool
({
name
:
'sequelize-read'
,
create
:
function
(
done
)
{
if
(
reads
>=
self
.
config
.
replication
.
read
s
.
length
)
reads
=
0
;
var
config
=
self
.
config
.
replication
.
read
s
[
reads
++
];
if
(
reads
>=
self
.
config
.
replication
.
read
.
length
)
reads
=
0
;
var
config
=
self
.
config
.
replication
.
read
[
reads
++
];
var
connection
=
mysql
.
createConnection
(
config
)
connection
.
queryType
=
'read'
;
self
.
isConnecting
=
false
done
(
null
,
connection
)
...
...
@@ -89,10 +88,8 @@ module.exports = (function() {
write
:
Pooling
.
Pool
({
name
:
'sequelize-write'
,
create
:
function
(
done
)
{
if
(
writes
>=
self
.
config
.
replication
.
writes
.
length
)
writes
=
0
;
var
config
=
self
.
config
.
replication
.
writes
[
writes
++
];
var
connection
=
mysql
.
createConnection
(
config
)
var
connection
=
mysql
.
createConnection
(
self
.
config
.
replication
.
write
)
connection
.
queryType
=
'write'
;
self
.
isConnecting
=
false
done
(
null
,
connection
)
...
...
@@ -171,7 +168,6 @@ module.exports = (function() {
this
.
pool
.
acquire
(
function
(
err
,
client
)
{
if
(
err
)
return
query
.
emit
(
'error'
,
err
);
client
.
queryType
=
options
.
type
;
query
.
client
=
client
;
query
.
run
(
sql
);
return
;
...
...
@@ -254,7 +250,6 @@ module.exports = (function() {
}
//we set the client here, asynchronously, when getting a pooled connection
//allowing the ConnectorManager.query method to remain synchronous
client
.
queryType
=
options
.
type
;
queueItem
.
query
.
client
=
client
queueItem
.
client
=
client
execQueueItem
.
call
(
self
,
queueItem
)
...
...
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