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 c2cbd591
authored
May 05, 2019
by
Erik Seliger
Committed by
Simon Schick
Jun 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: modernize connections handling in sqlite (#10894)
1 parent
ceb4b679
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
lib/dialects/sqlite/connection-manager.js
lib/dialects/sqlite/connection-manager.js
View file @
c2cbd59
...
@@ -17,14 +17,16 @@ class ConnectionManager extends AbstractConnectionManager {
...
@@ -17,14 +17,16 @@ class ConnectionManager extends AbstractConnectionManager {
delete
this
.
sequelize
.
options
.
host
;
delete
this
.
sequelize
.
options
.
host
;
}
}
this
.
connections
=
{}
;
this
.
connections
=
new
Map
()
;
this
.
lib
=
this
.
_loadDialectModule
(
'sqlite3'
).
verbose
();
this
.
lib
=
this
.
_loadDialectModule
(
'sqlite3'
).
verbose
();
this
.
refreshTypeParser
(
dataTypes
);
this
.
refreshTypeParser
(
dataTypes
);
}
}
_onProcessExit
()
{
_onProcessExit
()
{
const
promises
=
Object
.
getOwnPropertyNames
(
this
.
connections
)
const
promises
=
[];
.
map
(
connection
=>
Promise
.
fromCallback
(
callback
=>
this
.
connections
[
connection
].
close
(
callback
)));
for
(
const
conn
of
this
.
connections
.
values
())
{
promises
.
push
(
Promise
.
fromCallback
(
callback
=>
conn
.
close
(
callback
)));
}
return
Promise
return
Promise
.
all
(
promises
)
.
all
(
promises
)
...
@@ -38,20 +40,20 @@ class ConnectionManager extends AbstractConnectionManager {
...
@@ -38,20 +40,20 @@ class ConnectionManager extends AbstractConnectionManager {
const
dialectOptions
=
this
.
sequelize
.
options
.
dialectOptions
;
const
dialectOptions
=
this
.
sequelize
.
options
.
dialectOptions
;
options
.
readWriteMode
=
dialectOptions
&&
dialectOptions
.
mode
;
options
.
readWriteMode
=
dialectOptions
&&
dialectOptions
.
mode
;
if
(
this
.
connections
[
options
.
inMemory
||
options
.
uuid
]
)
{
if
(
this
.
connections
.
has
(
options
.
inMemory
||
options
.
uuid
)
)
{
return
Promise
.
resolve
(
this
.
connections
[
options
.
inMemory
||
options
.
uuid
]
);
return
Promise
.
resolve
(
this
.
connections
.
get
(
options
.
inMemory
||
options
.
uuid
)
);
}
}
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
connections
[
options
.
inMemory
||
options
.
uuid
]
=
new
this
.
lib
.
Database
(
this
.
connections
.
set
(
options
.
inMemory
||
options
.
uuid
,
new
this
.
lib
.
Database
(
this
.
sequelize
.
options
.
storage
||
this
.
sequelize
.
options
.
host
||
':memory:'
,
this
.
sequelize
.
options
.
storage
||
this
.
sequelize
.
options
.
host
||
':memory:'
,
options
.
readWriteMode
||
this
.
lib
.
OPEN_READWRITE
|
this
.
lib
.
OPEN_CREATE
,
// default mode
options
.
readWriteMode
||
this
.
lib
.
OPEN_READWRITE
|
this
.
lib
.
OPEN_CREATE
,
// default mode
err
=>
{
err
=>
{
if
(
err
)
return
reject
(
new
sequelizeErrors
.
ConnectionError
(
err
));
if
(
err
)
return
reject
(
new
sequelizeErrors
.
ConnectionError
(
err
));
debug
(
`connection acquired
${
options
.
uuid
}
`
);
debug
(
`connection acquired
${
options
.
uuid
}
`
);
resolve
(
this
.
connections
[
options
.
inMemory
||
options
.
uuid
]
);
resolve
(
this
.
connections
.
get
(
options
.
inMemory
||
options
.
uuid
)
);
}
}
);
)
)
;
}).
tap
(
connection
=>
{
}).
tap
(
connection
=>
{
if
(
this
.
sequelize
.
config
.
password
)
{
if
(
this
.
sequelize
.
config
.
password
)
{
// Make it possible to define and use password for sqlite encryption plugin like sqlcipher
// Make it possible to define and use password for sqlite encryption plugin like sqlcipher
...
@@ -71,7 +73,7 @@ class ConnectionManager extends AbstractConnectionManager {
...
@@ -71,7 +73,7 @@ class ConnectionManager extends AbstractConnectionManager {
if
(
connection
.
uuid
)
{
if
(
connection
.
uuid
)
{
connection
.
close
();
connection
.
close
();
debug
(
`connection released
${
connection
.
uuid
}
`
);
debug
(
`connection released
${
connection
.
uuid
}
`
);
delete
this
.
connections
[
connection
.
uuid
]
;
this
.
connections
.
delete
(
connection
.
uuid
)
;
}
}
}
}
}
}
...
...
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