-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
format insert into expression (#104)
* format insert into expression * 2.14.5
- Loading branch information
1 parent
9409f74
commit 37fe140
Showing
6 changed files
with
210 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export class CancelTransactionError extends Error { | ||
constructor() { | ||
super(); | ||
} | ||
} | ||
/** | ||
* | ||
* @param {import('@themost/common').DataAdapterBase} db | ||
* @param {function():Promise<void>} func | ||
* @returns | ||
*/ | ||
export function executeInTransactionAsync(db, func) { | ||
return new Promise((resolve, reject) => { | ||
// start transaction | ||
db.executeInTransaction((cb) => { | ||
try { | ||
func().then(() => { | ||
return cb(new CancelTransactionError()); | ||
}).catch( err => { | ||
return cb(err); | ||
}); | ||
} | ||
catch (err) { | ||
return cb(err); | ||
} | ||
|
||
}, err => { | ||
// if error is an instance of CancelTransactionError | ||
if (err && err instanceof CancelTransactionError) { | ||
return resolve(); | ||
} | ||
if (err) { | ||
return reject(err); | ||
} | ||
// exit | ||
return resolve(); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters