Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit 5b76dcb

Browse files
committed
feat: add startTransaction to library
This feature never received any feedback ¯\_(ツ)_/¯
1 parent 287542d commit 5b76dcb

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

lib/MySQL.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,8 @@ MySQL.ready = setmetatable({
148148
end,
149149
})
150150

151+
function MySQL.startTransaction(cb)
152+
return oxmysql:startTransaction(cb, resourceName)
153+
end
154+
151155
_ENV.MySQL = MySQL

lib/MySQL.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ interface OxMySQL {
4444
transaction: (query: Transaction, params?: Params | Callback<boolean>, cb?: Callback<boolean>) => Promise<boolean>;
4545
isReady: () => boolean;
4646
awaitConnection: () => Promise<true>;
47+
startTransaction: (
48+
cb: (query: <T = Result | null>(statement: string, params?: Params) => Promise<T>) => Promise<boolean | void>
49+
) => Promise<boolean>;
4750
}
4851

4952
const QueryStore: string[] = [];
@@ -158,4 +161,7 @@ export const oxmysql: OxMySQL = {
158161
async awaitConnection() {
159162
return await exp.awaitConnection();
160163
},
164+
async startTransaction(cb) {
165+
return exp.experimentalTransaction(cb, currentResourceName);
166+
},
161167
};

src/index.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,13 @@ MySQL.transaction = (
7878
rawTransaction(invokingResource, queries, parameters, cb, isPromise);
7979
};
8080

81-
global.exports(
82-
'experimentalTransaction',
83-
async (
84-
transactions: () => Promise<boolean>,
85-
cb: CFXCallback,
86-
invokingResource = GetInvokingResource(),
87-
isPromise?: boolean
88-
) => {
89-
return await startTransaction(invokingResource, transactions, cb, isPromise);
90-
}
91-
);
81+
MySQL.startTransaction = (
82+
transactions: () => Promise<boolean>,
83+
invokingResource = GetInvokingResource()
84+
) => {
85+
console.warn(`MySQL.startTransaction is "experimental" and may receive breaking changes.`)
86+
return startTransaction(invokingResource, transactions, undefined, true);
87+
};
9288

9389
MySQL.prepare = (
9490
query: string,

0 commit comments

Comments
 (0)