Skip to content

Commit

Permalink
feat: add startTransaction to library
Browse files Browse the repository at this point in the history
This feature never received any feedback ¯\_(ツ)_/¯
  • Loading branch information
thelindat committed Oct 1, 2024
1 parent 287542d commit 5b76dcb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions lib/MySQL.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,8 @@ MySQL.ready = setmetatable({
end,
})

function MySQL.startTransaction(cb)
return oxmysql:startTransaction(cb, resourceName)
end

_ENV.MySQL = MySQL
6 changes: 6 additions & 0 deletions lib/MySQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ interface OxMySQL {
transaction: (query: Transaction, params?: Params | Callback<boolean>, cb?: Callback<boolean>) => Promise<boolean>;
isReady: () => boolean;
awaitConnection: () => Promise<true>;
startTransaction: (
cb: (query: <T = Result | null>(statement: string, params?: Params) => Promise<T>) => Promise<boolean | void>
) => Promise<boolean>;
}

const QueryStore: string[] = [];
Expand Down Expand Up @@ -158,4 +161,7 @@ export const oxmysql: OxMySQL = {
async awaitConnection() {
return await exp.awaitConnection();
},
async startTransaction(cb) {
return exp.experimentalTransaction(cb, currentResourceName);
},
};
18 changes: 7 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,13 @@ MySQL.transaction = (
rawTransaction(invokingResource, queries, parameters, cb, isPromise);
};

global.exports(
'experimentalTransaction',
async (
transactions: () => Promise<boolean>,
cb: CFXCallback,
invokingResource = GetInvokingResource(),
isPromise?: boolean
) => {
return await startTransaction(invokingResource, transactions, cb, isPromise);
}
);
MySQL.startTransaction = (
transactions: () => Promise<boolean>,
invokingResource = GetInvokingResource()
) => {
console.warn(`MySQL.startTransaction is "experimental" and may receive breaking changes.`)
return startTransaction(invokingResource, transactions, undefined, true);
};

MySQL.prepare = (
query: string,
Expand Down

0 comments on commit 5b76dcb

Please sign in to comment.