mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-01 22:21:51 +00:00
refactor(db/startTransaction): use internal query functions
Some changes to function signature and callback. Make null-returns commit changes rather than rollback.
This commit is contained in:
1 parent
a876f92ead
commit
123a003332
4 files changed
+35
-31
No files matched your search
+14
-10
@@ -14,7 +14,8 @@ export const rawQuery = async (
|
||||
query: string,
|
||||
parameters: CFXParameters,
|
||||
cb?: CFXCallback,
|
||||
isPromise?: boolean
|
||||
isPromise?: boolean,
|
||||
connectionId?: number
|
||||
) => {
|
||||
cb = setCallback(parameters, cb);
|
||||
try {
|
||||
@@ -23,7 +24,7 @@ export const rawQuery = async (
|
||||
return logError(invokingResource, cb, err, isPromise, query, parameters);
|
||||
}
|
||||
|
||||
const connection = await getPoolConnection();
|
||||
const connection = await getPoolConnection(connectionId);
|
||||
|
||||
if (!connection) return;
|
||||
|
||||
@@ -42,16 +43,19 @@ export const rawQuery = async (
|
||||
logQuery(invokingResource, query, performance.now() - startTime, parameters);
|
||||
}
|
||||
|
||||
if (cb)
|
||||
try {
|
||||
cb(parseResponse(type, result));
|
||||
} catch (err) {
|
||||
if (typeof err === 'string') {
|
||||
if (err.includes('SCRIPT ERROR:')) return console.log(err);
|
||||
console.log(`^1SCRIPT ERROR in invoking resource ${invokingResource}: ${err}^0`);
|
||||
}
|
||||
if (!cb) return parseResponse(type, result);
|
||||
|
||||
try {
|
||||
cb(parseResponse(type, result));
|
||||
} catch (err) {
|
||||
if (typeof err === 'string') {
|
||||
if (err.includes('SCRIPT ERROR:')) return console.log(err);
|
||||
console.log(`^1SCRIPT ERROR in invoking resource ${invokingResource}: ${err}^0`);
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
if (!cb) throw new Error(err.message || err);
|
||||
|
||||
logError(invokingResource, cb, isPromise, err, query, parameters, true);
|
||||
} finally {
|
||||
connection.release();
|
||||
|
||||
Reference in new issue
Block a user