Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
NPM Packages
js-db
Commits
a0d32c21
Commit
a0d32c21
authored
Mar 28, 2020
by
Milan Wikarski
Browse files
BEGIN and COMMIT changes
parent
0c69c357
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/database.class.js
View file @
a0d32c21
...
...
@@ -96,9 +96,7 @@ class Database {
throw
new
Error
(
'
A transaction is already active
'
);
}
return
this
.
query
(
'
BEGIN
'
)
.
execute
()
.
then
(()
=>
(
this
.
_transaction
=
true
));
return
this
.
query
(
'
BEGIN
'
);
}
/**
...
...
@@ -106,14 +104,12 @@ class Database {
*
* @returns {Promise.<Boolean>} success
*/
commit
()
{
async
commit
()
{
if
(
!
this
.
_transaction
)
{
throw
new
Error
(
'
No transaction is active
'
);
}
return
this
.
query
(
'
COMMIT
'
)
.
execute
()
.
then
(()
=>
(
this
.
_transaction
=
false
));
return
this
.
query
(
'
COMMIT
'
);
}
}
...
...
tests/test.js
View file @
a0d32c21
...
...
@@ -46,7 +46,7 @@ const del = async () => {
};
const
update
=
async
()
=>
{
await
db
.
begin
();
console
.
log
(
await
db
.
begin
()
)
;
console
.
log
(
'
UPDATE
'
);
const
update
=
db
...
...
@@ -61,7 +61,7 @@ const update = async () => {
console
.
log
(
update
.
err
);
}
await
db
.
commit
();
console
.
log
(
await
db
.
commit
()
)
;
};
(
async
()
=>
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment