refs #5595 taking active connection
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alexandre Riera 2023-05-30 09:49:39 +02:00
parent 54eb0fc7a2
commit 153542d2be
3 changed files with 41 additions and 19 deletions

View File

@ -196,20 +196,48 @@ module.exports = function(Self) {
/*
* Shortcut to VnMySQL.executeP()
*/
rawSql(query, params, options, cb) {
async rawSql(query, params, options) {
const userId = options?.userId;
if (userId) {
params.unshift(userId);
return this.dataSource.connector.executeP(
`CALL account.myUser_loginWithName((SELECT name FROM account.user WHERE id = ?));
${query};
CALL account.myUser_logout();`,
params,
options,
cb
);
const connector = this.dataSource.connector;
let conn;
let res;
const opts = Object.assign({}, options);
try {
if (userId) {
conn = await new Promise((resolve, reject) => {
connector.client.getConnection(function(err, conn) {
if (err)
reject(err);
else
resolve(conn);
});
});
const opts = Object.assign({}, options);
if (!opts.transaction) {
opts.transaction = {
connection: conn,
connector
};
}
await connector.executeP(
'CALL account.myUser_loginWithName((SELECT name FROM account.user WHERE id = ?))',
[userId], opts
);
}
res = await connector.executeP(query, params, opts);
if (userId) {
await connector.executeP('CALL account.myUser_logout()', null, opts);
}
} finally {
if (conn) conn.release();
}
return this.dataSource.connector.executeP(query, params, options, cb);
return res;
},
/*

View File

@ -17,12 +17,6 @@ class VnMySQL extends MySQL {
executeP(query, params, options = {}, cb) {
return new Promise((resolve, reject) => {
this.execute(query, params, options, (error, response) => {
if(options?.userId)
{
response.shift(); // Remove OkPacket from logIn
response.pop(); // Remove OkPacket from logOut
response = response[response.length - 1] // Keep only query response
}
if (cb)
cb(error, response);
if (error)

View File

@ -32,7 +32,7 @@ module.exports = Self => {
Self.saveSign = async(ctx, options) => {
const args = Object.assign({}, ctx.args);
const models = Self.app.models;
const myOptions = {};
const myOptions = {userId: ctx.req.accessToken.userId};
let tx;
let dms;
let gestDocCreated = false;