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 de1d3e9d
authored
Jan 27, 2015
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'little-big-h-master'
2 parents
6ecece9a
1497e0dc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
5 deletions
lib/dialects/sqlite/connection-manager.js
test/integration/transaction.test.js
lib/dialects/sqlite/connection-manager.js
View file @
de1d3e9
...
@@ -11,6 +11,9 @@ ConnectionManager = function(dialect, sequelize) {
...
@@ -11,6 +11,9 @@ ConnectionManager = function(dialect, sequelize) {
this
.
dialect
=
dialect
;
this
.
dialect
=
dialect
;
this
.
connections
=
{};
this
.
connections
=
{};
// We attempt to parse file location from a connection uri but we shouldn't match sequelize default host.
if
(
this
.
sequelize
.
options
.
host
===
'localhost'
)
delete
this
.
sequelize
.
options
.
host
;
try
{
try
{
this
.
lib
=
require
(
sequelize
.
config
.
dialectModulePath
||
'sqlite3'
).
verbose
();
this
.
lib
=
require
(
sequelize
.
config
.
dialectModulePath
||
'sqlite3'
).
verbose
();
}
catch
(
err
)
{
}
catch
(
err
)
{
...
@@ -24,16 +27,17 @@ ConnectionManager.prototype.getConnection = function(options) {
...
@@ -24,16 +27,17 @@ ConnectionManager.prototype.getConnection = function(options) {
var
self
=
this
;
var
self
=
this
;
options
=
options
||
{};
options
=
options
||
{};
options
.
uuid
=
options
.
uuid
||
'default'
;
options
.
uuid
=
options
.
uuid
||
'default'
;
options
.
inMemory
=
((
self
.
sequelize
.
options
.
storage
||
self
.
sequelize
.
options
.
host
||
':memory:'
)
===
':memory:'
)
?
1
:
0
;
if
(
self
.
connections
[
options
.
uuid
])
return
Promise
.
resolve
(
self
.
connections
[
options
.
uuid
]);
if
(
self
.
connections
[
options
.
inMemory
||
options
.
uuid
])
return
Promise
.
resolve
(
self
.
connections
[
options
.
inMemory
||
options
.
uuid
]);
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
self
.
connections
[
options
.
uuid
]
=
new
self
.
lib
.
Database
(
self
.
sequelize
.
options
.
storage
||
self
.
sequelize
.
options
.
host
||
':memory:'
,
function
(
err
)
{
self
.
connections
[
options
.
inMemory
||
options
.
uuid
]
=
new
self
.
lib
.
Database
(
self
.
sequelize
.
options
.
storage
||
self
.
sequelize
.
options
.
host
||
':memory:'
,
function
(
err
)
{
if
(
err
)
{
if
(
err
)
{
if
(
err
.
code
===
'SQLITE_CANTOPEN'
)
return
reject
(
new
sequelizeErrors
.
ConnectionError
(
err
));
if
(
err
.
code
===
'SQLITE_CANTOPEN'
)
return
reject
(
new
sequelizeErrors
.
ConnectionError
(
err
));
return
reject
(
new
sequelizeErrors
.
ConnectionError
(
err
));
return
reject
(
new
sequelizeErrors
.
ConnectionError
(
err
));
}
}
resolve
(
self
.
connections
[
options
.
uuid
]);
resolve
(
self
.
connections
[
options
.
inMemory
||
options
.
uuid
]);
});
});
}).
tap
(
function
(
connection
)
{
}).
tap
(
function
(
connection
)
{
if
(
self
.
sequelize
.
options
.
foreignKeys
!==
false
)
{
if
(
self
.
sequelize
.
options
.
foreignKeys
!==
false
)
{
...
@@ -44,9 +48,12 @@ ConnectionManager.prototype.getConnection = function(options) {
...
@@ -44,9 +48,12 @@ ConnectionManager.prototype.getConnection = function(options) {
});
});
};
};
ConnectionManager
.
prototype
.
releaseConnection
=
function
(
connection
)
{
ConnectionManager
.
prototype
.
releaseConnection
=
function
(
connection
,
force
)
{
if
(
connection
.
filename
===
":memory:"
&&
force
!==
true
)
return
;
if
(
connection
.
uuid
)
{
if
(
connection
.
uuid
)
{
connection
.
close
();
connection
.
close
();
delete
this
.
connections
[
connection
.
uuid
];
}
}
};
};
...
...
test/integration/transaction.test.js
View file @
de1d3e9
...
@@ -86,8 +86,41 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
...
@@ -86,8 +86,41 @@ describe(Support.getTestDialectTeaser('Transaction'), function() {
).
to
.
eventually
.
be
.
rejected
;
).
to
.
eventually
.
be
.
rejected
;
});
});
if
(
dialect
===
'sqlite'
){
it
(
'provides persistent transactions'
,
function
()
{
var
sequelize
=
new
Support
.
Sequelize
(
'database'
,
'username'
,
'password'
,
{
dialect
:
'sqlite'
}),
User
=
sequelize
.
define
(
'user'
,
{
username
:
Support
.
Sequelize
.
STRING
,
awesome
:
Support
.
Sequelize
.
BOOLEAN
});
return
sequelize
.
transaction
()
.
then
(
function
(
t
)
{
return
sequelize
.
sync
({
transaction
:
t
})
.
then
(
function
(
)
{
return
t
;
});
})
.
then
(
function
(
t
)
{
return
User
.
create
({},
{
transaction
:
t
})
.
then
(
function
(
)
{
t
.
commit
();
});
})
.
then
(
function
(
)
{
return
sequelize
.
transaction
();
})
.
then
(
function
(
t
)
{
return
User
.
findAll
({},
{
transaction
:
t
});
})
.
then
(
function
(
users
)
{
return
expect
(
users
.
length
).
to
.
equal
(
1
);
});
});
}
if
(
current
.
dialect
.
supports
.
lock
)
{
if
(
current
.
dialect
.
supports
.
lock
)
{
describe
(
'row locking'
,
function
()
{
describe
(
'row locking'
,
function
()
{
this
.
timeout
(
10000
);
this
.
timeout
(
10000
);
it
(
'supports for update'
,
function
(
done
)
{
it
(
'supports for update'
,
function
(
done
)
{
var
User
=
this
.
sequelize
.
define
(
'user'
,
{
var
User
=
this
.
sequelize
.
define
(
'user'
,
{
...
...
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