Skip to content

Commit

Permalink
Merge branch 'master' of github.com:marpple/FxSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
shine1594 committed May 21, 2020
2 parents c406a67 + ae48db6 commit 185c9ec
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,14 @@ function BASE({
const pool = create_pool(connection_info);
const pool_query = query_fn(pool);

async function base_query(excute_query, texts, values) {
async function base_query(excute_query, texts, values, transaction_querys) {
try {
var query = replace_q(_SQL(texts, values));
if (Array.isArray(transaction_querys)) transaction_querys.push({
text: query.text,
values: JSON.stringify(query.values),
stack: new Error().stack
});
return await go(
is_injection(query) ? Promise.reject('INJECTION ERROR') : query,
tap(function(query) {
Expand Down Expand Up @@ -486,18 +491,17 @@ function BASE({
try {
const client = await get_connection(pool);
const client_query = query_fn(client);
const querys = [];
const transaction_querys = [];
await BEGIN(client);
function QUERY(texts, ...values) {
querys.push([texts.join('?'), values]);
return base_query(client_query, texts, values);
return base_query(client_query, texts, values, transaction_querys);
}
const QUERY1 = pipe(QUERY, first),
ASSOCIATE = baseAssociate(QUERY),
ASSOCIATE1 = pipe(ASSOCIATE, first);
await baseTransactionQuery(QUERY, QUERY1);
client.on('error', err => {
transactionErrorHandler(err, client, querys);
transactionErrorHandler(err, client, transaction_querys);
});
return {
client,
Expand All @@ -507,8 +511,16 @@ function BASE({
ASSOCIATE,
ASSOCIATE1,
LJOIN: use_ljoin && ljoin ? await ljoin(QUERY) : null,
COMMIT: _ => COMMIT(client),
ROLLBACK: _ => ROLLBACK(client)
COMMIT: _ => {
const { stack } = new Error();
transaction_querys.push({ query: 'COMMIT', VALUES: [], stack });
return COMMIT(client);
},
ROLLBACK: _ => {
const { stack } = new Error();
transaction_querys.push({ query: 'ROLLBACK', VALUES: [], stack });
return ROLLBACK(client);
}
}
} catch (e) { throw e; }
}
Expand Down

0 comments on commit 185c9ec

Please sign in to comment.