mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 14:38:50 +00:00
1 line
8.4 KiB
JavaScript
1 line
8.4 KiB
JavaScript
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[7835],{3905:function(e,t,n){n.d(t,{Zo:function(){return c},kt:function(){return d}});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function s(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function i(e,t){if(null==e)return{};var n,a,r=function(e,t){if(null==e)return{};var n,a,r={},o=Object.keys(e);for(a=0;a<o.length;a++)n=o[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a<o.length;a++)n=o[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var l=a.createContext({}),u=function(e){var t=a.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):s(s({},t),e)),n},c=function(e){var t=u(e.components);return a.createElement(l.Provider,{value:t},e.children)},m={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},p=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,o=e.originalType,l=e.parentName,c=i(e,["components","mdxType","originalType","parentName"]),p=u(n),d=r,y=p["".concat(l,".").concat(d)]||p[d]||m[d]||o;return n?a.createElement(y,s(s({ref:t},c),{},{components:n})):a.createElement(y,s({ref:t},c))}));function d(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var o=n.length,s=new Array(o);s[0]=p;var i={};for(var l in t)hasOwnProperty.call(t,l)&&(i[l]=t[l]);i.originalType=e,i.mdxType="string"==typeof e?e:r,s[1]=i;for(var u=2;u<o;u++)s[u]=n[u];return a.createElement.apply(null,s)}return a.createElement.apply(null,n)}p.displayName="MDXCreateElement"},1409:function(e,t,n){n.r(t),n.d(t,{frontMatter:function(){return i},contentTitle:function(){return l},metadata:function(){return u},assets:function(){return c},toc:function(){return m},default:function(){return d}});var a=n(7462),r=n(3366),o=(n(7294),n(3905)),s=["components"],i={},l="Transaction",u={unversionedId:"oxmysql/Usage/transaction",id:"oxmysql/Usage/transaction",title:"Transaction",description:"todo - update formatting and information",source:"@site/docs/oxmysql/Usage/transaction.md",sourceDirName:"oxmysql/Usage",slug:"/oxmysql/Usage/transaction",permalink:"/docs/oxmysql/Usage/transaction",editUrl:"https://github.com/overextended/overextended.github.io/tree/main/docs/oxmysql/Usage/transaction.md",tags:[],version:"current",frontMatter:{},sidebar:"docs",previous:{title:"Single",permalink:"/docs/oxmysql/Usage/single"},next:{title:"Update",permalink:"/docs/oxmysql/Usage/update"}},c={},m=[{value:"Transactions",id:"transactions",level:2},{value:"Specific Format",id:"specific-format",level:3},{value:"Usage",id:"usage",level:3},{value:"Lua",id:"lua",level:4},{value:"JavaScript",id:"javascript",level:4},{value:"Shared Format",id:"shared-format",level:3},{value:"Lua",id:"lua-1",level:4},{value:"JavaScript",id:"javascript-1",level:4},{value:"Transaction Isolation Level",id:"transaction-isolation-level",level:2}],p={toc:m};function d(e){var t=e.components,n=(0,r.Z)(e,s);return(0,o.kt)("wrapper",(0,a.Z)({},p,n,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("h1",{id:"transaction"},"Transaction"),(0,o.kt)("p",null,"todo - update formatting and information"),(0,o.kt)("h2",{id:"transactions"},"Transactions"),(0,o.kt)("p",null,"A transaction executes multiple queries and commits them only if all succeed. If one fails, none of the queries are committed. The return value is a ",(0,o.kt)("inlineCode",{parentName:"p"},"boolean"),", which is the result of the transaction."),(0,o.kt)("h3",{id:"specific-format"},"Specific Format"),(0,o.kt)("p",null,"When using the ",(0,o.kt)("inlineCode",{parentName:"p"},"Specific")," format you must pass one parameter to the oxmysql export. In this case, the ",(0,o.kt)("inlineCode",{parentName:"p"},"queries")," parameter contains your queries and the SQL variables unique to each query."),(0,o.kt)("p",null,"This is useful for transactions where the queries do not share many SQL variables."),(0,o.kt)("h3",{id:"usage"},"Usage"),(0,o.kt)("h4",{id:"lua"},"Lua"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-lua"},"local queries = {\n { query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { ['someid'] = 1 } },\n { query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { ['someid'] = 2 } }\n} -- NOTE, the 'values' tables can be named 'parameters' here for MySQL-Async compatibility.\n\n-- Async\nexports.oxmysql:transaction(queries, function(result) \n print(result) \nend)\n\n-- Sync\nlocal result = exports.oxmysql:transactionSync(queries)\nprint(result)\n")),(0,o.kt)("h4",{id:"javascript"},"JavaScript"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-js"},"const queries = [\n { query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { someid = 1 } },\n { query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { someid = 2 } }\n] // NOTE, the 'values' objects can be named 'parameters' here for MySQL-Async compatibility.\n\n// Async\nexports.oxmysql.transaction(queries, (result) => {\n console.log(result)\n})\n\n// Sync\nconst result = await exports.oxmysql.transactionSync(queries)\nconsole.log(result)\n")),(0,o.kt)("h3",{id:"shared-format"},"Shared Format"),(0,o.kt)("p",null,"When using the ",(0,o.kt)("inlineCode",{parentName:"p"},"Shared")," format you must pass two parameters to the oxmysql export. The ",(0,o.kt)("inlineCode",{parentName:"p"},"queries")," and the ",(0,o.kt)("inlineCode",{parentName:"p"},"parameters")," those queries will use.",(0,o.kt)("br",{parentName:"p"}),"\n","This is useful if your queries use the same SQL variables."),(0,o.kt)("h4",{id:"lua-1"},"Lua"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-lua"},"local queries = {\n 'INSERT INTO `test` (id, name) VALUES (:someid, :somename)',\n 'SET `name` = :newname IN `test` WHERE `id` = :someid'\n}\n\nlocal parameters = { ['someid'] = 2, ['somename'] = 'John Doe', ['newname'] = 'John Notdoe' }\n\n-- Async\nexports.oxmysql:transaction(queries, parameters, function(result) \n print(result) \nend)\n\n-- Sync\nlocal result = exports.oxmysql:transactionSync(queries, parameters)\nprint(result)\n")),(0,o.kt)("h4",{id:"javascript-1"},"JavaScript"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-js"},"const queries = [\n 'INSERT INTO `test` (id, name) VALUES (:someid, :somename)',\n 'SET `name` = :newname IN `test` WHERE `id` = :someid'\n]\n\nconst parameters = { someid = 2, somename = 'John Doe', newname = 'John Notdoe' }\n\n// Async\nexports.oxmysql.transaction(queries, parameters, (result) => {\n console.log(result)\n})\n\n// Sync\nconst result = await exports.oxmysql.transactionSync(queries, parameters)\nconsole.log(result)\n")),(0,o.kt)("h2",{id:"transaction-isolation-level"},"Transaction Isolation Level"),(0,o.kt)("p",null,"This can be set through the convar ",(0,o.kt)("inlineCode",{parentName:"p"},"mysql_transaction_isolation_level")," which should be an integer ranging from ",(0,o.kt)("inlineCode",{parentName:"p"},"1-4"),". The default convar value set by oxmysql is ",(0,o.kt)("inlineCode",{parentName:"p"},"2"),"."),(0,o.kt)("table",null,(0,o.kt)("thead",{parentName:"table"},(0,o.kt)("tr",{parentName:"thead"},(0,o.kt)("th",{parentName:"tr",align:null},"Convar Value"),(0,o.kt)("th",{parentName:"tr",align:null},"Result"))),(0,o.kt)("tbody",{parentName:"table"},(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"1"),(0,o.kt)("td",{parentName:"tr",align:null},"Repeatable Read")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"2"),(0,o.kt)("td",{parentName:"tr",align:null},"Read Committed")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"3"),(0,o.kt)("td",{parentName:"tr",align:null},"Read Uncommitted")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"4"),(0,o.kt)("td",{parentName:"tr",align:null},"Serializable")))))}d.isMDXComponent=!0}}]); |