Page Not Found
We could not find what you were looking for.
Please contact the owner of the site that linked you to the original URL and let them know their link is broken.
diff --git a/404.html b/404.html index 30dd316d8a..2473719907 100644 --- a/404.html +++ b/404.html @@ -2,10 +2,10 @@
- -We could not find what you were looking for.
Please contact the owner of the site that linked you to the original URL and let them know their link is broken.
["'])(?.*?)\1/,ue=/\{(? [\d,-]+)\}/,me={js:{start:"\\/\\/",end:""},jsBlock:{start:"\\/\\*",end:"\\*\\/"},jsx:{start:"\\{\\s*\\/\\*",end:"\\*\\/\\s*\\}"},bash:{start:"#",end:""},html:{start:"\x3c!--",end:"--\x3e"},lua:{start:"--",end:""},wasm:{start:"\\;\\;",end:""},tex:{start:"%",end:""}};function he(e,t){const n=e.map((e=>{const{start:n,end:s}=me[e];return`(?:${n}\\s*(${t.flatMap((e=>[e.line,e.block?.start,e.block?.end].filter(Boolean))).join("|")})\\s*${s})`})).join("|");return new RegExp(`^\\s*(?:${n})\\s*$`)}function pe(e,t){let n=e.replace(/\n$/,"");const{language:s,magicComments:a,metastring:o}=t;if(o&&ue.test(o)){const e=o.match(ue).groups.range;if(0===a.length)throw new Error(`A highlight range has been given in code block's metastring (\`\`\` ${o}), but no magic comment config is available. Docusaurus applies the first magic comment entry's className for metastring ranges.`);const t=a[0].className,s=re()(e).filter((e=>e>0)).map((e=>[e-1,[t]]));return{lineClassNames:Object.fromEntries(s),code:n}}if(void 0===s)return{lineClassNames:{},code:n};const i=function(e,t){switch(e){case"js":case"javascript":case"ts":case"typescript":return he(["js","jsBlock"],t);case"jsx":case"tsx":return he(["js","jsBlock","jsx"],t);case"html":return he(["js","jsBlock","html"],t);case"python":case"py":case"bash":return he(["bash"],t);case"markdown":case"md":return he(["html","jsx","bash"],t);case"tex":case"latex":case"matlab":return he(["tex"],t);case"lua":case"haskell":case"sql":return he(["lua"],t);case"wasm":return he(["wasm"],t);default:return he(Object.keys(me).filter((e=>!["lua","wasm","tex","latex","matlab"].includes(e))),t)}}(s,a),l=n.split("\n"),c=Object.fromEntries(a.map((e=>[e.className,{start:0,range:""}]))),r=Object.fromEntries(a.filter((e=>e.line)).map((e=>{let{className:t,line:n}=e;return[n,t]}))),d=Object.fromEntries(a.filter((e=>e.block)).map((e=>{let{className:t,block:n}=e;return[n.start,t]}))),u=Object.fromEntries(a.filter((e=>e.block)).map((e=>{let{className:t,block:n}=e;return[n.end,t]})));for(let h=0;h void 0!==e));r[t]?c[r[t]].range+=`${h},`:d[t]?c[d[t]].start=h:u[t]&&(c[u[t]].range+=`${c[u[t]].start}-${h-1},`),l.splice(h,1)}n=l.join("\n");const m={};return Object.entries(c).forEach((e=>{let[t,{range:n}]=e;re()(n).forEach((e=>{m[e]??=[],m[e].push(t)}))})),{lineClassNames:m,code:n}}const fe={codeBlockContainer:"codeBlockContainer_Ckt0"};function xe(e){let{as:t,...n}=e;const s=function(e){const t={color:"--prism-color",backgroundColor:"--prism-background-color"},n={};return Object.entries(e.plain).forEach((e=>{let[s,a]=e;const o=t[s];o&&"string"==typeof a&&(n[o]=a)})),n}(le());return(0,i.jsx)(t,{...n,style:s,className:(0,u.Z)(n.className,fe.codeBlockContainer,b.k.common.codeBlock)})}const be={codeBlockContent:"codeBlockContent_biex",codeBlockTitle:"codeBlockTitle_Ktv7",codeBlock:"codeBlock_bY9V",codeBlockStandalone:"codeBlockStandalone_MEMb",codeBlockLines:"codeBlockLines_e6Vv",codeBlockLinesWithNumbering:"codeBlockLinesWithNumbering_o6Pm",buttonGroup:"buttonGroup__atx"};function ge(e){let{children:t,className:n}=e;return(0,i.jsx)(xe,{as:"pre",tabIndex:0,className:(0,u.Z)(be.codeBlockStandalone,"thin-scrollbar",n),children:(0,i.jsx)("code",{className:be.codeBlockLines,children:t})})}const je={attributes:!0,characterData:!0,childList:!0,subtree:!0};function ve(e,t){const[n,a]=(0,s.useState)(),i=(0,s.useCallback)((()=>{a(e.current?.closest("[role=tabpanel][hidden]"))}),[e,a]);(0,s.useEffect)((()=>{i()}),[i]),function(e,t,n){void 0===n&&(n=je);const a=(0,o.zX)(t),i=(0,o.Ql)(n);(0,s.useEffect)((()=>{const t=new MutationObserver(a);return e&&t.observe(e,i),()=>t.disconnect()}),[e,a,i])}(n,(e=>{e.forEach((e=>{"attributes"===e.type&&"hidden"===e.attributeName&&(t(),i())}))}),{attributes:!0,characterData:!1,childList:!1,subtree:!1})}var Ne=n(2573);const Ce={codeLine:"codeLine_lJS_",codeLineNumber:"codeLineNumber_Tfdd",codeLineContent:"codeLineContent_feaV"};function ke(e){let{line:t,classNames:n,showLineNumbers:s,getLineProps:a,getTokenProps:o}=e;1===t.length&&"\n"===t[0].content&&(t[0].content="");const l=a({line:t,className:(0,u.Z)(n,s&&Ce.codeLine)}),c=t.map(((e,t)=>(0,i.jsx)("span",{...o({token:e,key:t})},t)));return(0,i.jsxs)("span",{...l,children:[s?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("span",{className:Ce.codeLineNumber}),(0,i.jsx)("span",{className:Ce.codeLineContent,children:c})]}):c,(0,i.jsx)("br",{})]})}function Le(e){return(0,i.jsx)("svg",{viewBox:"0 0 24 24",...e,children:(0,i.jsx)("path",{fill:"currentColor",d:"M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"})})}function ye(e){return(0,i.jsx)("svg",{viewBox:"0 0 24 24",...e,children:(0,i.jsx)("path",{fill:"currentColor",d:"M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"})})}const we={copyButtonCopied:"copyButtonCopied_obH4",copyButtonIcons:"copyButtonIcons_eSgA",copyButtonIcon:"copyButtonIcon_y97N",copyButtonSuccessIcon:"copyButtonSuccessIcon_LjdS"};function Be(e){let{code:t,className:n}=e;const[a,o]=(0,s.useState)(!1),l=(0,s.useRef)(void 0),c=(0,s.useCallback)((()=>{!function(e,t){let{target:n=document.body}=void 0===t?{}:t;if("string"!=typeof e)throw new TypeError(`Expected parameter \`text\` to be a \`string\`, got \`${typeof e}\`.`);const s=document.createElement("textarea"),a=document.activeElement;s.value=e,s.setAttribute("readonly",""),s.style.contain="strict",s.style.position="absolute",s.style.left="-9999px",s.style.fontSize="12pt";const o=document.getSelection(),i=o.rangeCount>0&&o.getRangeAt(0);n.append(s),s.select(),s.selectionStart=0,s.selectionEnd=e.length;let l=!1;try{l=document.execCommand("copy")}catch{}s.remove(),i&&(o.removeAllRanges(),o.addRange(i)),a&&a.focus()}(t),o(!0),l.current=window.setTimeout((()=>{o(!1)}),1e3)}),[t]);return(0,s.useEffect)((()=>()=>window.clearTimeout(l.current)),[]),(0,i.jsx)("button",{type:"button","aria-label":a?(0,g.I)({id:"theme.CodeBlock.copied",message:"Copied",description:"The copied button label on code blocks"}):(0,g.I)({id:"theme.CodeBlock.copyButtonAriaLabel",message:"Copy code to clipboard",description:"The ARIA label for copy code blocks button"}),title:(0,g.I)({id:"theme.CodeBlock.copy",message:"Copy",description:"The copy button label on code blocks"}),className:(0,u.Z)("clean-btn",n,we.copyButton,a&&we.copyButtonCopied),onClick:c,children:(0,i.jsxs)("span",{className:we.copyButtonIcons,"aria-hidden":"true",children:[(0,i.jsx)(Le,{className:we.copyButtonIcon}),(0,i.jsx)(ye,{className:we.copyButtonSuccessIcon})]})})}function _e(e){return(0,i.jsx)("svg",{viewBox:"0 0 24 24",...e,children:(0,i.jsx)("path",{fill:"currentColor",d:"M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3l3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"})})}const Ze={wordWrapButtonIcon:"wordWrapButtonIcon_Bwma",wordWrapButtonEnabled:"wordWrapButtonEnabled_EoeP"};function Te(e){let{className:t,onClick:n,isEnabled:s}=e;const a=(0,g.I)({id:"theme.CodeBlock.wordWrapToggle",message:"Toggle word wrap",description:"The title attribute for toggle word wrapping button of code block lines"});return(0,i.jsx)("button",{type:"button",onClick:n,className:(0,u.Z)("clean-btn",t,s&&Ze.wordWrapButtonEnabled),"aria-label":a,title:a,children:(0,i.jsx)(_e,{className:Ze.wordWrapButtonIcon,"aria-hidden":"true"})})}function Ee(e){let{children:t,className:n="",metastring:a,title:o,showLineNumbers:l,language:c}=e;const{prism:{defaultLanguage:r,magicComments:d}}=(0,M.L)(),m=function(e){return e?.toLowerCase()}(c??function(e){const t=e.split(" ").find((e=>e.startsWith("language-")));return t?.replace(/language-/,"")}(n)??r),h=le(),p=function(){const[e,t]=(0,s.useState)(!1),[n,a]=(0,s.useState)(!1),o=(0,s.useRef)(null),i=(0,s.useCallback)((()=>{const n=o.current.querySelector("code");e?n.removeAttribute("style"):(n.style.whiteSpace="pre-wrap",n.style.overflowWrap="anywhere"),t((e=>!e))}),[o,e]),l=(0,s.useCallback)((()=>{const{scrollWidth:e,clientWidth:t}=o.current,n=e>t||o.current.querySelector("code").hasAttribute("style");a(n)}),[o]);return ve(o,l),(0,s.useEffect)((()=>{l()}),[e,l]),(0,s.useEffect)((()=>(window.addEventListener("resize",l,{passive:!0}),()=>{window.removeEventListener("resize",l)})),[l]),{codeBlockRef:o,isEnabled:e,isCodeScrollable:n,toggle:i}}(),f=function(e){return e?.match(de)?.groups.title??""}(a)||o,{lineClassNames:x,code:b}=pe(t,{metastring:a,language:m,magicComments:d}),g=l??function(e){return Boolean(e?.includes("showLineNumbers"))}(a);return(0,i.jsxs)(xe,{as:"div",className:(0,u.Z)(n,m&&!n.includes(`language-${m}`)&&`language-${m}`),children:[f&&(0,i.jsx)("div",{className:be.codeBlockTitle,children:f}),(0,i.jsxs)("div",{className:be.codeBlockContent,children:[(0,i.jsx)(Ne.y$,{theme:h,code:b,language:m??"text",children:e=>{let{className:t,style:n,tokens:s,getLineProps:a,getTokenProps:o}=e;return(0,i.jsx)("pre",{tabIndex:0,ref:p.codeBlockRef,className:(0,u.Z)(t,be.codeBlock,"thin-scrollbar"),style:n,children:(0,i.jsx)("code",{className:(0,u.Z)(be.codeBlockLines,g&&be.codeBlockLinesWithNumbering),children:s.map(((e,t)=>(0,i.jsx)(ke,{line:e,getLineProps:a,getTokenProps:o,classNames:x[t],showLineNumbers:g},t)))})})}}),(0,i.jsxs)("div",{className:be.buttonGroup,children:[(p.isEnabled||p.isCodeScrollable)&&(0,i.jsx)(Te,{className:be.codeButton,onClick:()=>p.toggle(),isEnabled:p.isEnabled}),(0,i.jsx)(Be,{className:be.codeButton,code:b})]})]})]})}function He(e){let{children:t,...n}=e;const a=(0,oe.Z)(),o=function(e){return s.Children.toArray(e).some((e=>(0,s.isValidElement)(e)))?e:Array.isArray(e)?e.join(""):e}(t),l="string"==typeof o?Ee:ge;return(0,i.jsx)(l,{...n,children:o},String(a))}var Ae=n(4673);function Ie(e){const t=s.Children.toArray(e.children),n=t.find((e=>s.isValidElement(e)&&"summary"===e.type)),a=(0,i.jsx)(i.Fragment,{children:t.filter((e=>e!==n))});return(0,i.jsx)(Ae.Z,{...e,summary:n,children:a})}function Me(e){return(0,i.jsx)(ne.Z,{...e})}const Se={containsTaskList:"containsTaskList_mC6p"};function Ue(e){if(void 0!==e)return(0,u.Z)(e,e?.includes("contains-task-list")&&Se.containsTaskList)}const ze={img:"img_ev3q"};function Ve(e){const{mdxAdmonitionTitle:t,rest:n}=function(e){const t=s.Children.toArray(e),n=t.find((e=>s.isValidElement(e)&&"mdxAdmonitionTitle"===e.type)),a=t.filter((e=>e!==n)),o=n?.props.children;return{mdxAdmonitionTitle:o,rest:a.length>0?(0,i.jsx)(i.Fragment,{children:a}):null}}(e.children),a=e.title??t;return{...e,...a&&{title:a},children:n}}const Re={admonition:"admonition_xJq3",admonitionHeading:"admonitionHeading_Gvgb",admonitionIcon:"admonitionIcon_Rf37",admonitionContent:"admonitionContent_BuS1"};function Oe(e){let{type:t,className:n,children:s}=e;return(0,i.jsx)("div",{className:(0,u.Z)(b.k.common.admonition,b.k.common.admonitionType(t),Re.admonition,n),children:s})}function Pe(e){let{icon:t,title:n}=e;return(0,i.jsxs)("div",{className:Re.admonitionHeading,children:[(0,i.jsx)("span",{className:Re.admonitionIcon,children:t}),n]})}function $e(e){let{children:t}=e;return t?(0,i.jsx)("div",{className:Re.admonitionContent,children:t}):null}function De(e){const{type:t,icon:n,title:s,children:a,className:o}=e;return(0,i.jsxs)(Oe,{type:t,className:o,children:[(0,i.jsx)(Pe,{title:s,icon:n}),(0,i.jsx)($e,{children:a})]})}function We(e){return(0,i.jsx)("svg",{viewBox:"0 0 14 16",...e,children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M6.3 5.69a.942.942 0 0 1-.28-.7c0-.28.09-.52.28-.7.19-.18.42-.28.7-.28.28 0 .52.09.7.28.18.19.28.42.28.7 0 .28-.09.52-.28.7a1 1 0 0 1-.7.3c-.28 0-.52-.11-.7-.3zM8 7.99c-.02-.25-.11-.48-.31-.69-.2-.19-.42-.3-.69-.31H6c-.27.02-.48.13-.69.31-.2.2-.3.44-.31.69h1v3c.02.27.11.5.31.69.2.2.42.31.69.31h1c.27 0 .48-.11.69-.31.2-.19.3-.42.31-.69H8V7.98v.01zM7 2.3c-3.14 0-5.7 2.54-5.7 5.68 0 3.14 2.56 5.7 5.7 5.7s5.7-2.55 5.7-5.7c0-3.15-2.56-5.69-5.7-5.69v.01zM7 .98c3.86 0 7 3.14 7 7s-3.14 7-7 7-7-3.12-7-7 3.14-7 7-7z"})})}const Fe={icon:(0,i.jsx)(We,{}),title:(0,i.jsx)(g.Z,{id:"theme.admonition.note",description:"The default label used for the Note admonition (:::note)",children:"note"})};function qe(e){return(0,i.jsx)(De,{...Fe,...e,className:(0,u.Z)("alert alert--secondary",e.className),children:e.children})}function Ge(e){return(0,i.jsx)("svg",{viewBox:"0 0 12 16",...e,children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M6.5 0C3.48 0 1 2.19 1 5c0 .92.55 2.25 1 3 1.34 2.25 1.78 2.78 2 4v1h5v-1c.22-1.22.66-1.75 2-4 .45-.75 1-2.08 1-3 0-2.81-2.48-5-5.5-5zm3.64 7.48c-.25.44-.47.8-.67 1.11-.86 1.41-1.25 2.06-1.45 3.23-.02.05-.02.11-.02.17H5c0-.06 0-.13-.02-.17-.2-1.17-.59-1.83-1.45-3.23-.2-.31-.42-.67-.67-1.11C2.44 6.78 2 5.65 2 5c0-2.2 2.02-4 4.5-4 1.22 0 2.36.42 3.22 1.19C10.55 2.94 11 3.94 11 5c0 .66-.44 1.78-.86 2.48zM4 14h5c-.23 1.14-1.3 2-2.5 2s-2.27-.86-2.5-2z"})})}const Je={icon:(0,i.jsx)(Ge,{}),title:(0,i.jsx)(g.Z,{id:"theme.admonition.tip",description:"The default label used for the Tip admonition (:::tip)",children:"tip"})};function Ye(e){return(0,i.jsx)(De,{...Je,...e,className:(0,u.Z)("alert alert--success",e.className),children:e.children})}function Qe(e){return(0,i.jsx)("svg",{viewBox:"0 0 14 16",...e,children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"})})}const Xe={icon:(0,i.jsx)(Qe,{}),title:(0,i.jsx)(g.Z,{id:"theme.admonition.info",description:"The default label used for the Info admonition (:::info)",children:"info"})};function Ke(e){return(0,i.jsx)(De,{...Xe,...e,className:(0,u.Z)("alert alert--info",e.className),children:e.children})}function et(e){return(0,i.jsx)("svg",{viewBox:"0 0 16 16",...e,children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"})})}const tt={icon:(0,i.jsx)(et,{}),title:(0,i.jsx)(g.Z,{id:"theme.admonition.warning",description:"The default label used for the Warning admonition (:::warning)",children:"warning"})};function nt(e){return(0,i.jsx)("svg",{viewBox:"0 0 12 16",...e,children:(0,i.jsx)("path",{fillRule:"evenodd",d:"M5.05.31c.81 2.17.41 3.38-.52 4.31C3.55 5.67 1.98 6.45.9 7.98c-1.45 2.05-1.7 6.53 3.53 7.7-2.2-1.16-2.67-4.52-.3-6.61-.61 2.03.53 3.33 1.94 2.86 1.39-.47 2.3.53 2.27 1.67-.02.78-.31 1.44-1.13 1.81 3.42-.59 4.78-3.42 4.78-5.56 0-2.84-2.53-3.22-1.25-5.61-1.52.13-2.03 1.13-1.89 2.75.09 1.08-1.02 1.8-1.86 1.33-.67-.41-.66-1.19-.06-1.78C8.18 5.31 8.68 2.45 5.05.32L5.03.3l.02.01z"})})}const st={icon:(0,i.jsx)(nt,{}),title:(0,i.jsx)(g.Z,{id:"theme.admonition.danger",description:"The default label used for the Danger admonition (:::danger)",children:"danger"})};const at={icon:(0,i.jsx)(et,{}),title:(0,i.jsx)(g.Z,{id:"theme.admonition.caution",description:"The default label used for the Caution admonition (:::caution)",children:"caution"})};const ot={...{note:qe,tip:Ye,info:Ke,warning:function(e){return(0,i.jsx)(De,{...tt,...e,className:(0,u.Z)("alert alert--warning",e.className),children:e.children})},danger:function(e){return(0,i.jsx)(De,{...st,...e,className:(0,u.Z)("alert alert--danger",e.className),children:e.children})}},...{secondary:e=>(0,i.jsx)(qe,{title:"secondary",...e}),important:e=>(0,i.jsx)(Ke,{title:"important",...e}),success:e=>(0,i.jsx)(Ye,{title:"success",...e}),caution:function(e){return(0,i.jsx)(De,{...at,...e,className:(0,u.Z)("alert alert--warning",e.className),children:e.children})}}};function it(e){const t=Ve(e),n=(s=t.type,ot[s]||(console.warn(`No admonition component found for admonition type "${s}". Using Info as fallback.`),ot.info));var s;return(0,i.jsx)(n,{...t})}const lt={Head:ae.Z,details:Ie,Details:Ie,code:function(e){return s.Children.toArray(e.children).every((e=>"string"==typeof e&&!e.includes("\n")))?(0,i.jsx)("code",{...e}):(0,i.jsx)(He,{...e})},a:function(e){return(0,i.jsx)(C.Z,{...e})},pre:function(e){return(0,i.jsx)(i.Fragment,{children:e.children})},ul:function(e){return(0,i.jsx)("ul",{...e,className:Ue(e.className)})},img:function(e){return(0,i.jsx)("img",{loading:"lazy",...e,className:(t=e.className,(0,u.Z)(t,ze.img))});var t},h1:e=>(0,i.jsx)(Me,{as:"h1",...e}),h2:e=>(0,i.jsx)(Me,{as:"h2",...e}),h3:e=>(0,i.jsx)(Me,{as:"h3",...e}),h4:e=>(0,i.jsx)(Me,{as:"h4",...e}),h5:e=>(0,i.jsx)(Me,{as:"h5",...e}),h6:e=>(0,i.jsx)(Me,{as:"h6",...e}),admonition:it,mermaid:()=>null};function ct(e){let{children:t}=e;return(0,i.jsx)(se.Z,{components:lt,children:t})}function rt(e){let{children:t}=e;const n=function(){const{metadata:e,frontMatter:t,contentTitle:n}=r();return t.hide_title||void 0!==n?null:e.title}();return(0,i.jsxs)("div",{className:(0,u.Z)(b.k.docs.docMarkdown,"markdown"),children:[n&&(0,i.jsx)("header",{children:(0,i.jsx)(ne.Z,{as:"h1",children:n})}),(0,i.jsx)(ct,{children:t})]})}var dt=n(1310);function ut(){return(0,i.jsx)(g.Z,{id:"theme.unlistedContent.title",description:"The unlisted content banner title",children:"Unlisted page"})}function mt(){return(0,i.jsx)(g.Z,{id:"theme.unlistedContent.message",description:"The unlisted content banner message",children:"This page is unlisted. Search engines will not index it, and only users having a direct link can access it."})}function ht(){return(0,i.jsx)(ae.Z,{children:(0,i.jsx)("meta",{name:"robots",content:"noindex, nofollow"})})}function pt(e){let{className:t}=e;return(0,i.jsx)(it,{type:"caution",title:(0,i.jsx)(ut,{}),className:(0,u.Z)(t,b.k.common.unlistedBanner),children:(0,i.jsx)(mt,{})})}function ft(e){return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(ht,{}),(0,i.jsx)(pt,{...e})]})}const xt={docItemContainer:"docItemContainer_Djhp",docItemCol:"docItemCol_VOVn"};function bt(e){let{children:t}=e;const n=function(){const{frontMatter:e,toc:t}=r(),n=(0,m.i)(),s=e.hide_table_of_contents,a=!s&&t.length>0;return{hidden:s,mobile:a?(0,i.jsx)(Y,{}):void 0,desktop:!a||"desktop"!==n&&"ssr"!==n?void 0:(0,i.jsx)(te,{})}}(),{metadata:{unlisted:s}}=r();return(0,i.jsxs)("div",{className:"row",children:[(0,i.jsxs)("div",{className:(0,u.Z)("col",!n.hidden&&xt.docItemCol),children:[s&&(0,i.jsx)(ft,{}),(0,i.jsx)(f.Z,{}),(0,i.jsxs)("div",{className:xt.docItemContainer,children:[(0,i.jsxs)("article",{children:[(0,i.jsx)(dt.Z,{}),(0,i.jsx)(x.Z,{}),n.mobile,(0,i.jsx)(rt,{children:t}),(0,i.jsx)(A,{})]}),(0,i.jsx)(p,{})]})]}),n.desktop&&(0,i.jsx)("div",{className:"col col--3",children:n.desktop})]})}function gt(e){const t=`docs-doc-id-${e.content.metadata.id}`,n=e.content;return(0,i.jsx)(c,{content:e.content,children:(0,i.jsxs)(a.FG,{className:t,children:[(0,i.jsx)(d,{}),(0,i.jsx)(bt,{children:(0,i.jsx)(n,{})})]})})}},4966:(e,t,n)=>{"use strict";n.d(t,{Z:()=>c});n(7294);var s=n(5999),a=n(512),o=n(9960),i=n(5893);function l(e){const{permalink:t,title:n,subLabel:s,isNext:l}=e;return(0,i.jsxs)(o.Z,{className:(0,a.Z)("pagination-nav__link",l?"pagination-nav__link--next":"pagination-nav__link--prev"),to:t,children:[s&&(0,i.jsx)("div",{className:"pagination-nav__sublabel",children:s}),(0,i.jsx)("div",{className:"pagination-nav__label",children:n})]})}function c(e){const{previous:t,next:n}=e;return(0,i.jsxs)("nav",{className:"pagination-nav docusaurus-mt-lg","aria-label":(0,s.I)({id:"theme.docs.paginator.navAriaLabel",message:"Docs pages",description:"The ARIA label for the docs pagination"}),children:[t&&(0,i.jsx)(l,{...t,subLabel:(0,i.jsx)(s.Z,{id:"theme.docs.paginator.previous",description:"The label used to navigate to the previous doc",children:"Previous"})}),n&&(0,i.jsx)(l,{...n,subLabel:(0,i.jsx)(s.Z,{id:"theme.docs.paginator.next",description:"The label used to navigate to the next doc",children:"Next"}),isNext:!0})]})}},4364:(e,t,n)=>{"use strict";n.d(t,{Z:()=>c});n(7294);var s=n(512),a=n(5999),o=n(5281),i=n(4477),l=n(5893);function c(e){let{className:t}=e;const n=(0,i.E)();return n.badge?(0,l.jsx)("span",{className:(0,s.Z)(t,o.k.docs.docVersionBadge,"badge badge--secondary"),children:(0,l.jsx)(a.Z,{id:"theme.docs.versionBadge.label",values:{versionLabel:n.label},children:"Version: {versionLabel}"})}):null}},3120:(e,t,n)=>{"use strict";n.d(t,{Z:()=>x});n(7294);var s=n(512),a=n(2263),o=n(9960),i=n(5999),l=n(143),c=n(5281),r=n(373),d=n(4477),u=n(5893);const m={unreleased:function(e){let{siteTitle:t,versionMetadata:n}=e;return(0,u.jsx)(i.Z,{id:"theme.docs.versions.unreleasedVersionLabel",description:"The label used to tell the user that he's browsing an unreleased doc version",values:{siteTitle:t,versionLabel:(0,u.jsx)("b",{children:n.label})},children:"This is unreleased documentation for {siteTitle} {versionLabel} version."})},unmaintained:function(e){let{siteTitle:t,versionMetadata:n}=e;return(0,u.jsx)(i.Z,{id:"theme.docs.versions.unmaintainedVersionLabel",description:"The label used to tell the user that he's browsing an unmaintained doc version",values:{siteTitle:t,versionLabel:(0,u.jsx)("b",{children:n.label})},children:"This is documentation for {siteTitle} {versionLabel}, which is no longer actively maintained."})}};function h(e){const t=m[e.versionMetadata.banner];return(0,u.jsx)(t,{...e})}function p(e){let{versionLabel:t,to:n,onClick:s}=e;return(0,u.jsx)(i.Z,{id:"theme.docs.versions.latestVersionSuggestionLabel",description:"The label used to tell the user to check the latest version",values:{versionLabel:t,latestVersionLink:(0,u.jsx)("b",{children:(0,u.jsx)(o.Z,{to:n,onClick:s,children:(0,u.jsx)(i.Z,{id:"theme.docs.versions.latestVersionLinkLabel",description:"The label used for the latest version suggestion link label",children:"latest version"})})})},children:"For up-to-date documentation, see the {latestVersionLink} ({versionLabel})."})}function f(e){let{className:t,versionMetadata:n}=e;const{siteConfig:{title:o}}=(0,a.Z)(),{pluginId:i}=(0,l.gA)({failfast:!0}),{savePreferredVersionName:d}=(0,r.J)(i),{latestDocSuggestion:m,latestVersionSuggestion:f}=(0,l.Jo)(i),x=m??(b=f).docs.find((e=>e.id===b.mainDocId));var b;return(0,u.jsxs)("div",{className:(0,s.Z)(t,c.k.docs.docVersionBanner,"alert alert--warning margin-bottom--md"),role:"alert",children:[(0,u.jsx)("div",{children:(0,u.jsx)(h,{siteTitle:o,versionMetadata:n})}),(0,u.jsx)("div",{className:"margin-top--md",children:(0,u.jsx)(p,{versionLabel:f.label,to:x.path,onClick:()=>d(f.name)})})]})}function x(e){let{className:t}=e;const n=(0,d.E)();return n.banner?(0,u.jsx)(f,{className:t,versionMetadata:n}):null}},7594:(e,t)=>{function n(e){let t,n=[];for(let s of e.split(",").map((e=>e.trim())))if(/^-?\d+$/.test(s))n.push(parseInt(s,10));else if(t=s.match(/^(-?\d+)(-|\.\.\.?|\u2025|\u2026|\u22EF)(-?\d+)$/)){let[e,s,a,o]=t;if(s&&o){s=parseInt(s),o=parseInt(o);const e=s {"use strict";n.d(t,{Z:()=>l,a:()=>i});var s=n(7294);const a={},o=s.createContext(a);function i(e){const t=s.useContext(o);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:i(e.components),s.createElement(o.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/1a362983.2aad723b.js b/assets/js/1a362983.2aad723b.js deleted file mode 100644 index 9bc264543e..0000000000 --- a/assets/js/1a362983.2aad723b.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[138],{4491:e=>{e.exports=JSON.parse('{"title":"Row Data Packet","slug":"/category/row-data-packet","permalink":"/node-mysql2/docs/category/row-data-packet","navigation":{"previous":{"title":"Procedure Call Packet (Row as Array)","permalink":"/node-mysql2/docs/examples/typescript/procedure-call/row-as-array"},"next":{"title":"Row Data Packet","permalink":"/node-mysql2/docs/examples/typescript/row-data/row-data-packet"}}}')}}]); \ No newline at end of file diff --git a/assets/js/1a4e3797.5fb5e418.js b/assets/js/1a4e3797.5fb5e418.js deleted file mode 100644 index a7600067f6..0000000000 --- a/assets/js/1a4e3797.5fb5e418.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[7920],{2027:(e,t,r)=>{r.r(t),r.d(t,{default:()=>$});var s=r(7294),a=r(2263),n=r(8862),c=r(5742),l=r(9960),o=r(5999);const u=["zero","one","two","few","many","other"];function h(e){return u.filter((t=>e.includes(t)))}const i={locale:"en",pluralForms:h(["one","other"]),select:e=>1===e?"one":"other"};function m(){const{i18n:{currentLocale:e}}=(0,a.Z)();return(0,s.useMemo)((()=>{try{return function(e){const t=new Intl.PluralRules(e);return{locale:e,pluralForms:h(t.resolvedOptions().pluralCategories),select:e=>t.select(e)}}(e)}catch(t){return console.error(`Failed to use Intl.PluralRules for locale "${e}".\nDocusaurus will fallback to the default (English) implementation.\nError: ${t.message}\n`),i}}),[e])}function d(){const e=m();return{selectMessage:(t,r)=>function(e,t,r){const s=e.split("|");if(1===s.length)return s[0];s.length>r.pluralForms.length&&console.error(`For locale=${r.locale}, a maximum of ${r.pluralForms.length} plural forms are expected (${r.pluralForms.join(",")}), but the message contains ${s.length}: ${e}`);const a=r.select(t),n=r.pluralForms.indexOf(a);return s[Math.min(n,s.length-1)]}(r,t,e)}}var p=r(1728),g=r(6550),x=r(2389),f=r(8087);const y=function(){const e=(0,x.Z)(),t=(0,g.k6)(),r=(0,g.TH)(),{siteConfig:{baseUrl:s}}=(0,a.Z)(),n=e?new URLSearchParams(r.search):null,c=n?.get("q")||"",l=n?.get("ctx")||"",o=n?.get("version")||"",u=e=>{const t=new URLSearchParams(r.search);return e?t.set("q",e):t.delete("q"),t};return{searchValue:c,searchContext:l&&Array.isArray(f.Kc)&&f.Kc.some((e=>"string"==typeof e?e===l:e.path===l))?l:"",searchVersion:o,updateSearchPath:e=>{const r=u(e);t.replace({search:r.toString()})},updateSearchContext:e=>{const s=new URLSearchParams(r.search);s.set("ctx",e),t.replace({search:s.toString()})},generateSearchPageLink:e=>{const t=u(e);return`${s}search?${t.toString()}`}}};var S=r(22),C=r(8202),j=r(2539),I=r(726),w=r(1073),v=r(311),R=r(3926);const P={searchContextInput:"searchContextInput_mXoe",searchQueryInput:"searchQueryInput_CFBF",searchResultItem:"searchResultItem_U687",searchResultItemPath:"searchResultItemPath_uIbk",searchResultItemSummary:"searchResultItemSummary_oZHr",searchQueryColumn:"searchQueryColumn_q7nx",searchContextColumn:"searchContextColumn_oWAF"};var b=r(51),_=r(5893);function F(){const{siteConfig:{baseUrl:e},i18n:{currentLocale:t}}=(0,a.Z)(),{selectMessage:r}=d(),{searchValue:n,searchContext:l,searchVersion:u,updateSearchPath:h,updateSearchContext:i}=y(),[m,g]=(0,s.useState)(n),[x,j]=(0,s.useState)(),[I,w]=(0,s.useState)(),R=`${e}${u}`,F=(0,s.useMemo)((()=>m?(0,o.I)({id:"theme.SearchPage.existingResultsTitle",message:'Search results for "{query}"',description:"The search page title for non-empty query"},{query:m}):(0,o.I)({id:"theme.SearchPage.emptyResultsTitle",message:"Search the documentation",description:"The search page title for empty query"})),[m]);(0,s.useEffect)((()=>{h(m),x&&(m?x(m,(e=>{w(e)})):w(void 0))}),[m,x]);const $=(0,s.useCallback)((e=>{g(e.target.value)}),[]);return(0,s.useEffect)((()=>{n&&n!==m&&g(n)}),[n]),(0,s.useEffect)((()=>{!async function(){const{wrappedIndexes:e,zhDictionary:t}=!Array.isArray(f.Kc)||l||f.pQ?await(0,S.w)(R,l):{wrappedIndexes:[],zhDictionary:[]};j((()=>(0,C.v)(e,t,100)))}()}),[l,R]),(0,_.jsxs)(s.Fragment,{children:[(0,_.jsxs)(c.Z,{children:[(0,_.jsx)("meta",{property:"robots",content:"noindex, follow"}),(0,_.jsx)("title",{children:F})]}),(0,_.jsxs)("div",{className:"container margin-vert--lg",children:[(0,_.jsx)("h1",{children:F}),(0,_.jsxs)("div",{className:"row",children:[(0,_.jsx)("div",{className:(0,p.Z)("col",{[P.searchQueryColumn]:Array.isArray(f.Kc),"col--9":Array.isArray(f.Kc),"col--12":!Array.isArray(f.Kc)}),children:(0,_.jsx)("input",{type:"search",name:"q",className:P.searchQueryInput,"aria-label":"Search",onChange:$,value:m,autoComplete:"off",autoFocus:!0})}),Array.isArray(f.Kc)?(0,_.jsx)("div",{className:(0,p.Z)("col","col--3","padding-left--none",P.searchContextColumn),children:(0,_.jsxs)("select",{name:"search-context",className:P.searchContextInput,id:"context-selector",value:l,onChange:e=>i(e.target.value),children:[f.pQ&&(0,_.jsx)("option",{value:"",children:(0,o.I)({id:"theme.SearchPage.searchContext.everywhere",message:"everywhere"})}),f.Kc.map((e=>{const{label:r,path:s}=(0,b._)(e,t);return(0,_.jsx)("option",{value:s,children:r},s)}))]})}):null]}),!x&&m&&(0,_.jsx)("div",{children:(0,_.jsx)(v.Z,{})}),I&&(I.length>0?(0,_.jsx)("p",{children:r(I.length,(0,o.I)({id:"theme.SearchPage.documentsFound.plurals",message:"1 document found|{count} documents found",description:'Pluralized label for "{count} documents found". Use as much plural forms (separated by "|") as your language support (see https://www.unicode.org/cldr/cldr-aux/charts/34/supplemental/language_plural_rules.html)'},{count:I.length}))}):(0,_.jsx)("p",{children:(0,o.I)({id:"theme.SearchPage.noResultsText",message:"No documents were found",description:"The paragraph for empty search result"})})),(0,_.jsx)("section",{children:I&&I.map((e=>(0,_.jsx)(A,{searchResult:e},e.document.i)))})]})]})}function A(e){let{searchResult:{document:t,type:r,page:s,tokens:a,metadata:n}}=e;const c=0===r,o=2===r,u=(c?t.b:s.b).slice(),h=o?t.s:t.t;c||u.push(s.t);let i="";if(f.vc&&a.length>0){const e=new URLSearchParams;for(const t of a)e.append("_highlight",t);i=`?${e.toString()}`}return(0,_.jsxs)("article",{className:P.searchResultItem,children:[(0,_.jsx)("h2",{children:(0,_.jsx)(l.Z,{to:t.u+i+(t.h||""),dangerouslySetInnerHTML:{__html:o?(0,j.C)(h,a):(0,I.o)(h,(0,w.m)(n,"t"),a,100)}})}),u.length>0&&(0,_.jsx)("p",{className:P.searchResultItemPath,children:(0,R.e)(u)}),o&&(0,_.jsx)("p",{className:P.searchResultItemSummary,dangerouslySetInnerHTML:{__html:(0,I.o)(t.t,(0,w.m)(n,"t"),a,100)}})]})}const $=function(){return(0,_.jsx)(n.Z,{children:(0,_.jsx)(F,{})})}}}]); \ No newline at end of file diff --git a/assets/js/1a4e3797.b37fdfae.js b/assets/js/1a4e3797.b37fdfae.js new file mode 100644 index 0000000000..3013e31893 --- /dev/null +++ b/assets/js/1a4e3797.b37fdfae.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[7920],{8824:(e,t,r)=>{r.d(t,{c:()=>u});var s=r(7294),a=r(2263);const n=["zero","one","two","few","many","other"];function c(e){return n.filter((t=>e.includes(t)))}const l={locale:"en",pluralForms:c(["one","other"]),select:e=>1===e?"one":"other"};function o(){const{i18n:{currentLocale:e}}=(0,a.Z)();return(0,s.useMemo)((()=>{try{return function(e){const t=new Intl.PluralRules(e);return{locale:e,pluralForms:c(t.resolvedOptions().pluralCategories),select:e=>t.select(e)}}(e)}catch(t){return console.error(`Failed to use Intl.PluralRules for locale "${e}".\nDocusaurus will fallback to the default (English) implementation.\nError: ${t.message}\n`),l}}),[e])}function u(){const e=o();return{selectMessage:(t,r)=>function(e,t,r){const s=e.split("|");if(1===s.length)return s[0];s.length>r.pluralForms.length&&console.error(`For locale=${r.locale}, a maximum of ${r.pluralForms.length} plural forms are expected (${r.pluralForms.join(",")}), but the message contains ${s.length}: ${e}`);const a=r.select(t),n=r.pluralForms.indexOf(a);return s[Math.min(n,s.length-1)]}(r,t,e)}}},1473:(e,t,r)=>{r.r(t),r.d(t,{default:()=>b});var s=r(7294),a=r(2263),n=r(8862),c=r(5742),l=r(3692),o=r(5999),u=r(8824),h=r(1728),i=r(6550),m=r(2389),d=r(8087);const p=function(){const e=(0,m.Z)(),t=(0,i.k6)(),r=(0,i.TH)(),{siteConfig:{baseUrl:s}}=(0,a.Z)(),n=e?new URLSearchParams(r.search):null,c=n?.get("q")||"",l=n?.get("ctx")||"",o=n?.get("version")||"",u=e=>{const t=new URLSearchParams(r.search);return e?t.set("q",e):t.delete("q"),t};return{searchValue:c,searchContext:l&&Array.isArray(d.Kc)&&d.Kc.some((e=>"string"==typeof e?e===l:e.path===l))?l:"",searchVersion:o,updateSearchPath:e=>{const r=u(e);t.replace({search:r.toString()})},updateSearchContext:e=>{const s=new URLSearchParams(r.search);s.set("ctx",e),t.replace({search:s.toString()})},generateSearchPageLink:e=>{const t=u(e);return`${s}search?${t.toString()}`}}};var g=r(22),x=r(8202),f=r(2539),y=r(726),S=r(1073),C=r(311),j=r(3926);const I={searchContextInput:"searchContextInput_mXoe",searchQueryInput:"searchQueryInput_CFBF",searchResultItem:"searchResultItem_U687",searchResultItemPath:"searchResultItemPath_uIbk",searchResultItemSummary:"searchResultItemSummary_oZHr",searchQueryColumn:"searchQueryColumn_q7nx",searchContextColumn:"searchContextColumn_oWAF"};var w=r(51),v=r(5893);function R(){const{siteConfig:{baseUrl:e},i18n:{currentLocale:t}}=(0,a.Z)(),{selectMessage:r}=(0,u.c)(),{searchValue:n,searchContext:l,searchVersion:i,updateSearchPath:m,updateSearchContext:f}=p(),[y,S]=(0,s.useState)(n),[j,R]=(0,s.useState)(),[b,_]=(0,s.useState)(),F=`${e}${i}`,A=(0,s.useMemo)((()=>y?(0,o.I)({id:"theme.SearchPage.existingResultsTitle",message:'Search results for "{query}"',description:"The search page title for non-empty query"},{query:y}):(0,o.I)({id:"theme.SearchPage.emptyResultsTitle",message:"Search the documentation",description:"The search page title for empty query"})),[y]);(0,s.useEffect)((()=>{m(y),j&&(y?j(y,(e=>{_(e)})):_(void 0))}),[y,j]);const $=(0,s.useCallback)((e=>{S(e.target.value)}),[]);return(0,s.useEffect)((()=>{n&&n!==y&&S(n)}),[n]),(0,s.useEffect)((()=>{!async function(){const{wrappedIndexes:e,zhDictionary:t}=!Array.isArray(d.Kc)||l||d.pQ?await(0,g.w)(F,l):{wrappedIndexes:[],zhDictionary:[]};R((()=>(0,x.v)(e,t,100)))}()}),[l,F]),(0,v.jsxs)(s.Fragment,{children:[(0,v.jsxs)(c.Z,{children:[(0,v.jsx)("meta",{property:"robots",content:"noindex, follow"}),(0,v.jsx)("title",{children:A})]}),(0,v.jsxs)("div",{className:"container margin-vert--lg",children:[(0,v.jsx)("h1",{children:A}),(0,v.jsxs)("div",{className:"row",children:[(0,v.jsx)("div",{className:(0,h.Z)("col",{[I.searchQueryColumn]:Array.isArray(d.Kc),"col--9":Array.isArray(d.Kc),"col--12":!Array.isArray(d.Kc)}),children:(0,v.jsx)("input",{type:"search",name:"q",className:I.searchQueryInput,"aria-label":"Search",onChange:$,value:y,autoComplete:"off",autoFocus:!0})}),Array.isArray(d.Kc)?(0,v.jsx)("div",{className:(0,h.Z)("col","col--3","padding-left--none",I.searchContextColumn),children:(0,v.jsxs)("select",{name:"search-context",className:I.searchContextInput,id:"context-selector",value:l,onChange:e=>f(e.target.value),children:[d.pQ&&(0,v.jsx)("option",{value:"",children:(0,o.I)({id:"theme.SearchPage.searchContext.everywhere",message:"everywhere"})}),d.Kc.map((e=>{const{label:r,path:s}=(0,w._)(e,t);return(0,v.jsx)("option",{value:s,children:r},s)}))]})}):null]}),!j&&y&&(0,v.jsx)("div",{children:(0,v.jsx)(C.Z,{})}),b&&(b.length>0?(0,v.jsx)("p",{children:r(b.length,(0,o.I)({id:"theme.SearchPage.documentsFound.plurals",message:"1 document found|{count} documents found",description:'Pluralized label for "{count} documents found". Use as much plural forms (separated by "|") as your language support (see https://www.unicode.org/cldr/cldr-aux/charts/34/supplemental/language_plural_rules.html)'},{count:b.length}))}):(0,v.jsx)("p",{children:(0,o.I)({id:"theme.SearchPage.noResultsText",message:"No documents were found",description:"The paragraph for empty search result"})})),(0,v.jsx)("section",{children:b&&b.map((e=>(0,v.jsx)(P,{searchResult:e},e.document.i)))})]})]})}function P(e){let{searchResult:{document:t,type:r,page:s,tokens:a,metadata:n}}=e;const c=0===r,o=2===r,u=(c?t.b:s.b).slice(),h=o?t.s:t.t;c||u.push(s.t);let i="";if(d.vc&&a.length>0){const e=new URLSearchParams;for(const t of a)e.append("_highlight",t);i=`?${e.toString()}`}return(0,v.jsxs)("article",{className:I.searchResultItem,children:[(0,v.jsx)("h2",{children:(0,v.jsx)(l.Z,{to:t.u+i+(t.h||""),dangerouslySetInnerHTML:{__html:o?(0,f.C)(h,a):(0,y.o)(h,(0,S.m)(n,"t"),a,100)}})}),u.length>0&&(0,v.jsx)("p",{className:I.searchResultItemPath,children:(0,j.e)(u)}),o&&(0,v.jsx)("p",{className:I.searchResultItemSummary,dangerouslySetInnerHTML:{__html:(0,y.o)(t.t,(0,S.m)(n,"t"),a,100)}})]})}const b=function(){return(0,v.jsx)(n.Z,{children:(0,v.jsx)(R,{})})}}}]); \ No newline at end of file diff --git a/assets/js/1f08bd40.b4d8e865.js b/assets/js/1f08bd40.b4d8e865.js deleted file mode 100644 index aded3e12c0..0000000000 --- a/assets/js/1f08bd40.b4d8e865.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[312],{5467:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>m,frontMatter:()=>u,metadata:()=>i,toc:()=>d});var a=n(5893),r=n(1151),s=n(4866),o=n(5162);const u={},l="Row Data Packet",i={id:"examples/typescript/row-data/row-data-packet",title:"Row Data Packet",description:"",source:"@site/docs/examples/typescript/row-data/00-row-data-packet.mdx",sourceDirName:"examples/typescript/row-data",slug:"/examples/typescript/row-data/row-data-packet",permalink:"/node-mysql2/docs/examples/typescript/row-data/row-data-packet",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/typescript/row-data/00-row-data-packet.mdx",tags:[],version:"current",sidebarPosition:0,frontMatter:{},sidebar:"examples",previous:{title:"Row Data Packet",permalink:"/node-mysql2/docs/category/row-data-packet"},next:{title:"Row Data Packet (Row as Array)",permalink:"/node-mysql2/docs/examples/typescript/row-data/row-as-array"}},c={},d=[];function p(e){const t={code:"code",h1:"h1",pre:"pre",...(0,r.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(t.h1,{id:"row-data-packet",children:"Row Data Packet"}),"\n",(0,a.jsx)(s.Z,{children:(0,a.jsx)(o.Z,{value:"index.ts",default:!0,children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",children:"/**\n * The types are explicity for learning purpose\n * By extending the `RowDataPacket`, you can use your Interface in `query` and `execute`\n */\n\nimport mysql, {\n ConnectionOptions,\n ResultSetHeader,\n RowDataPacket,\n} from 'mysql2/promise';\n\ninterface User extends RowDataPacket {\n id: number;\n name: string;\n}\n\n(async () => {\n const access: ConnectionOptions = {\n host: '',\n user: '',\n password: '',\n database: '',\n };\n\n const conn = await mysql.createConnection(access);\n\n /** Deleting the `users` table, if it exists */\n await conn.query ('DROP TABLE IF EXISTS `users`;');\n\n /** Creating a minimal user table */\n await conn.query (\n 'CREATE TABLE `users` (`id` INT(11) AUTO_INCREMENT, `name` VARCHAR(50), PRIMARY KEY (`id`));'\n );\n\n /** Inserting some users */\n const [inserted] = await conn.execute (\n 'INSERT INTO `users`(`name`) VALUES(?), (?), (?), (?);',\n ['Josh', 'John', 'Marie', 'Gween']\n );\n\n console.log('Inserted:', inserted.affectedRows);\n\n /** Getting users */\n const [users] = await conn.query (\n 'SELECT * FROM `users` ORDER BY `name` ASC;'\n );\n\n users.forEach((user) => {\n console.log('-----------');\n console.log('id: ', user.id);\n console.log('name:', user.name);\n });\n\n await conn.end();\n})();\n\n/** Output\n *\n * Inserted: 4\n * -----------\n * id: 4\n * name: Gween\n * -----------\n * id: 2\n * name: John\n * -----------\n * id: 1\n * name: Josh\n * -----------\n * id: 3\n * name: Marie\n */\n"})})})})]})}function m(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>o});n(7294);var a=n(512);const r={tabItem:"tabItem_Ymn6"};var s=n(5893);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,a.Z)(r.tabItem,o),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>k});var a=n(7294),r=n(512),s=n(2466),o=n(6550),u=n(469),l=n(1980),i=n(7392),c=n(12);function d(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}(n);return function(e){const t=(0,i.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.k6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l._X)(s),(0,a.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(r.location.search);t.set(s,e),r.replace({...r.location,search:t.toString()})}),[s,r])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,s=p(e),[o,l]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:s}))),[i,d]=f({queryString:n,groupId:r}),[h,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,s]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:r}),w=(()=>{const e=i??h;return m({value:e,tabValues:s})?e:null})();(0,u.Z)((()=>{w&&l(w)}),[w]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),b(e)}),[d,b,s]),tabValues:s}}var b=n(2389);const w={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=n(5893);function v(e){let{className:t,block:n,selectedValue:a,selectValue:o,tabValues:u}=e;const l=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.o5)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),r=u[n].value;r!==a&&(i(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":n},t),children:u.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:a===t?0:-1,"aria-selected":a===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...s,className:(0,r.Z)("tabs__item",w.tabItem,s?.className,{"tabs__item--active":a===t}),children:n??t},t)}))})}function g(e){let{lazy:t,children:n,selectedValue:r}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function x(e){const t=h(e);return(0,y.jsxs)("div",{className:(0,r.Z)("tabs-container",w.tabList),children:[(0,y.jsx)(v,{...e,...t}),(0,y.jsx)(g,{...e,...t})]})}function k(e){const t=(0,b.Z)();return(0,y.jsx)(x,{...e,children:d(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>u,a:()=>o});var a=n(7294);const r={},s=a.createContext(r);function o(e){const t=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function u(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),a.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/20afe101.be6389dc.js b/assets/js/20afe101.be6389dc.js new file mode 100644 index 0000000000..721978a0eb --- /dev/null +++ b/assets/js/20afe101.be6389dc.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[1411],{3156:e=>{e.exports=JSON.parse('{"label":"URI","permalink":"/node-mysql2/docs/tags/uri","allTagsPath":"/node-mysql2/docs/tags","count":3,"items":[{"id":"examples/connections/create-connection","title":"createConnection","description":"For queries please see the Simple Queries and Prepared Statements examples.","permalink":"/node-mysql2/docs/examples/connections/create-connection"},{"id":"examples/connections/create-pool","title":"createPool","description":"For queries please see the Simple Queries and Prepared Statements examples.","permalink":"/node-mysql2/docs/examples/connections/create-pool"},{"id":"examples/connections/createPoolCluster","title":"createPoolCluster","description":"For queries please see the Simple Queries and Prepared Statements examples.","permalink":"/node-mysql2/docs/examples/connections/createPoolCluster"}],"unlisted":false}')}}]); \ No newline at end of file diff --git a/assets/js/22161331.bdd78c44.js b/assets/js/22161331.bdd78c44.js new file mode 100644 index 0000000000..06ede7720d --- /dev/null +++ b/assets/js/22161331.bdd78c44.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[556],{7165:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>i,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var r=t(5893),s=t(1151),o=t(4866),a=t(5162);const l={},u="MySQL Proxy",c={id:"examples/tests/mysql-proxy",title:"MySQL Proxy",description:"",source:"@site/docs/examples/tests/mysql-proxy.mdx",sourceDirName:"examples/tests",slug:"/examples/tests/mysql-proxy",permalink:"/node-mysql2/docs/examples/tests/mysql-proxy",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/tests/mysql-proxy.mdx",tags:[],version:"current",frontMatter:{},sidebar:"examples",previous:{title:"await \u2014 co",permalink:"/node-mysql2/docs/examples/promise-wrapper/co-await"},next:{title:"Pool",permalink:"/node-mysql2/docs/examples/tests/pool"}},i={},d=[];function m(e){const n={code:"code",h1:"h1",pre:"pre",...(0,s.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h1,{id:"mysql-proxy",children:"MySQL Proxy"}),"\n",(0,r.jsx)(o.Z,{children:(0,r.jsx)(a.Z,{value:"index.js",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"'use strict';\n\nconst mysql = require('mysql2');\nconst ClientFlags = require('mysql2/lib/constants/client.js');\n\nconst server = mysql.createServer();\nserver.listen(3307);\n\nserver.on('connection', (conn) => {\n console.log('connection');\n\n conn.serverHandshake({\n protocolVersion: 10,\n serverVersion: 'node.js rocks',\n connectionId: 1234,\n statusFlags: 2,\n characterSet: 8,\n capabilityFlags: 0xffffff ^ ClientFlags.COMPRESS,\n });\n\n conn.on('field_list', (table, fields) => {\n console.log('field list:', table, fields);\n conn.writeEof();\n });\n\n const remote = mysql.createConnection({\n user: 'root',\n database: 'dbname',\n host: 'server.example.com',\n password: 'secret',\n });\n\n conn.on('query', (sql) => {\n console.log(`proxying query: ${sql}`);\n remote.query(sql, function (err) {\n // overloaded args, either (err, result :object)\n // or (err, rows :array, columns :array)\n if (Array.isArray(arguments[1])) {\n // response to a 'select', 'show' or similar\n const rows = arguments[1],\n columns = arguments[2];\n console.log('rows', rows);\n console.log('columns', columns);\n conn.writeTextResult(rows, columns);\n } else {\n // response to an 'insert', 'update' or 'delete'\n const result = arguments[1];\n console.log('result', result);\n conn.writeOk(result);\n }\n });\n });\n\n conn.on('end', remote.end.bind(remote));\n});\n"})})})})]})}function p(e={}){const{wrapper:n}={...(0,s.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>a});t(7294);var r=t(512);const s={tabItem:"tabItem_Ymn6"};var o=t(5893);function a(e){let{children:n,hidden:t,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,r.Z)(s.tabItem,a),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>q});var r=t(7294),s=t(512),o=t(2466),a=t(6550),l=t(469),u=t(1980),c=t(7392),i=t(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:n,children:t}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return d(e).map((e=>{let{props:{value:n,label:t,attributes:r,default:s}}=e;return{value:n,label:t,attributes:r,default:s}}))}(t);return function(e){const n=(0,c.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function p(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function f(e){let{queryString:n=!1,groupId:t}=e;const s=(0,a.k6)(),o=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:n,groupId:t});return[(0,u._X)(o),(0,r.useCallback)((e=>{if(!o)return;const n=new URLSearchParams(s.location.search);n.set(o,e),s.replace({...s.location,search:n.toString()})}),[o,s])]}function b(e){const{defaultValue:n,queryString:t=!1,groupId:s}=e,o=m(e),[a,u]=(0,r.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const r=t.find((e=>e.default))??t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:n,tabValues:o}))),[c,d]=f({queryString:t,groupId:s}),[b,h]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[s,o]=(0,i.Nk)(t);return[s,(0,r.useCallback)((e=>{t&&o.set(e)}),[t,o])]}({groupId:s}),y=(()=>{const e=c??b;return p({value:e,tabValues:o})?e:null})();(0,l.Z)((()=>{y&&u(y)}),[y]);return{selectedValue:a,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),h(e)}),[d,h,o]),tabValues:o}}var h=t(2389);const y={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=t(5893);function x(e){let{className:n,block:t,selectedValue:r,selectValue:a,tabValues:l}=e;const u=[],{blockElementScrollPositionUntilNextRender:c}=(0,o.o5)(),i=e=>{const n=e.currentTarget,t=u.indexOf(n),s=l[t].value;s!==r&&(c(n),a(s))},d=e=>{let n=null;switch(e.key){case"Enter":i(e);break;case"ArrowRight":{const t=u.indexOf(e.currentTarget)+1;n=u[t]??u[0];break}case"ArrowLeft":{const t=u.indexOf(e.currentTarget)-1;n=u[t]??u[u.length-1];break}}n?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:o}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===n?0:-1,"aria-selected":r===n,ref:e=>u.push(e),onKeyDown:d,onClick:i,...o,className:(0,s.Z)("tabs__item",y.tabItem,o?.className,{"tabs__item--active":r===n}),children:t??n},n)}))})}function g(e){let{lazy:n,children:t,selectedValue:s}=e;const o=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=o.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:o.map(((e,n)=>(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==s})))})}function w(e){const n=b(e);return(0,v.jsxs)("div",{className:(0,s.Z)("tabs-container",y.tabList),children:[(0,v.jsx)(x,{...e,...n}),(0,v.jsx)(g,{...e,...n})]})}function q(e){const n=(0,h.Z)();return(0,v.jsx)(w,{...e,children:d(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>a});var r=t(7294);const s={},o=r.createContext(s);function a(e){const n=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:a(e.components),r.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2a05ee09.1e59c012.js b/assets/js/2a05ee09.1e59c012.js new file mode 100644 index 0000000000..9acd28eee0 --- /dev/null +++ b/assets/js/2a05ee09.1e59c012.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[2714],{398:e=>{e.exports=JSON.parse('{"label":"SSL","permalink":"/node-mysql2/docs/tags/ssl","allTagsPath":"/node-mysql2/docs/tags","count":3,"items":[{"id":"examples/connections/create-connection","title":"createConnection","description":"For queries please see the Simple Queries and Prepared Statements examples.","permalink":"/node-mysql2/docs/examples/connections/create-connection"},{"id":"examples/connections/create-pool","title":"createPool","description":"For queries please see the Simple Queries and Prepared Statements examples.","permalink":"/node-mysql2/docs/examples/connections/create-pool"},{"id":"examples/connections/createPoolCluster","title":"createPoolCluster","description":"For queries please see the Simple Queries and Prepared Statements examples.","permalink":"/node-mysql2/docs/examples/connections/createPoolCluster"}],"unlisted":false}')}}]); \ No newline at end of file diff --git a/assets/js/2bc14e22.3ce1e359.js b/assets/js/2bc14e22.684b748e.js similarity index 63% rename from assets/js/2bc14e22.3ce1e359.js rename to assets/js/2bc14e22.684b748e.js index 65f0c37d60..b82d00d6db 100644 --- a/assets/js/2bc14e22.3ce1e359.js +++ b/assets/js/2bc14e22.684b748e.js @@ -1,2 +1,2 @@ -/*! For license information please see 2bc14e22.3ce1e359.js.LICENSE.txt */ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[2839],{4760:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>d,contentTitle:()=>o,default:()=>x,frontMatter:()=>a,metadata:()=>i,toc:()=>h});var t=s(5893),r=s(1151),l=s(8609),c=s(3901);const a={},o="Using MySQL2 with TypeScript",i={id:"documentation/typescript-examples",title:"Using MySQL2 with TypeScript",description:"Installation",source:"@site/docs/documentation/typescript-examples.mdx",sourceDirName:"documentation",slug:"/documentation/typescript-examples",permalink:"/node-mysql2/docs/documentation/typescript-examples",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/documentation/typescript-examples.mdx",tags:[],version:"current",frontMatter:{},sidebar:"docs",previous:{title:"Promise Wrappers",permalink:"/node-mysql2/docs/documentation/promise-wrapper"},next:{title:"API and Configuration",permalink:"/node-mysql2/docs/api-and-configurations"}},d={},h=[{value:"Installation",id:"installation",level:2},{value:"Usage",id:"usage",level:2},{value:"Connection",id:"connection",level:3},{value:"Pool Connection",id:"pool-connection",level:3},{value:"Query and Execute",id:"query-and-execute",level:3},{value:"A simple query",id:"a-simple-query",level:4},{value:"Type Specification",id:"type-specification",level:2},{value:"RowDataPacket[]",id:"rowdatapacket",level:3},{value:"RowDataPacket[][]",id:"rowdatapacket-1",level:3},{value:"ResultSetHeader",id:"resultsetheader",level:3},{value:"ResultSetHeader[]",id:"resultsetheader-1",level:3},{value:"ProcedureCallPacket",id:"procedurecallpacket",level:3},{value:"OkPacket",id:"okpacket",level:3},{value:"Examples",id:"examples",level:2}];function u(e){const n={a:"a",admonition:"admonition",blockquote:"blockquote",br:"br",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",h4:"h4",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.h1,{id:"using-mysql2-with-typescript",children:"Using MySQL2 with TypeScript"}),"\n",(0,t.jsx)(n.h2,{id:"installation",children:"Installation"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"npm install --save mysql2\nnpm install --save-dev @types/node\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsxs)(n.p,{children:["The ",(0,t.jsx)(n.code,{children:"@types/node"})," ensure the proper interaction between ",(0,t.jsx)(n.strong,{children:"TypeScript"})," and the ",(0,t.jsx)(n.strong,{children:"Node.js"})," modules used by ",(0,t.jsx)(n.strong,{children:"MySQL2"})," (",(0,t.jsx)(n.em,{children:"net"}),", ",(0,t.jsx)(n.em,{children:"events"}),", ",(0,t.jsx)(n.em,{children:"stream"}),", ",(0,t.jsx)(n.em,{children:"tls"}),", etc.)."]}),"\n"]}),"\n",(0,t.jsx)(n.admonition,{type:"info",children:(0,t.jsxs)(n.p,{children:["Requires ",(0,t.jsx)(n.strong,{children:"TypeScript"})," ",(0,t.jsx)(n.code,{children:">=4.5.2"}),"."]})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,t.jsxs)(n.p,{children:["You can import ",(0,t.jsx)(n.strong,{children:"MySQL2"})," in two ways:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["By setting the ",(0,t.jsx)(n.code,{children:"esModuleInterop"})," option to ",(0,t.jsx)(n.code,{children:"true"})," in ",(0,t.jsx)(n.code,{children:"tsconfig.json"})]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql from 'mysql2';\nimport mysql from 'mysql2/promise';\n"})}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["By setting the ",(0,t.jsx)(n.code,{children:"esModuleInterop"})," option to ",(0,t.jsx)(n.code,{children:"false"})," in ",(0,t.jsx)(n.code,{children:"tsconfig.json"})]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import * as mysql from 'mysql2';\nimport * as mysql from 'mysql2/promise';\n"})}),"\n",(0,t.jsx)(n.h3,{id:"connection",children:"Connection"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { ConnectionOptions } from 'mysql2';\n\nconst access: ConnectionOptions = {\n user: 'test',\n database: 'test',\n};\n\nconst conn = mysql.createConnection(access);\n"})}),"\n",(0,t.jsx)(n.h3,{id:"pool-connection",children:"Pool Connection"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { PoolOptions } from 'mysql2';\n\nconst access: PoolOptions = {\n user: 'test',\n database: 'test',\n};\n\nconst conn = mysql.createPool(access);\n"})}),"\n",(0,t.jsx)(n.h3,{id:"query-and-execute",children:"Query and Execute"}),"\n",(0,t.jsx)(n.h4,{id:"a-simple-query",children:"A simple query"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"conn.query('SELECT 1 + 1 AS `test`;', (_err, rows) => {\n /**\n * @rows: [ { test: 2 } ]\n */\n});\n\nconn.execute('SELECT 1 + 1 AS `test`;', (_err, rows) => {\n /**\n * @rows: [ { test: 2 } ]\n */\n});\n"})}),"\n",(0,t.jsxs)(n.p,{children:["The ",(0,t.jsx)(n.code,{children:"rows"})," output will be these possible types:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.code,{children:"RowDataPacket[]"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.code,{children:"RowDataPacket[][]"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.code,{children:"ResultSetHeader"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.code,{children:"ResultSetHeader[]"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.code,{children:"ProcedureCallPacket"})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"In this example, you need to manually check the output types"}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h2,{id:"type-specification",children:"Type Specification"}),"\n",(0,t.jsx)(n.h3,{id:"rowdatapacket",children:"RowDataPacket[]"}),"\n",(0,t.jsx)(c.X,{level:2}),"\n",(0,t.jsx)(n.p,{children:"An array with the returned rows, for example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { RowDataPacket } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n});\n\n// SELECT\nconn.query ('SELECT 1 + 1 AS `test`;', (_err, rows) => {\n console.log(rows);\n /**\n * @rows: [ { test: 2 } ]\n */\n});\n\n// SHOW\nconn.query ('SHOW TABLES FROM `test`;', (_err, rows) => {\n console.log(rows);\n /**\n * @rows: [ { Tables_in_test: 'test' } ]\n */\n});\n"})}),"\n",(0,t.jsxs)(n.p,{children:["Using ",(0,t.jsx)(n.code,{children:"rowsAsArray"})," option as ",(0,t.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { RowDataPacket } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n rowsAsArray: true,\n});\n\n// SELECT\nconn.query (\n 'SELECT 1 + 1 AS test, 2 + 2 AS test;',\n (_err, rows) => {\n console.log(rows);\n /**\n * @rows: [ [ 2, 4 ] ]\n */\n }\n);\n\n// SHOW\nconn.query ('SHOW TABLES FROM `test`;', (_err, rows) => {\n console.log(rows);\n /**\n * @rows: [ [ 'test' ] ]\n */\n});\n"})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"rowdatapacket-1",children:"RowDataPacket[][]"}),"\n",(0,t.jsx)(c.X,{level:2}),"\n",(0,t.jsxs)(n.p,{children:["Using ",(0,t.jsx)(n.code,{children:"multipleStatements"})," option as ",(0,t.jsx)(n.code,{children:"true"})," with multiple queries:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { RowDataPacket } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n multipleStatements: true,\n});\n\nconst sql = `\n SELECT 1 + 1 AS test;\n SELECT 2 + 2 AS test;\n`;\n\nconn.query (sql, (_err, rows) => {\n console.log(rows);\n /**\n * @rows: [ [ { test: 2 } ], [ { test: 4 } ] ]\n */\n});\n"})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"resultsetheader",children:"ResultSetHeader"}),"\n",(0,t.jsx)(c.X,{level:2}),"\n",(0,t.jsx)(l.A,{records:[{version:"3.5.1",changes:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.strong,{children:"OkPacket"})," is deprecated and might be removed in the future major release.",(0,t.jsx)(n.br,{}),"Please use ",(0,t.jsx)(n.strong,{children:"ResultSetHeader"})," instead."]}),(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.strong,{children:"changedRows"})," option is deprecated and might be removed in the future major release.",(0,t.jsx)(n.br,{}),"Please use ",(0,t.jsx)(n.strong,{children:"affectedRows"})," instead."]})]}]}),"\n",(0,t.jsxs)(n.p,{children:["For ",(0,t.jsx)(n.code,{children:"INSERT"}),", ",(0,t.jsx)(n.code,{children:"UPDATE"}),", ",(0,t.jsx)(n.code,{children:"DELETE"}),", ",(0,t.jsx)(n.code,{children:"TRUNCATE"}),", etc.:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { ResultSetHeader } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n});\n\nconst sql = `\n SET @1 = 1;\n`;\n\nconn.query (sql, (_err, result) => {\n console.log(result);\n /**\n * @result: ResultSetHeader {\n fieldCount: 0,\n affectedRows: 0,\n insertId: 0,\n info: '',\n serverStatus: 2,\n warningStatus: 0,\n changedRows: 0\n }\n */\n});\n"})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"resultsetheader-1",children:"ResultSetHeader[]"}),"\n",(0,t.jsx)(c.X,{level:2}),"\n",(0,t.jsx)(l.A,{records:[{version:"3.5.1",changes:[(0,t.jsxs)(t.Fragment,{children:["Introduce ",(0,t.jsx)(n.strong,{children:"ResultSetHeader[]"})]})]}]}),"\n",(0,t.jsxs)(n.p,{children:["For multiples ",(0,t.jsx)(n.code,{children:"INSERT"}),", ",(0,t.jsx)(n.code,{children:"UPDATE"}),", ",(0,t.jsx)(n.code,{children:"DELETE"}),", ",(0,t.jsx)(n.code,{children:"TRUNCATE"}),", etc. when using ",(0,t.jsx)(n.code,{children:"multipleStatements"})," as ",(0,t.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { ResultSetHeader } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n multipleStatements: true,\n});\n\nconst sql = `\n SET @1 = 1;\n SET @2 = 2;\n`;\n\nconn.query (sql, (_err, results) => {\n console.log(results);\n /**\n * @results: [\n ResultSetHeader {\n fieldCount: 0,\n affectedRows: 0,\n insertId: 0,\n info: '',\n serverStatus: 10,\n warningStatus: 0,\n changedRows: 0\n },\n ResultSetHeader {\n fieldCount: 0,\n affectedRows: 0,\n insertId: 0,\n info: '',\n serverStatus: 2,\n warningStatus: 0,\n changedRows: 0\n }\n ]\n */\n});\n"})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"procedurecallpacket",children:"ProcedureCallPacket"}),"\n",(0,t.jsx)(c.X,{level:2}),"\n",(0,t.jsx)(l.A,{records:[{version:"3.5.1",changes:[(0,t.jsxs)(t.Fragment,{children:["Introduce ",(0,t.jsx)(n.strong,{children:"ProcedureCallPacket"})]})]}]}),"\n",(0,t.jsx)(n.admonition,{type:"tip",children:(0,t.jsxs)(n.p,{children:["By performing a ",(0,t.jsx)(n.strong,{children:"Call Procedure"})," using ",(0,t.jsx)(n.code,{children:"INSERT"}),", ",(0,t.jsx)(n.code,{children:"UPDATE"}),", etc., the return will be a ",(0,t.jsx)(n.code,{children:"ProcedureCallPacket "})," (even if you perform multiples queries and set ",(0,t.jsx)(n.code,{children:"multipleStatements"})," to ",(0,t.jsx)(n.code,{children:"true"}),"):"]})}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { ProcedureCallPacket, ResultSetHeader } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n});\n\n/** ResultSetHeader */\nconn.query('DROP PROCEDURE IF EXISTS myProcedure');\n\n/** ResultSetHeader */\nconn.query(`\n CREATE PROCEDURE myProcedure()\n BEGIN\n SET @1 = 1;\n SET @2 = 2;\n END\n `);\n\n/** ProcedureCallPacket */\nconst sql = 'CALL myProcedure()';\n\nconn.query >(sql, (_err, result) => {\n console.log(result);\n /**\n * @result: ResultSetHeader {\n fieldCount: 0,\n affectedRows: 0,\n insertId: 0,\n info: '',\n serverStatus: 2,\n warningStatus: 0,\n changedRows: 0\n }\n */\n});\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsxs)(n.p,{children:["For ",(0,t.jsx)(n.code,{children:"CREATE PROCEDURE"})," and ",(0,t.jsx)(n.code,{children:"DROP PROCEDURE"}),", these returns will be the ",(0,t.jsx)(n.em,{children:"default"})," ",(0,t.jsx)(n.code,{children:"ResultSetHeader"}),"."]}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:["By using ",(0,t.jsx)(n.code,{children:"SELECT"})," and ",(0,t.jsx)(n.code,{children:"SHOW"})," queries in a ",(0,t.jsx)(n.strong,{children:"Procedure Call"}),", it groups the results as:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-tsx",children:"/** ProcedureCallPacket */\n[RowDataPacket[], ResultSetHeader]\n"})}),"\n",(0,t.jsxs)(n.p,{children:["For ",(0,t.jsx)(n.code,{children:"ProcedureCallPacket "}),", please see the following examples."]}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"okpacket",children:"OkPacket"}),"\n",(0,t.jsx)(c.X,{level:0,message:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.strong,{children:"OkPacket"})," is deprecated and might be removed in the future major release.",(0,t.jsx)(n.br,{}),"Please use ",(0,t.jsx)(n.strong,{children:"ResultSetHeader"})," instead."]})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h2,{id:"examples",children:"Examples"}),"\n",(0,t.jsxs)(n.p,{children:["You can also check some code examples using ",(0,t.jsx)(n.strong,{children:"MySQL2"})," and ",(0,t.jsx)(n.strong,{children:"TypeScript"})," to understand advanced concepts:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/row-data/row-data-packet",children:["Extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/row-data/row-as-array",children:["Extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"})," and ",(0,t.jsx)(n.code,{children:"rowAsArray"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/row-data/multi-statements",children:["Extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"})," and ",(0,t.jsx)(n.code,{children:"multipleStatements"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/row-data/row-as-array-multi-statements",children:["Extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"}),", ",(0,t.jsx)(n.code,{children:"rowAsArray"})," and ",(0,t.jsx)(n.code,{children:"multipleStatements"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/procedure-call/procedure-call-packet",children:["Checking for ",(0,t.jsx)(n.code,{children:"ResultSetHeader"}),", extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"})," from ",(0,t.jsx)(n.code,{children:"ProcedureCallPacket"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/procedure-call/row-as-array",children:["Checking for ",(0,t.jsx)(n.code,{children:"ResultSetHeader"}),", extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"})," and ",(0,t.jsx)(n.code,{children:"rowAsArray"})," from ",(0,t.jsx)(n.code,{children:"ProcedureCallPacket"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/basic-custom-class",children:["Creating a basic custom ",(0,t.jsx)(n.strong,{children:"MySQL2"})," ",(0,t.jsx)(n.strong,{children:"Class"})]})}),"\n"]})]})}function x(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(u,{...e})}):u(e)}},4673:(e,n,s)=>{s.d(n,{Z:()=>p});var t=s(7294),r=s(512),l=s(2389),c=s(6043);const a={details:"details_lb9f",isBrowser:"isBrowser_bmU9",collapsibleContent:"collapsibleContent_i85q"};var o=s(5893);function i(e){return!!e&&("SUMMARY"===e.tagName||i(e.parentElement))}function d(e,n){return!!e&&(e===n||d(e.parentElement,n))}function h(e){let{summary:n,children:s,...h}=e;const u=(0,l.Z)(),x=(0,t.useRef)(null),{collapsed:p,setCollapsed:j}=(0,c.u)({initialState:!h.open}),[m,y]=(0,t.useState)(h.open),g=t.isValidElement(n)?n:(0,o.jsx)("summary",{children:n??"Details"});return(0,o.jsxs)("details",{...h,ref:x,open:m,"data-collapsed":p,className:(0,r.Z)(a.details,u&&a.isBrowser,h.className),onMouseDown:e=>{i(e.target)&&e.detail>1&&e.preventDefault()},onClick:e=>{e.stopPropagation();const n=e.target;i(n)&&d(n,x.current)&&(e.preventDefault(),p?(j(!1),y(!0)):j(!0))},children:[g,(0,o.jsx)(c.z,{lazy:!1,collapsed:p,disableSSRStyle:!0,onCollapseTransitionEnd:e=>{j(e),y(!e)},children:(0,o.jsx)("div",{className:a.collapsibleContent,children:s})})]})}const u={details:"details_b_Ee"},x="alert alert--info";function p(e){let{...n}=e;return(0,o.jsx)(h,{...n,className:(0,r.Z)(x,u.details,n.className)})}},8609:(e,n,s)=>{s.d(n,{A:()=>c});var t=s(4673);const r=(0,s(4297).Z)("FileClock",[["path",{d:"M16 22h2c.5 0 1-.2 1.4-.6.4-.4.6-.9.6-1.4V7.5L14.5 2H6c-.5 0-1 .2-1.4.6C4.2 3 4 3.5 4 4v3",key:"9lo3o3"}],["polyline",{points:"14 2 14 8 20 8",key:"1ew0cm"}],["circle",{cx:"8",cy:"16",r:"6",key:"10v15b"}],["path",{d:"M9.5 17.5 8 16.25V14",key:"1o80t2"}]]);var l=s(5893);const c=e=>{let{records:n,open:s}=e;return(0,l.jsx)(t.Z,{open:s,summary:(0,l.jsxs)("summary",{children:[(0,l.jsx)(r,{})," History"]}),className:"history",children:(0,l.jsxs)("table",{children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{children:"Version"}),(0,l.jsx)("th",{children:"Changes"})]})}),(0,l.jsx)("tbody",{children:n.map(((e,n)=>(0,l.jsxs)("tr",{children:[(0,l.jsx)("td",{children:(0,l.jsxs)("strong",{children:["v",e.version.replace(/[^0-9.]/g,"")]})}),(0,l.jsx)("td",{children:(0,l.jsx)("div",{className:"changes",children:e.changes.map(((e,n)=>(0,l.jsx)("section",{children:e},`change:${n}`)))})})]},`record:${n}`)))})]})})}},3901:(e,n,s)=>{s.d(n,{X:()=>u});var t=s(9960),r=s(4297);const l=(0,r.Z)("AlertTriangle",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z",key:"c3ski4"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]),c=(0,r.Z)("Lightbulb",[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]]),a=(0,r.Z)("Microscope",[["path",{d:"M6 18h8",key:"1borvv"}],["path",{d:"M3 22h18",key:"8prr45"}],["path",{d:"M14 22a7 7 0 1 0 0-14h-1",key:"1jwaiy"}],["path",{d:"M9 14h2",key:"197e7h"}],["path",{d:"M9 12a2 2 0 0 1-2-2V6h6v4a2 2 0 0 1-2 2Z",key:"1bmzmy"}],["path",{d:"M12 6V3a1 1 0 0 0-1-1H9a1 1 0 0 0-1 1v3",key:"1drr47"}]]),o=(0,r.Z)("PackageSearch",[["path",{d:"M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14",key:"e7tb2h"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["line",{x1:"12",x2:"12",y1:"22",y2:"12",key:"a4e8g8"}],["circle",{cx:"18.5",cy:"15.5",r:"2.5",key:"b5zd12"}],["path",{d:"M20.27 17.27 22 19",key:"1l4muz"}]]),i=(0,r.Z)("PackageCheck",[["path",{d:"m16 16 2 2 4-4",key:"gfu2re"}],["path",{d:"M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14",key:"e7tb2h"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["line",{x1:"12",x2:"12",y1:"22",y2:"12",key:"a4e8g8"}]]),d=(0,r.Z)("LightbulbOff",[["path",{d:"M16.8 11.2c.8-.9 1.2-2 1.2-3.2a6 6 0 0 0-9.3-5",key:"1fkcox"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M6.3 6.3a4.67 4.67 0 0 0 1.2 5.2c.7.7 1.3 1.5 1.5 2.5",key:"10m8kw"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]]);var h=s(5893);const u=e=>{let{level:n,message:s}=e;const r={0:{title:"Deprecated",icon:(0,h.jsx)(l,{})},1:{title:"Experimental",icon:(0,h.jsx)(c,{})},1.1:{title:"Early Development",icon:(0,h.jsx)(a,{})},1.2:{title:"Release Candidate",icon:(0,h.jsx)(o,{})},2:{title:"Stable",icon:(0,h.jsx)(i,{})},3:{title:"Legacy",icon:(0,h.jsx)(d,{})}};return(0,h.jsxs)("section",{className:"stability","data-level":n,children:[(0,h.jsx)(t.Z,{to:"/docs/stability-badges",children:(0,h.jsxs)("header",{children:[(0,h.jsx)("strong",{children:n}),(0,h.jsx)("span",{children:r[n].title}),r[n].icon]})}),s?(0,h.jsx)("p",{children:s}):null]})}},4297:(e,n,s)=>{s.d(n,{Z:()=>l});var t=s(7294),r={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const l=(e,n)=>{const s=(0,t.forwardRef)((({color:s="currentColor",size:l=24,strokeWidth:c=2,absoluteStrokeWidth:a,className:o="",children:i,...d},h)=>{return(0,t.createElement)("svg",{ref:h,...r,width:l,height:l,stroke:s,strokeWidth:a?24*Number(c)/Number(l):c,className:["lucide",`lucide-${u=e,u.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().trim()}`,o].join(" "),...d},[...n.map((([e,n])=>(0,t.createElement)(e,n))),...Array.isArray(i)?i:[i]]);var u}));return s.displayName=`${e}`,s}},1151:(e,n,s)=>{s.d(n,{Z:()=>a,a:()=>c});var t=s(7294);const r={},l=t.createContext(r);function c(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file +/*! For license information please see 2bc14e22.684b748e.js.LICENSE.txt */ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[2839],{4760:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>d,contentTitle:()=>o,default:()=>x,frontMatter:()=>a,metadata:()=>i,toc:()=>h});var t=s(5893),r=s(1151),l=s(8609),c=s(3901);const a={},o="Using MySQL2 with TypeScript",i={id:"documentation/typescript-examples",title:"Using MySQL2 with TypeScript",description:"Installation",source:"@site/docs/documentation/typescript-examples.mdx",sourceDirName:"documentation",slug:"/documentation/typescript-examples",permalink:"/node-mysql2/docs/documentation/typescript-examples",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/documentation/typescript-examples.mdx",tags:[],version:"current",frontMatter:{},sidebar:"docs",previous:{title:"Promise Wrappers",permalink:"/node-mysql2/docs/documentation/promise-wrapper"},next:{title:"API and Configuration",permalink:"/node-mysql2/docs/api-and-configurations"}},d={},h=[{value:"Installation",id:"installation",level:2},{value:"Usage",id:"usage",level:2},{value:"Connection",id:"connection",level:3},{value:"Pool Connection",id:"pool-connection",level:3},{value:"Query and Execute",id:"query-and-execute",level:3},{value:"A simple query",id:"a-simple-query",level:4},{value:"Type Specification",id:"type-specification",level:2},{value:"RowDataPacket[]",id:"rowdatapacket",level:3},{value:"RowDataPacket[][]",id:"rowdatapacket-1",level:3},{value:"ResultSetHeader",id:"resultsetheader",level:3},{value:"ResultSetHeader[]",id:"resultsetheader-1",level:3},{value:"ProcedureCallPacket",id:"procedurecallpacket",level:3},{value:"OkPacket",id:"okpacket",level:3},{value:"Examples",id:"examples",level:2}];function u(e){const n={a:"a",admonition:"admonition",blockquote:"blockquote",br:"br",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",h4:"h4",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.h1,{id:"using-mysql2-with-typescript",children:"Using MySQL2 with TypeScript"}),"\n",(0,t.jsx)(n.h2,{id:"installation",children:"Installation"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"npm install --save mysql2\nnpm install --save-dev @types/node\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsxs)(n.p,{children:["The ",(0,t.jsx)(n.code,{children:"@types/node"})," ensure the proper interaction between ",(0,t.jsx)(n.strong,{children:"TypeScript"})," and the ",(0,t.jsx)(n.strong,{children:"Node.js"})," modules used by ",(0,t.jsx)(n.strong,{children:"MySQL2"})," (",(0,t.jsx)(n.em,{children:"net"}),", ",(0,t.jsx)(n.em,{children:"events"}),", ",(0,t.jsx)(n.em,{children:"stream"}),", ",(0,t.jsx)(n.em,{children:"tls"}),", etc.)."]}),"\n"]}),"\n",(0,t.jsx)(n.admonition,{type:"info",children:(0,t.jsxs)(n.p,{children:["Requires ",(0,t.jsx)(n.strong,{children:"TypeScript"})," ",(0,t.jsx)(n.code,{children:">=4.5.2"}),"."]})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,t.jsxs)(n.p,{children:["You can import ",(0,t.jsx)(n.strong,{children:"MySQL2"})," in two ways:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["By setting the ",(0,t.jsx)(n.code,{children:"esModuleInterop"})," option to ",(0,t.jsx)(n.code,{children:"true"})," in ",(0,t.jsx)(n.code,{children:"tsconfig.json"})]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql from 'mysql2';\nimport mysql from 'mysql2/promise';\n"})}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["By setting the ",(0,t.jsx)(n.code,{children:"esModuleInterop"})," option to ",(0,t.jsx)(n.code,{children:"false"})," in ",(0,t.jsx)(n.code,{children:"tsconfig.json"})]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import * as mysql from 'mysql2';\nimport * as mysql from 'mysql2/promise';\n"})}),"\n",(0,t.jsx)(n.h3,{id:"connection",children:"Connection"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { ConnectionOptions } from 'mysql2';\n\nconst access: ConnectionOptions = {\n user: 'test',\n database: 'test',\n};\n\nconst conn = mysql.createConnection(access);\n"})}),"\n",(0,t.jsx)(n.h3,{id:"pool-connection",children:"Pool Connection"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { PoolOptions } from 'mysql2';\n\nconst access: PoolOptions = {\n user: 'test',\n database: 'test',\n};\n\nconst conn = mysql.createPool(access);\n"})}),"\n",(0,t.jsx)(n.h3,{id:"query-and-execute",children:"Query and Execute"}),"\n",(0,t.jsx)(n.h4,{id:"a-simple-query",children:"A simple query"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"conn.query('SELECT 1 + 1 AS `test`;', (_err, rows) => {\n /**\n * @rows: [ { test: 2 } ]\n */\n});\n\nconn.execute('SELECT 1 + 1 AS `test`;', (_err, rows) => {\n /**\n * @rows: [ { test: 2 } ]\n */\n});\n"})}),"\n",(0,t.jsxs)(n.p,{children:["The ",(0,t.jsx)(n.code,{children:"rows"})," output will be these possible types:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.code,{children:"RowDataPacket[]"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.code,{children:"RowDataPacket[][]"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.code,{children:"ResultSetHeader"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.code,{children:"ResultSetHeader[]"})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.code,{children:"ProcedureCallPacket"})}),"\n"]}),"\n",(0,t.jsx)(n.p,{children:"In this example, you need to manually check the output types"}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h2,{id:"type-specification",children:"Type Specification"}),"\n",(0,t.jsx)(n.h3,{id:"rowdatapacket",children:"RowDataPacket[]"}),"\n",(0,t.jsx)(c.X,{level:2}),"\n",(0,t.jsx)(n.p,{children:"An array with the returned rows, for example:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { RowDataPacket } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n});\n\n// SELECT\nconn.query ('SELECT 1 + 1 AS `test`;', (_err, rows) => {\n console.log(rows);\n /**\n * @rows: [ { test: 2 } ]\n */\n});\n\n// SHOW\nconn.query ('SHOW TABLES FROM `test`;', (_err, rows) => {\n console.log(rows);\n /**\n * @rows: [ { Tables_in_test: 'test' } ]\n */\n});\n"})}),"\n",(0,t.jsxs)(n.p,{children:["Using ",(0,t.jsx)(n.code,{children:"rowsAsArray"})," option as ",(0,t.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { RowDataPacket } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n rowsAsArray: true,\n});\n\n// SELECT\nconn.query (\n 'SELECT 1 + 1 AS test, 2 + 2 AS test;',\n (_err, rows) => {\n console.log(rows);\n /**\n * @rows: [ [ 2, 4 ] ]\n */\n }\n);\n\n// SHOW\nconn.query ('SHOW TABLES FROM `test`;', (_err, rows) => {\n console.log(rows);\n /**\n * @rows: [ [ 'test' ] ]\n */\n});\n"})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"rowdatapacket-1",children:"RowDataPacket[][]"}),"\n",(0,t.jsx)(c.X,{level:2}),"\n",(0,t.jsxs)(n.p,{children:["Using ",(0,t.jsx)(n.code,{children:"multipleStatements"})," option as ",(0,t.jsx)(n.code,{children:"true"})," with multiple queries:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { RowDataPacket } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n multipleStatements: true,\n});\n\nconst sql = `\n SELECT 1 + 1 AS test;\n SELECT 2 + 2 AS test;\n`;\n\nconn.query (sql, (_err, rows) => {\n console.log(rows);\n /**\n * @rows: [ [ { test: 2 } ], [ { test: 4 } ] ]\n */\n});\n"})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"resultsetheader",children:"ResultSetHeader"}),"\n",(0,t.jsx)(c.X,{level:2}),"\n",(0,t.jsx)(l.A,{records:[{version:"3.5.1",changes:[(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.strong,{children:"OkPacket"})," is deprecated and might be removed in the future major release.",(0,t.jsx)(n.br,{}),"Please use ",(0,t.jsx)(n.strong,{children:"ResultSetHeader"})," instead."]}),(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.strong,{children:"changedRows"})," option is deprecated and might be removed in the future major release.",(0,t.jsx)(n.br,{}),"Please use ",(0,t.jsx)(n.strong,{children:"affectedRows"})," instead."]})]}]}),"\n",(0,t.jsxs)(n.p,{children:["For ",(0,t.jsx)(n.code,{children:"INSERT"}),", ",(0,t.jsx)(n.code,{children:"UPDATE"}),", ",(0,t.jsx)(n.code,{children:"DELETE"}),", ",(0,t.jsx)(n.code,{children:"TRUNCATE"}),", etc.:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { ResultSetHeader } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n});\n\nconst sql = `\n SET @1 = 1;\n`;\n\nconn.query (sql, (_err, result) => {\n console.log(result);\n /**\n * @result: ResultSetHeader {\n fieldCount: 0,\n affectedRows: 0,\n insertId: 0,\n info: '',\n serverStatus: 2,\n warningStatus: 0,\n changedRows: 0\n }\n */\n});\n"})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"resultsetheader-1",children:"ResultSetHeader[]"}),"\n",(0,t.jsx)(c.X,{level:2}),"\n",(0,t.jsx)(l.A,{records:[{version:"3.5.1",changes:[(0,t.jsxs)(t.Fragment,{children:["Introduce ",(0,t.jsx)(n.strong,{children:"ResultSetHeader[]"})]})]}]}),"\n",(0,t.jsxs)(n.p,{children:["For multiples ",(0,t.jsx)(n.code,{children:"INSERT"}),", ",(0,t.jsx)(n.code,{children:"UPDATE"}),", ",(0,t.jsx)(n.code,{children:"DELETE"}),", ",(0,t.jsx)(n.code,{children:"TRUNCATE"}),", etc. when using ",(0,t.jsx)(n.code,{children:"multipleStatements"})," as ",(0,t.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { ResultSetHeader } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n multipleStatements: true,\n});\n\nconst sql = `\n SET @1 = 1;\n SET @2 = 2;\n`;\n\nconn.query (sql, (_err, results) => {\n console.log(results);\n /**\n * @results: [\n ResultSetHeader {\n fieldCount: 0,\n affectedRows: 0,\n insertId: 0,\n info: '',\n serverStatus: 10,\n warningStatus: 0,\n changedRows: 0\n },\n ResultSetHeader {\n fieldCount: 0,\n affectedRows: 0,\n insertId: 0,\n info: '',\n serverStatus: 2,\n warningStatus: 0,\n changedRows: 0\n }\n ]\n */\n});\n"})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"procedurecallpacket",children:"ProcedureCallPacket"}),"\n",(0,t.jsx)(c.X,{level:2}),"\n",(0,t.jsx)(l.A,{records:[{version:"3.5.1",changes:[(0,t.jsxs)(t.Fragment,{children:["Introduce ",(0,t.jsx)(n.strong,{children:"ProcedureCallPacket"})]})]}]}),"\n",(0,t.jsx)(n.admonition,{type:"tip",children:(0,t.jsxs)(n.p,{children:["By performing a ",(0,t.jsx)(n.strong,{children:"Call Procedure"})," using ",(0,t.jsx)(n.code,{children:"INSERT"}),", ",(0,t.jsx)(n.code,{children:"UPDATE"}),", etc., the return will be a ",(0,t.jsx)(n.code,{children:"ProcedureCallPacket "})," (even if you perform multiples queries and set ",(0,t.jsx)(n.code,{children:"multipleStatements"})," to ",(0,t.jsx)(n.code,{children:"true"}),"):"]})}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-ts",children:"import mysql, { ProcedureCallPacket, ResultSetHeader } from 'mysql2';\n\nconst conn = mysql.createConnection({\n user: 'test',\n database: 'test',\n});\n\n/** ResultSetHeader */\nconn.query('DROP PROCEDURE IF EXISTS myProcedure');\n\n/** ResultSetHeader */\nconn.query(`\n CREATE PROCEDURE myProcedure()\n BEGIN\n SET @1 = 1;\n SET @2 = 2;\n END\n `);\n\n/** ProcedureCallPacket */\nconst sql = 'CALL myProcedure()';\n\nconn.query >(sql, (_err, result) => {\n console.log(result);\n /**\n * @result: ResultSetHeader {\n fieldCount: 0,\n affectedRows: 0,\n insertId: 0,\n info: '',\n serverStatus: 2,\n warningStatus: 0,\n changedRows: 0\n }\n */\n});\n"})}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsxs)(n.p,{children:["For ",(0,t.jsx)(n.code,{children:"CREATE PROCEDURE"})," and ",(0,t.jsx)(n.code,{children:"DROP PROCEDURE"}),", these returns will be the ",(0,t.jsx)(n.em,{children:"default"})," ",(0,t.jsx)(n.code,{children:"ResultSetHeader"}),"."]}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:["By using ",(0,t.jsx)(n.code,{children:"SELECT"})," and ",(0,t.jsx)(n.code,{children:"SHOW"})," queries in a ",(0,t.jsx)(n.strong,{children:"Procedure Call"}),", it groups the results as:"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-tsx",children:"/** ProcedureCallPacket */\n[RowDataPacket[], ResultSetHeader]\n"})}),"\n",(0,t.jsxs)(n.p,{children:["For ",(0,t.jsx)(n.code,{children:"ProcedureCallPacket "}),", please see the following examples."]}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"okpacket",children:"OkPacket"}),"\n",(0,t.jsx)(c.X,{level:0,message:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.strong,{children:"OkPacket"})," is deprecated and might be removed in the future major release.",(0,t.jsx)(n.br,{}),"Please use ",(0,t.jsx)(n.strong,{children:"ResultSetHeader"})," instead."]})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h2,{id:"examples",children:"Examples"}),"\n",(0,t.jsxs)(n.p,{children:["You can also check some code examples using ",(0,t.jsx)(n.strong,{children:"MySQL2"})," and ",(0,t.jsx)(n.strong,{children:"TypeScript"})," to understand advanced concepts:"]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/row-data/index",children:["Extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/row-data/row-as-array",children:["Extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"})," and ",(0,t.jsx)(n.code,{children:"rowAsArray"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/row-data/multi-statements",children:["Extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"})," and ",(0,t.jsx)(n.code,{children:"multipleStatements"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/row-data/row-as-array-multi-statements",children:["Extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"}),", ",(0,t.jsx)(n.code,{children:"rowAsArray"})," and ",(0,t.jsx)(n.code,{children:"multipleStatements"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/procedure-call/index",children:["Checking for ",(0,t.jsx)(n.code,{children:"ResultSetHeader"}),", extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"})," from ",(0,t.jsx)(n.code,{children:"ProcedureCallPacket"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/procedure-call/row-as-array",children:["Checking for ",(0,t.jsx)(n.code,{children:"ResultSetHeader"}),", extending and using ",(0,t.jsx)(n.strong,{children:"Interfaces"})," with ",(0,t.jsx)(n.code,{children:"RowDataPacket"})," and ",(0,t.jsx)(n.code,{children:"rowAsArray"})," from ",(0,t.jsx)(n.code,{children:"ProcedureCallPacket"})]})}),"\n",(0,t.jsx)(n.li,{children:(0,t.jsxs)(n.a,{href:"/docs/examples/typescript/basic-custom-class",children:["Creating a basic custom ",(0,t.jsx)(n.strong,{children:"MySQL2"})," ",(0,t.jsx)(n.strong,{children:"Class"})]})}),"\n"]})]})}function x(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(u,{...e})}):u(e)}},4673:(e,n,s)=>{s.d(n,{Z:()=>p});var t=s(7294),r=s(512),l=s(2389),c=s(6043);const a={details:"details_lb9f",isBrowser:"isBrowser_bmU9",collapsibleContent:"collapsibleContent_i85q"};var o=s(5893);function i(e){return!!e&&("SUMMARY"===e.tagName||i(e.parentElement))}function d(e,n){return!!e&&(e===n||d(e.parentElement,n))}function h(e){let{summary:n,children:s,...h}=e;const u=(0,l.Z)(),x=(0,t.useRef)(null),{collapsed:p,setCollapsed:j}=(0,c.u)({initialState:!h.open}),[m,y]=(0,t.useState)(h.open),g=t.isValidElement(n)?n:(0,o.jsx)("summary",{children:n??"Details"});return(0,o.jsxs)("details",{...h,ref:x,open:m,"data-collapsed":p,className:(0,r.Z)(a.details,u&&a.isBrowser,h.className),onMouseDown:e=>{i(e.target)&&e.detail>1&&e.preventDefault()},onClick:e=>{e.stopPropagation();const n=e.target;i(n)&&d(n,x.current)&&(e.preventDefault(),p?(j(!1),y(!0)):j(!0))},children:[g,(0,o.jsx)(c.z,{lazy:!1,collapsed:p,disableSSRStyle:!0,onCollapseTransitionEnd:e=>{j(e),y(!e)},children:(0,o.jsx)("div",{className:a.collapsibleContent,children:s})})]})}const u={details:"details_b_Ee"},x="alert alert--info";function p(e){let{...n}=e;return(0,o.jsx)(h,{...n,className:(0,r.Z)(x,u.details,n.className)})}},8609:(e,n,s)=>{s.d(n,{A:()=>c});var t=s(4673);const r=(0,s(4297).Z)("FileClock",[["path",{d:"M16 22h2c.5 0 1-.2 1.4-.6.4-.4.6-.9.6-1.4V7.5L14.5 2H6c-.5 0-1 .2-1.4.6C4.2 3 4 3.5 4 4v3",key:"9lo3o3"}],["polyline",{points:"14 2 14 8 20 8",key:"1ew0cm"}],["circle",{cx:"8",cy:"16",r:"6",key:"10v15b"}],["path",{d:"M9.5 17.5 8 16.25V14",key:"1o80t2"}]]);var l=s(5893);const c=e=>{let{records:n,open:s}=e;return(0,l.jsx)(t.Z,{open:s,summary:(0,l.jsxs)("summary",{children:[(0,l.jsx)(r,{})," History"]}),className:"history",children:(0,l.jsxs)("table",{children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{children:"Version"}),(0,l.jsx)("th",{children:"Changes"})]})}),(0,l.jsx)("tbody",{children:n.map(((e,n)=>(0,l.jsxs)("tr",{children:[(0,l.jsx)("td",{children:(0,l.jsxs)("strong",{children:["v",e.version.replace(/[^0-9.]/g,"")]})}),(0,l.jsx)("td",{children:(0,l.jsx)("div",{className:"changes",children:e.changes.map(((e,n)=>(0,l.jsx)("section",{children:e},`change:${n}`)))})})]},`record:${n}`)))})]})})}},3901:(e,n,s)=>{s.d(n,{X:()=>u});var t=s(3692),r=s(4297);const l=(0,r.Z)("AlertTriangle",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z",key:"c3ski4"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]),c=(0,r.Z)("Lightbulb",[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]]),a=(0,r.Z)("Microscope",[["path",{d:"M6 18h8",key:"1borvv"}],["path",{d:"M3 22h18",key:"8prr45"}],["path",{d:"M14 22a7 7 0 1 0 0-14h-1",key:"1jwaiy"}],["path",{d:"M9 14h2",key:"197e7h"}],["path",{d:"M9 12a2 2 0 0 1-2-2V6h6v4a2 2 0 0 1-2 2Z",key:"1bmzmy"}],["path",{d:"M12 6V3a1 1 0 0 0-1-1H9a1 1 0 0 0-1 1v3",key:"1drr47"}]]),o=(0,r.Z)("PackageSearch",[["path",{d:"M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14",key:"e7tb2h"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["line",{x1:"12",x2:"12",y1:"22",y2:"12",key:"a4e8g8"}],["circle",{cx:"18.5",cy:"15.5",r:"2.5",key:"b5zd12"}],["path",{d:"M20.27 17.27 22 19",key:"1l4muz"}]]),i=(0,r.Z)("PackageCheck",[["path",{d:"m16 16 2 2 4-4",key:"gfu2re"}],["path",{d:"M21 10V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14",key:"e7tb2h"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["line",{x1:"12",x2:"12",y1:"22",y2:"12",key:"a4e8g8"}]]),d=(0,r.Z)("LightbulbOff",[["path",{d:"M16.8 11.2c.8-.9 1.2-2 1.2-3.2a6 6 0 0 0-9.3-5",key:"1fkcox"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M6.3 6.3a4.67 4.67 0 0 0 1.2 5.2c.7.7 1.3 1.5 1.5 2.5",key:"10m8kw"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]]);var h=s(5893);const u=e=>{let{level:n,message:s}=e;const r={0:{title:"Deprecated",icon:(0,h.jsx)(l,{})},1:{title:"Experimental",icon:(0,h.jsx)(c,{})},1.1:{title:"Early Development",icon:(0,h.jsx)(a,{})},1.2:{title:"Release Candidate",icon:(0,h.jsx)(o,{})},2:{title:"Stable",icon:(0,h.jsx)(i,{})},3:{title:"Legacy",icon:(0,h.jsx)(d,{})}};return(0,h.jsxs)("section",{className:"stability","data-level":n,children:[(0,h.jsx)(t.Z,{to:"/docs/stability-badges",children:(0,h.jsxs)("header",{children:[(0,h.jsx)("strong",{children:n}),(0,h.jsx)("span",{children:r[n].title}),r[n].icon]})}),s?(0,h.jsx)("p",{children:s}):null]})}},4297:(e,n,s)=>{s.d(n,{Z:()=>l});var t=s(7294),r={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};const l=(e,n)=>{const s=(0,t.forwardRef)((({color:s="currentColor",size:l=24,strokeWidth:c=2,absoluteStrokeWidth:a,className:o="",children:i,...d},h)=>{return(0,t.createElement)("svg",{ref:h,...r,width:l,height:l,stroke:s,strokeWidth:a?24*Number(c)/Number(l):c,className:["lucide",`lucide-${u=e,u.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase().trim()}`,o].join(" "),...d},[...n.map((([e,n])=>(0,t.createElement)(e,n))),...Array.isArray(i)?i:[i]]);var u}));return s.displayName=`${e}`,s}},1151:(e,n,s)=>{s.d(n,{Z:()=>a,a:()=>c});var t=s(7294);const r={},l=t.createContext(r);function c(e){const n=t.useContext(l);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),t.createElement(l.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/2bc14e22.3ce1e359.js.LICENSE.txt b/assets/js/2bc14e22.684b748e.js.LICENSE.txt similarity index 76% rename from assets/js/2bc14e22.3ce1e359.js.LICENSE.txt rename to assets/js/2bc14e22.684b748e.js.LICENSE.txt index 4b1ddb7671..3d48b22d31 100644 --- a/assets/js/2bc14e22.3ce1e359.js.LICENSE.txt +++ b/assets/js/2bc14e22.684b748e.js.LICENSE.txt @@ -1,5 +1,5 @@ /** - * @license lucide-react v0.303.0 - ISC + * @license lucide-react v0.306.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. diff --git a/assets/js/3226d26d.e340bb5c.js b/assets/js/3226d26d.e340bb5c.js new file mode 100644 index 0000000000..abc58a0439 --- /dev/null +++ b/assets/js/3226d26d.e340bb5c.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[4243],{7991:e=>{e.exports=JSON.parse('{"label":"Placeholders","permalink":"/node-mysql2/docs/tags/placeholders","allTagsPath":"/node-mysql2/docs/tags","count":4,"items":[{"id":"examples/queries/prepared-statements/delete","title":"DELETE","description":"execute(sql, values)","permalink":"/node-mysql2/docs/examples/queries/prepared-statements/delete"},{"id":"examples/queries/prepared-statements/insert","title":"INSERT","description":"execute(sql, values)","permalink":"/node-mysql2/docs/examples/queries/prepared-statements/insert"},{"id":"examples/queries/prepared-statements/select","title":"SELECT","description":"execute(sql, values)","permalink":"/node-mysql2/docs/examples/queries/prepared-statements/select"},{"id":"examples/queries/prepared-statements/update","title":"UPDATE","description":"execute(sql, values)","permalink":"/node-mysql2/docs/examples/queries/prepared-statements/update"}],"unlisted":false}')}}]); \ No newline at end of file diff --git a/assets/js/3720c009.8c42b22a.js b/assets/js/3720c009.8c42b22a.js new file mode 100644 index 0000000000..93b7ade9e4 --- /dev/null +++ b/assets/js/3720c009.8c42b22a.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[3751],{9861:(t,e,s)=>{s.r(e),s.d(e,{default:()=>p});s(7294);var a=s(512),r=s(1944),l=s(5281),n=s(5999);const c=()=>(0,n.I)({id:"theme.tags.tagsPageTitle",message:"Tags",description:"The title of the tag list page"});var i=s(3008),g=s(2503);const o={tag:"tag_Nnez"};var u=s(5893);function h(t){let{letterEntry:e}=t;return(0,u.jsxs)("article",{children:[(0,u.jsx)(g.Z,{as:"h2",id:e.letter,children:e.letter}),(0,u.jsx)("ul",{className:"padding--none",children:e.tags.map((t=>(0,u.jsx)("li",{className:o.tag,children:(0,u.jsx)(i.Z,{...t})},t.permalink)))}),(0,u.jsx)("hr",{})]})}function d(t){let{tags:e}=t;const s=function(t){const e={};return Object.values(t).forEach((t=>{const s=function(t){return t[0].toUpperCase()}(t.label);e[s]??=[],e[s].push(t)})),Object.entries(e).sort(((t,e)=>{let[s]=t,[a]=e;return s.localeCompare(a)})).map((t=>{let[e,s]=t;return{letter:e,tags:s.sort(((t,e)=>t.label.localeCompare(e.label)))}}))}(e);return(0,u.jsx)("section",{className:"margin-vert--lg",children:s.map((t=>(0,u.jsx)(h,{letterEntry:t},t.letter)))})}var j=s(197);function m(t){let{title:e}=t;return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(r.d,{title:e}),(0,u.jsx)(j.Z,{tag:"doc_tags_list"})]})}function x(t){let{tags:e,title:s}=t;return(0,u.jsx)(r.FG,{className:(0,a.Z)(l.k.page.docsTagsListPage),children:(0,u.jsx)("div",{className:"container margin-vert--lg",children:(0,u.jsx)("div",{className:"row",children:(0,u.jsxs)("main",{className:"col col--8 col--offset-2",children:[(0,u.jsx)(g.Z,{as:"h1",children:s}),(0,u.jsx)(d,{tags:e})]})})})})}function p(t){const e=c();return(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(m,{...t,title:e}),(0,u.jsx)(x,{...t,title:e})]})}},3008:(t,e,s)=>{s.d(e,{Z:()=>c});s(7294);var a=s(512),r=s(3692);const l={tag:"tag_zVej",tagRegular:"tagRegular_sFm0",tagWithCount:"tagWithCount_h2kH"};var n=s(5893);function c(t){let{permalink:e,label:s,count:c}=t;return(0,n.jsxs)(r.Z,{href:e,className:(0,a.Z)(l.tag,c?l.tagWithCount:l.tagRegular),children:[s,c&&(0,n.jsx)("span",{children:c})]})}}}]); \ No newline at end of file diff --git a/assets/js/3be0564c.69bfa956.js b/assets/js/3be0564c.69bfa956.js deleted file mode 100644 index 600cb81a93..0000000000 --- a/assets/js/3be0564c.69bfa956.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[9594],{3034:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>h,frontMatter:()=>l,metadata:()=>i,toc:()=>d});var r=n(5893),a=n(1151),s=n(4866),o=n(5162);const l={},u="Binlog Watcher",i={id:"examples/binlog-watcher",title:"Binlog Watcher",description:"",source:"@site/docs/examples/binlog-watcher.mdx",sourceDirName:"examples",slug:"/examples/binlog-watcher",permalink:"/node-mysql2/docs/examples/binlog-watcher",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/binlog-watcher.mdx",tags:[],version:"current",frontMatter:{},sidebar:"examples",previous:{title:"Introduction",permalink:"/node-mysql2/docs/examples"},next:{title:"Connect Over Socks",permalink:"/node-mysql2/docs/examples/connect-over-socks"}},c={},d=[];function m(e){const t={code:"code",h1:"h1",pre:"pre",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{id:"binlog-watcher",children:"Binlog Watcher"}),"\n",(0,r.jsx)(s.Z,{children:(0,r.jsx)(o.Z,{value:"index.js",default:!0,children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",children:"'use strict';\n\nconst mysql = require('mysql2');\nconst through2 = require('through2');\n\nconst binlogStream = mysql.createBinlogStream({\n serverId: 123, // slave ID, first field in \"show slave hosts\" sql response\n // you can also specify slave host, username, password and port\n masterId: 0,\n filename: 'mysql-bin.000007',\n binlogPos: 120,\n flags: 1, // 1 = \"non-blocking mode\"\n});\n\nbinlogStream.pipe(\n through2.obj((obj, enc, next) => {\n console.log(obj);\n next();\n })\n);\n"})})})})]})}function h(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>o});n(7294);var r=n(512);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,o),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>j});var r=n(7294),a=n(512),s=n(2466),o=n(6550),l=n(469),u=n(1980),i=n(7392),c=n(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,i.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function p(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u._X)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(e),[o,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[i,d]=p({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,c.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),g=(()=>{const e=i??b;return h({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{g&&u(g)}),[g]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),f(e)}),[d,f,s]),tabValues:s}}var f=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(5893);function x(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.o5)(),c=e=>{const t=e.currentTarget,n=u.indexOf(t),a=l[n].value;a!==r&&(i(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.Z)("tabs__item",g.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function y(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=b(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",g.tabList),children:[(0,v.jsx)(x,{...e,...t}),(0,v.jsx)(y,{...e,...t})]})}function j(e){const t=(0,f.Z)();return(0,v.jsx)(w,{...e,children:d(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>l,a:()=>o});var r=n(7294);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/3be0564c.99fbf261.js b/assets/js/3be0564c.99fbf261.js new file mode 100644 index 0000000000..efe61ac715 --- /dev/null +++ b/assets/js/3be0564c.99fbf261.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[9594],{3034:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>p,frontMatter:()=>o,metadata:()=>i,toc:()=>d});var r=n(5893),a=n(1151),s=n(4866),l=n(5162);const o={},u="Binlog Watcher",i={id:"examples/binlog-watcher",title:"Binlog Watcher",description:"",source:"@site/docs/examples/binlog-watcher.mdx",sourceDirName:"examples",slug:"/examples/binlog-watcher",permalink:"/node-mysql2/docs/examples/binlog-watcher",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/binlog-watcher.mdx",tags:[],version:"current",frontMatter:{},sidebar:"examples",previous:{title:"DELETE",permalink:"/node-mysql2/docs/examples/queries/prepared-statements/delete"},next:{title:"await \u2014 co",permalink:"/node-mysql2/docs/examples/promise-wrapper/co-await"}},c={},d=[];function m(e){const t={code:"code",h1:"h1",pre:"pre",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{id:"binlog-watcher",children:"Binlog Watcher"}),"\n",(0,r.jsx)(s.Z,{children:(0,r.jsx)(l.Z,{value:"index.js",default:!0,children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",children:"'use strict';\n\nconst mysql = require('mysql2');\nconst through2 = require('through2');\n\nconst binlogStream = mysql.createBinlogStream({\n serverId: 123, // slave ID, first field in \"show slave hosts\" sql response\n // you can also specify slave host, username, password and port\n masterId: 0,\n filename: 'mysql-bin.000007',\n binlogPos: 120,\n flags: 1, // 1 = \"non-blocking mode\"\n});\n\nbinlogStream.pipe(\n through2.obj((obj, enc, next) => {\n console.log(obj);\n next();\n })\n);\n"})})})})]})}function p(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>l});n(7294);var r=n(512);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function l(e){let{children:t,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,l),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>j});var r=n(7294),a=n(512),s=n(2466),l=n(6550),o=n(469),u=n(1980),i=n(7392),c=n(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,i.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function h(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u._X)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(e),[l,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[i,d]=h({queryString:n,groupId:a}),[b,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,c.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),g=(()=>{const e=i??b;return p({value:e,tabValues:s})?e:null})();(0,o.Z)((()=>{g&&u(g)}),[g]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),f(e)}),[d,f,s]),tabValues:s}}var f=n(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(5893);function x(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:o}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.o5)(),c=e=>{const t=e.currentTarget,n=u.indexOf(t),a=o[n].value;a!==r&&(i(t),l(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.Z)("tabs__item",g.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function w(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function y(e){const t=b(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",g.tabList),children:[(0,v.jsx)(x,{...e,...t}),(0,v.jsx)(w,{...e,...t})]})}function j(e){const t=(0,f.Z)();return(0,v.jsx)(y,{...e,children:d(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>l});var r=n(7294);const a={},s=r.createContext(a);function l(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/3bea1af6.2654cd83.js b/assets/js/3bea1af6.2654cd83.js deleted file mode 100644 index 0d266ce428..0000000000 --- a/assets/js/3bea1af6.2654cd83.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[9264],{3006:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>i,contentTitle:()=>u,default:()=>p,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var r=n(5893),a=n(1151),s=n(4866),o=n(5162);const l={},u="Execute",c={id:"examples/execute",title:"Execute",description:"",source:"@site/docs/examples/execute.mdx",sourceDirName:"examples",slug:"/examples/execute",permalink:"/node-mysql2/docs/examples/execute",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/execute.mdx",tags:[],version:"current",frontMatter:{},sidebar:"examples",previous:{title:"Connect Over Socks",permalink:"/node-mysql2/docs/examples/connect-over-socks"},next:{title:"MySQL Proxy",permalink:"/node-mysql2/docs/examples/mysqlproxy"}},i={},d=[];function m(e){const t={code:"code",h1:"h1",pre:"pre",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{id:"execute",children:"Execute"}),"\n",(0,r.jsx)(s.Z,{children:(0,r.jsx)(o.Z,{value:"index.js",default:!0,children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",children:"'use strict';\n\n// get the client\nconst mysql = require('mysql2');\n\n// create the connection to database\nconst connection = mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n});\n\nconnection.execute(\n 'select ?+1 as qqq, ? as rrr, ? as yyy',\n [1, null, 3],\n (err, rows, fields) => {\n console.log(err, rows, fields);\n connection.execute(\n 'select ?+1 as qqq, ? as rrr, ? as yyy',\n [3, null, 3],\n (err, rows, fields) => {\n console.log(err, rows, fields);\n connection.unprepare('select ?+1 as qqq, ? as rrr, ? as yyy');\n connection.execute(\n 'select ?+1 as qqq, ? as rrr, ? as yyy',\n [3, null, 3],\n (err, rows, fields) => {\n console.log(err, rows, fields);\n }\n );\n }\n );\n }\n);\n"})})})})]})}function p(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>o});n(7294);var r=n(512);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,o),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7294),a=n(512),s=n(2466),o=n(6550),l=n(469),u=n(1980),c=n(7392),i=n(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,c.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u._X)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(e),[o,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[c,d]=f({queryString:n,groupId:a}),[h,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,i.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),x=(()=>{const e=c??h;return p({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{x&&u(x)}),[x]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),b(e)}),[d,b,s]),tabValues:s}}var b=n(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(5893);function y(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const u=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),i=e=>{const t=e.currentTarget,n=u.indexOf(t),a=l[n].value;a!==r&&(c(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":i(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:i,...s,className:(0,a.Z)("tabs__item",x.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function g(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function q(e){const t=h(e);return(0,v.jsxs)("div",{className:(0,a.Z)("tabs-container",x.tabList),children:[(0,v.jsx)(y,{...e,...t}),(0,v.jsx)(g,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,v.jsx)(q,{...e,children:d(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>l,a:()=>o});var r=n(7294);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/43758d02.6ddfbc88.js b/assets/js/43758d02.6ddfbc88.js deleted file mode 100644 index 0b8a70a91e..0000000000 --- a/assets/js/43758d02.6ddfbc88.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[764],{3230:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>u,default:()=>m,frontMatter:()=>l,metadata:()=>i,toc:()=>d});var r=n(5893),a=n(1151),s=n(4866),o=n(5162);const l={},u="Pool Test",i={id:"examples/pool-test",title:"Pool Test",description:"",source:"@site/docs/examples/pool-test.mdx",sourceDirName:"examples",slug:"/examples/pool-test",permalink:"/node-mysql2/docs/examples/pool-test",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/pool-test.mdx",tags:[],version:"current",frontMatter:{},sidebar:"examples",previous:{title:"Pass SHA",permalink:"/node-mysql2/docs/examples/pass-sha"},next:{title:"Prepared Statements",permalink:"/node-mysql2/docs/examples/prepare"}},c={},d=[];function p(e){const t={code:"code",h1:"h1",pre:"pre",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{id:"pool-test",children:"Pool Test"}),"\n",(0,r.jsx)(s.Z,{children:(0,r.jsx)(o.Z,{value:"index.js",default:!0,children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",children:"'use strict';\n\nconst pool = require('mysql2').createPool({\n host: 'localhost',\n user: 'root',\n database: 'test',\n password: 'root',\n});\n\nsetInterval(() => {\n for (let i = 0; i < 5; ++i) {\n pool.query((err, rows, fields) => {\n console.log(rows, fields);\n // Connection is automatically released once query resolves\n });\n }\n}, 1000);\n\nsetInterval(() => {\n for (let i = 0; i < 5; ++i) {\n pool.getConnection((err, db) => {\n db.query('select sleep(0.5) as qqq', (err, rows, fields) => {\n console.log(rows, fields);\n db.release();\n });\n });\n }\n}, 1000);\n"})})})})]})}function m(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>o});n(7294);var r=n(512);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,o),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>q});var r=n(7294),a=n(512),s=n(2466),o=n(6550),l=n(469),u=n(1980),i=n(7392),c=n(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,i.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,o.k6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u._X)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=p(e),[o,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[i,d]=f({queryString:n,groupId:a}),[b,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,c.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),v=(()=>{const e=i??b;return m({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{v&&u(v)}),[v]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),h(e)}),[d,h,s]),tabValues:s}}var h=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=n(5893);function g(e){let{className:t,block:n,selectedValue:r,selectValue:o,tabValues:l}=e;const u=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.o5)(),c=e=>{const t=e.currentTarget,n=u.indexOf(t),a=l[n].value;a!==r&&(i(t),o(a))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:l.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:c,...s,className:(0,a.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function y(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function w(e){const t=b(e);return(0,x.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,x.jsx)(g,{...e,...t}),(0,x.jsx)(y,{...e,...t})]})}function q(e){const t=(0,h.Z)();return(0,x.jsx)(w,{...e,children:d(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>l,a:()=>o});var r=n(7294);const a={},s=r.createContext(a);function o(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4e547710.9c523c17.js b/assets/js/4e547710.9c523c17.js deleted file mode 100644 index ae4ad0339a..0000000000 --- a/assets/js/4e547710.9c523c17.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[1449],{9393:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>u,contentTitle:()=>c,default:()=>m,frontMatter:()=>l,metadata:()=>i,toc:()=>d});var r=t(5893),a=t(1151),s=t(4866),o=t(5162);const l={},c="Promise CO Await",i={id:"examples/promise-co-await",title:"Promise CO Await",description:"",source:"@site/docs/examples/promise-co-await.mdx",sourceDirName:"examples",slug:"/examples/promise-co-await",permalink:"/node-mysql2/docs/examples/promise-co-await",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/promise-co-await.mdx",tags:[],version:"current",frontMatter:{},sidebar:"examples",previous:{title:"Prepared Statements",permalink:"/node-mysql2/docs/examples/prepare"},next:{title:"Queries",permalink:"/node-mysql2/docs/category/queries"}},u={},d=[];function p(e){const n={code:"code",h1:"h1",pre:"pre",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h1,{id:"promise-co-await",children:"Promise CO Await"}),"\n",(0,r.jsxs)(s.Z,{children:[(0,r.jsx)(o.Z,{value:"await.js",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"'use strict';\n\nconst mysql = require('mysql2/promise');\n\nasync function test() {\n const c = await mysql.createConnection({\n port: 3306,\n user: 'testuser',\n namedPlaceholders: true,\n password: 'testpassword',\n });\n console.log('connected!');\n const [rows, fields] = await c.query('show databases');\n console.log(rows);\n\n try {\n const [rows, fields] = await c.query('some invalid sql here');\n } catch (e) {\n console.log('caught exception!', e);\n }\n\n console.log(await c.execute('select sleep(0.5)'));\n console.log('after first sleep');\n console.log(await c.execute('select sleep(0.5)'));\n console.log('after second sleep');\n let start = +new Date();\n console.log(\n await Promise.all([\n c.execute('select sleep(2.5)'),\n c.execute('select sleep(2.5)'),\n ])\n );\n console.log(\n 'after 2+3 parallel sleep which is in fact not parallel because commands are queued per connection'\n );\n let end = +new Date();\n console.log(end - start);\n await c.end();\n\n const p = mysql.createPool({\n port: 3306,\n user: 'testuser',\n namedPlaceholders: true,\n password: 'testpassword',\n });\n console.log(await p.execute('select sleep(0.5)'));\n console.log('after first pool sleep');\n start = +new Date();\n console.log(\n await Promise.all([\n p.execute('select sleep(2.5)'),\n p.execute('select sleep(2.5)'),\n ])\n );\n console.log('after 2+3 parallel pool sleep');\n end = +new Date();\n console.log(end - start);\n await p.end();\n}\n\ntest()\n .then(() => {\n console.log('done');\n })\n .catch((err) => {\n console.log('error!', err);\n throw err;\n });\n"})})}),(0,r.jsx)(o.Z,{value:"co.js",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"'use strict';\n\nconst mysql = require('mysql2/promise');\nconst co = require('co');\n\nco(function* () {\n const c = yield mysql.createConnection({\n port: 3306,\n user: 'root',\n namedPlaceholders: true,\n });\n const rows = yield c.query('show databases');\n console.log(rows);\n console.log(yield c.execute('select 1+:toAdd as qqq', { toAdd: 10 }));\n yield c.end();\n})\n .then(function () {\n console.log('done');\n })\n .catch(function (err) {\n console.log(err);\n throw err;\n });\n"})})}),(0,r.jsx)(o.Z,{value:".babelrc",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-json",children:'{\n "plugins": ["transform-async-to-generator"]\n}\n'})})}),(0,r.jsx)(o.Z,{value:"package.json",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-json",children:'{\n "name": "promise-co-await",\n "version": "1.0.0",\n "description": "",\n "main": "await.js",\n "scripts": {\n "test": "echo \\"Error: no test specified\\" && exit 1"\n },\n "author": "",\n "license": "ISC",\n "dependencies": {\n "babel-cli": "^6.9.0"\n }\n}\n'})})})]})]})}function m(e={}){const{wrapper:n}={...(0,a.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>o});t(7294);var r=t(512);const a={tabItem:"tabItem_Ymn6"};var s=t(5893);function o(e){let{children:n,hidden:t,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,o),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>j});var r=t(7294),a=t(512),s=t(2466),o=t(6550),l=t(469),c=t(1980),i=t(7392),u=t(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:n,children:t}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return d(e).map((e=>{let{props:{value:n,label:t,attributes:r,default:a}}=e;return{value:n,label:t,attributes:r,default:a}}))}(t);return function(e){const n=(0,i.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function m(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function h(e){let{queryString:n=!1,groupId:t}=e;const a=(0,o.k6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:n,groupId:t});return[(0,c._X)(s),(0,r.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(a.location.search);n.set(s,e),a.replace({...a.location,search:n.toString()})}),[s,a])]}function f(e){const{defaultValue:n,queryString:t=!1,groupId:a}=e,s=p(e),[o,c]=(0,r.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const r=t.find((e=>e.default))??t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:n,tabValues:s}))),[i,d]=h({queryString:t,groupId:a}),[f,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[a,s]=(0,u.Nk)(t);return[a,(0,r.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:a}),g=(()=>{const e=i??f;return m({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{g&&c(g)}),[g]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);c(e),d(e),b(e)}),[d,b,s]),tabValues:s}}var b=t(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var w=t(5893);function x(e){let{className:n,block:t,selectedValue:r,selectValue:o,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.o5)(),u=e=>{const n=e.currentTarget,t=c.indexOf(n),a=l[t].value;a!==r&&(i(n),o(a))},d=e=>{let n=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const t=c.indexOf(e.currentTarget)+1;n=c[t]??c[0];break}case"ArrowLeft":{const t=c.indexOf(e.currentTarget)-1;n=c[t]??c[c.length-1];break}}n?.focus()};return(0,w.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:s}=e;return(0,w.jsx)("li",{role:"tab",tabIndex:r===n?0:-1,"aria-selected":r===n,ref:e=>c.push(e),onKeyDown:d,onClick:u,...s,className:(0,a.Z)("tabs__item",g.tabItem,s?.className,{"tabs__item--active":r===n}),children:t??n},n)}))})}function v(e){let{lazy:n,children:t,selectedValue:a}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,w.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==a})))})}function y(e){const n=f(e);return(0,w.jsxs)("div",{className:(0,a.Z)("tabs-container",g.tabList),children:[(0,w.jsx)(x,{...e,...n}),(0,w.jsx)(v,{...e,...n})]})}function j(e){const n=(0,b.Z)();return(0,w.jsx)(y,{...e,children:d(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>o});var r=t(7294);const a={},s=r.createContext(a);function o(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4edc808e.1929d38c.js b/assets/js/4edc808e.1929d38c.js new file mode 100644 index 0000000000..41a64b873a --- /dev/null +++ b/assets/js/4edc808e.1929d38c.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[4173],{7559:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>d,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>h});var t=s(5893),o=s(1151),r=s(4866),a=s(5162),l=s(4442);const i={slug:"/",position:1,title:"Quickstart",description:"MySQL client for Node.js with focus on performance"},c="MySQL2",u={id:"index",title:"Quickstart",description:"MySQL client for Node.js with focus on performance",source:"@site/docs/index.mdx",sourceDirName:".",slug:"/",permalink:"/node-mysql2/docs/",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/index.mdx",tags:[],version:"current",frontMatter:{slug:"/",position:1,title:"Quickstart",description:"MySQL client for Node.js with focus on performance"},sidebar:"docs",next:{title:"History and Why MySQL2",permalink:"/node-mysql2/docs/history-and-why-mysq2"}},d={},h=[{value:"Installation",id:"installation",level:2},{value:"First Query",id:"first-query",level:3},{value:"Using Prepared Statements",id:"using-prepared-statements",level:3},{value:"Using Connection Pools",id:"using-connection-pools",level:3},{value:"Using Promise Wrapper",id:"using-promise-wrapper",level:3},{value:"Array Results",id:"array-results",level:3},{value:"Connection Level",id:"connection-level",level:4},{value:"Query Level",id:"query-level",level:4}];function m(e){const n={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",hr:"hr",img:"img",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(l.V,{title:"MySQL2 | Quickstart"}),"\n",(0,t.jsx)(n.h1,{id:"mysql2",children:"MySQL2"}),"\n","\n",(0,t.jsx)(n.p,{children:"MySQL client for Node.js with focus on performance. Supports prepared statements, non-utf8 encodings, binary log protocol, compression, ssl much more."}),"\n",(0,t.jsxs)(n.p,{children:[(0,t.jsx)(n.a,{href:"https://npmjs.org/package/mysql2",children:(0,t.jsx)(n.img,{src:"https://img.shields.io/npm/v/mysql2.svg",alt:"NPM Version"})}),"\n",(0,t.jsx)(n.a,{href:"https://npmjs.org/package/mysql2",children:(0,t.jsx)(n.img,{src:"https://img.shields.io/npm/dm/mysql2.svg",alt:"NPM Downloads"})}),"\n",(0,t.jsx)(n.a,{href:"https://nodejs.org/download/",children:(0,t.jsx)(n.img,{src:"https://img.shields.io/node/v/mysql2.svg",alt:"Node.js Version"})}),"\n",(0,t.jsx)(n.a,{href:"https://github.com/sidorares/node-mysql2/blob/master/License",children:(0,t.jsx)(n.img,{src:"https://img.shields.io/npm/l/mysql2.svg?maxAge=2592000",alt:"License"})})]}),"\n",(0,t.jsx)(n.h2,{id:"installation",children:"Installation"}),"\n",(0,t.jsx)(n.p,{children:"MySQL2 is free from native bindings and can be installed on Linux, Mac OS or Windows without any issues."}),"\n",(0,t.jsxs)(r.Z,{children:[(0,t.jsx)(a.Z,{value:"JavaScript",default:!0,children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"npm install --save mysql2\n"})})}),(0,t.jsxs)(a.Z,{value:"TypeScript",children:[(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"npm install --save mysql2\nnpm install --save-dev @types/node\n"})}),(0,t.jsxs)(n.p,{children:["For TypeScript documentation and examples, see ",(0,t.jsx)(n.a,{href:"/docs/documentation/typescript-examples",children:"here"}),"."]})]})]}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"first-query",children:"First Query"}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsxs)(n.p,{children:["To explore more queries examples, please visit the example sections ",(0,t.jsx)(n.a,{href:"/docs/examples/queries/simple-queries",children:(0,t.jsx)(n.strong,{children:"Simple Queries"})})," and ",(0,t.jsx)(n.a,{href:"/docs/examples/queries/prepared-statements",children:(0,t.jsx)(n.strong,{children:"Prepared Statements"})}),"."]}),"\n"]}),"\n",(0,t.jsxs)(r.Z,{children:[(0,t.jsx)(a.Z,{value:"Promise",default:!0,children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"// Get the client\nimport mysql from 'mysql2/promise';\n\n// Create the connection to database\nconst connection = await mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n});\n\n// A simple SELECT query\ntry {\n const [results, fields] = await connection.query(\n 'SELECT * FROM `table` WHERE `name` = \"Page\" AND `age` > 45'\n );\n\n console.log(results); // results contains rows returned by server\n console.log(fields); // fields contains extra meta data about results, if available\n} catch (err) {\n console.log(err);\n}\n\n// Using placeholders\ntry {\n const [results] = await connection.query(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Page', 45]\n );\n\n console.log(results);\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,t.jsx)(a.Z,{value:"Callback",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"// Get the client\nconst mysql = require('mysql2');\n\n// Create the connection to database\nconst connection = mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n});\n\n// A simple SELECT query\nconnection.query(\n 'SELECT * FROM `table` WHERE `name` = \"Page\" AND `age` > 45',\n function (err, results, fields) {\n console.log(results); // results contains rows returned by server\n console.log(fields); // fields contains extra meta data about results, if available\n }\n);\n\n// Using placeholders\nconnection.query(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Page', 45],\n function (err, results) {\n console.log(results);\n }\n);\n"})})})]}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"using-prepared-statements",children:"Using Prepared Statements"}),"\n",(0,t.jsx)(n.p,{children:"With MySQL2 you also get the prepared statements. With prepared statements MySQL doesn't have to prepare plan for same query every time, this results in better performance. If you don't know why they are important, please check these discussions:"}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsx)(n.li,{children:(0,t.jsx)(n.a,{href:"https://stackoverflow.com/questions/8263371/how-can-prepared-statements-protect-from-sql-injection-attacks",children:"How prepared statements can protect from SQL Injection attacks"})}),"\n"]}),"\n",(0,t.jsxs)(n.p,{children:["MySQL2 provides ",(0,t.jsx)(n.code,{children:"execute"})," helper which will prepare and query the statement. You can also manually prepare / unprepare statement with ",(0,t.jsx)(n.code,{children:"prepare"})," / ",(0,t.jsx)(n.code,{children:"unprepare"})," methods."]}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsxs)(n.p,{children:["To explore more Prepared Statements and Placeholders examples, please visit the example section ",(0,t.jsx)(n.a,{href:"/docs/examples/queries/prepared-statements",children:(0,t.jsx)(n.strong,{children:"Prepared Statements"})}),"."]}),"\n"]}),"\n",(0,t.jsxs)(r.Z,{children:[(0,t.jsx)(a.Z,{value:"Promise",default:!0,children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\ntry {\n // create the connection to database\n const connection = await mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n });\n\n // execute will internally call prepare and query\n const [results, fields] = await connection.execute(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Rick C-137', 53]\n );\n\n console.log(results); // results contains rows returned by server\n console.log(fields); // fields contains extra meta data about results, if available\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,t.jsx)(a.Z,{value:"Callback",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\n// create the connection to database\nconst connection = mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n});\n\n// execute will internally call prepare and query\nconnection.execute(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Rick C-137', 53],\n function (err, results, fields) {\n console.log(results); // results contains rows returned by server\n console.log(fields); // fields contains extra meta data about results, if available\n }\n);\n"})})})]}),"\n",(0,t.jsx)(n.admonition,{type:"tip",children:(0,t.jsx)(n.p,{children:"If you execute same statement again, it will be picked from a LRU cache which will save query preparation time and give better performance."})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"using-connection-pools",children:"Using Connection Pools"}),"\n",(0,t.jsx)(n.p,{children:"Connection pools help reduce the time spent connecting to the MySQL server by reusing a previous connection, leaving them open instead of closing when you are done with them."}),"\n",(0,t.jsx)(n.p,{children:"This improves the latency of queries as you avoid all of the overhead that comes with establishing a new connection."}),"\n",(0,t.jsxs)(n.blockquote,{children:["\n",(0,t.jsxs)(n.p,{children:["To explore more Connection Pools examples, please visit the example section ",(0,t.jsx)(n.a,{href:"/docs/examples/connections/create-pool",children:(0,t.jsx)(n.strong,{children:"createPool"})}),"."]}),"\n"]}),"\n",(0,t.jsxs)(r.Z,{children:[(0,t.jsx)(a.Z,{value:"Promise",default:!0,children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\n// Create the connection pool. The pool-specific settings are the defaults\nconst pool = mysql.createPool({\n host: 'localhost',\n user: 'root',\n database: 'test',\n waitForConnections: true,\n connectionLimit: 10,\n maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit`\n idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000\n queueLimit: 0,\n enableKeepAlive: true,\n keepAliveInitialDelay: 0,\n});\n"})})}),(0,t.jsx)(a.Z,{value:"Callback",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\n// Create the connection pool. The pool-specific settings are the defaults\nconst pool = mysql.createPool({\n host: 'localhost',\n user: 'root',\n database: 'test',\n waitForConnections: true,\n connectionLimit: 10,\n maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit`\n idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000\n queueLimit: 0,\n enableKeepAlive: true,\n keepAliveInitialDelay: 0,\n});\n"})})})]}),"\n",(0,t.jsx)(n.admonition,{type:"note",children:(0,t.jsx)(n.p,{children:"The pool does not create all connections upfront but creates them on demand until the connection limit is reached."})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsxs)(n.p,{children:["You can use the pool in the same way as connections (using ",(0,t.jsx)(n.code,{children:"pool.query()"})," and ",(0,t.jsx)(n.code,{children:"pool.execute()"}),"):"]}),"\n",(0,t.jsxs)(r.Z,{children:[(0,t.jsx)(a.Z,{value:"Promise",default:!0,children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"try {\n // For pool initialization, see above\n const [rows, fields] = await pool.query('SELECT `field` FROM `table`');\n // Connection is automatically released when query resolves\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,t.jsx)(a.Z,{value:"Callback",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"// For pool initialization, see above\npool.query('SELECT `field` FROM `table`', function (err, rows, fields) {\n // Connection is automatically released when query resolves\n});\n"})})})]}),"\n",(0,t.jsx)(n.p,{children:"Alternatively, there is also the possibility of manually acquiring a connection from the pool and returning it later:"}),"\n",(0,t.jsxs)(r.Z,{children:[(0,t.jsx)(a.Z,{value:"Promise",default:!0,children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"// For pool initialization, see above\nconst conn = await pool.getConnection();\n\n// Do something with the connection\nawait conn.query(/* ... */);\n\n// Don't forget to release the connection when finished!\npool.releaseConnection(conn);\n"})})}),(0,t.jsx)(a.Z,{value:"Callback",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"// For pool initialization, see above\npool.getConnection(function (err, conn) {\n // Do something with the connection\n conn.query(/* ... */);\n\n // Don't forget to release the connection when finished!\n pool.releaseConnection(conn);\n});\n"})})})]}),"\n",(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["Additionally, directly release the connection using the ",(0,t.jsx)(n.code,{children:"connection"})," object:"]}),"\n"]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"conn.release();\n"})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"using-promise-wrapper",children:"Using Promise Wrapper"}),"\n",(0,t.jsx)(n.p,{children:"MySQL2 also support Promise API. Which works very well with ES7 async await."}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\nasync function main() {\n // create the connection\n const connection = await mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n });\n\n // query database\n const [rows, fields] = await connection.execute(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Morty', 14]\n );\n}\n"})}),"\n",(0,t.jsxs)(n.p,{children:["MySQL2 use default ",(0,t.jsx)(n.code,{children:"Promise"})," object available in scope. But you can choose which ",(0,t.jsx)(n.code,{children:"Promise"})," implementation you want to use."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"// get the client\nimport mysql from 'mysql2/promise';\n\n// get the promise implementation, we will use bluebird\nimport bluebird from 'bluebird';\n\n// create the connection, specify bluebird as Promise\nconst connection = await mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n Promise: bluebird,\n});\n\n// query database\nconst [rows, fields] = await connection.execute(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Morty', 14]\n);\n"})}),"\n",(0,t.jsxs)(n.p,{children:["MySQL2 also exposes a ",(0,t.jsx)(n.code,{children:".promise()"})," function on Pools, so you can create a promise/non-promise connections from the same pool."]}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2';\n\nasync function main() {\n // create the pool\n const pool = mysql.createPool({\n host: 'localhost',\n user: 'root',\n database: 'test',\n });\n\n // now get a Promise wrapped instance of that pool\n const promisePool = pool.promise();\n\n // query database using promises\n const [rows, fields] = await promisePool.query('SELECT 1');\n}\n"})}),"\n",(0,t.jsxs)(n.p,{children:["MySQL2 exposes a ",(0,t.jsx)(n.code,{children:".promise()"}),' function on Connections, to "upgrade" an existing non-promise connection to use promise.']}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",metastring:"{11}",children:"const mysql = require('mysql2');\n\n// create the connection\nconst conn = mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n});\n\nconn\n .promise()\n .query('SELECT 1')\n .then(([rows, fields]) => {\n console.log(rows);\n })\n .catch(console.log)\n .then(() => conn.end());\n"})}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.h3,{id:"array-results",children:"Array Results"}),"\n",(0,t.jsxs)(n.p,{children:["If you have two columns with the same name, you might want to get results as an array rather than an object to prevent them from clashing. This is a deviation from the ",(0,t.jsx)(n.a,{href:"https://github.com/mysqljs/mysql",children:"Node MySQL"})," library."]}),"\n",(0,t.jsxs)(n.p,{children:["For example: ",(0,t.jsx)(n.code,{children:"SELECT 1 AS `foo`, 2 AS `foo`"}),"."]}),"\n",(0,t.jsx)(n.p,{children:"You can enable this setting at either the connection level (applies to all queries), or at the query level (applies only to that specific query)."}),"\n",(0,t.jsx)(n.h4,{id:"connection-level",children:"Connection Level"}),"\n",(0,t.jsxs)(r.Z,{children:[(0,t.jsx)(a.Z,{value:"Promise",default:!0,children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",metastring:"{5}",children:"const conn = await mysql.createConnection({\n host: 'localhost',\n database: 'test',\n user: 'root',\n rowsAsArray: true,\n});\n"})})}),(0,t.jsx)(a.Z,{value:"Callback",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",metastring:"{5}",children:"const conn = mysql.createConnection({\n host: 'localhost',\n database: 'test',\n user: 'root',\n rowsAsArray: true,\n});\n"})})})]}),"\n",(0,t.jsx)(n.h4,{id:"query-level",children:"Query Level"}),"\n",(0,t.jsxs)(r.Z,{children:[(0,t.jsx)(a.Z,{value:"Promise",default:!0,children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",metastring:"{4}",children:"try {\n const [results, fields] = await conn.query({\n sql: 'SELECT 1 AS `foo`, 2 AS `foo`',\n rowsAsArray: true,\n });\n\n console.log(results); // in this query, results will be an array of arrays rather than an array of objects\n console.log(fields); // fields are unchanged\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,t.jsx)(a.Z,{value:"Callback",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",metastring:"{4}",children:"conn.query(\n {\n sql: 'SELECT 1 AS `foo`, 2 AS `foo`',\n rowsAsArray: true,\n },\n function (err, results, fields) {\n console.log(results); // in this query, results will be an array of arrays rather than an array of objects\n console.log(fields); // fields are unchanged\n }\n);\n"})})})]}),"\n",(0,t.jsx)(n.hr,{}),"\n",(0,t.jsx)(n.admonition,{title:"Getting Help",type:"tip",children:(0,t.jsxs)(n.p,{children:["Need help? Ask your question on ",(0,t.jsx)(n.a,{href:"https://stackoverflow.com/questions/tagged/mysql2",children:"Stack Overflow"})," or ",(0,t.jsx)(n.a,{href:"https://github.com/sidorares/node-mysql2/discussions",children:"GitHub"}),".\nIf you've encountered an issue, please ",(0,t.jsx)(n.a,{href:"https://github.com/sidorares/node-mysql2/issues",children:"file it on GitHub"}),"."]})})]})}function p(e={}){const{wrapper:n}={...(0,o.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(m,{...e})}):m(e)}},5162:(e,n,s)=>{s.d(n,{Z:()=>a});s(7294);var t=s(512);const o={tabItem:"tabItem_Ymn6"};var r=s(5893);function a(e){let{children:n,hidden:s,className:a}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,t.Z)(o.tabItem,a),hidden:s,children:n})}},4866:(e,n,s)=>{s.d(n,{Z:()=>q});var t=s(7294),o=s(512),r=s(2466),a=s(6550),l=s(469),i=s(1980),c=s(7392),u=s(12);function d(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:n,children:s}=e;return(0,t.useMemo)((()=>{const e=n??function(e){return d(e).map((e=>{let{props:{value:n,label:s,attributes:t,default:o}}=e;return{value:n,label:s,attributes:t,default:o}}))}(s);return function(e){const n=(0,c.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,s])}function m(e){let{value:n,tabValues:s}=e;return s.some((e=>e.value===n))}function p(e){let{queryString:n=!1,groupId:s}=e;const o=(0,a.k6)(),r=function(e){let{queryString:n=!1,groupId:s}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:n,groupId:s});return[(0,i._X)(r),(0,t.useCallback)((e=>{if(!r)return;const n=new URLSearchParams(o.location.search);n.set(r,e),o.replace({...o.location,search:n.toString()})}),[r,o])]}function x(e){const{defaultValue:n,queryString:s=!1,groupId:o}=e,r=h(e),[a,i]=(0,t.useState)((()=>function(e){let{defaultValue:n,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const t=s.find((e=>e.default))??s[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:n,tabValues:r}))),[c,d]=p({queryString:s,groupId:o}),[x,y]=function(e){let{groupId:n}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(n),[o,r]=(0,u.Nk)(s);return[o,(0,t.useCallback)((e=>{s&&r.set(e)}),[s,r])]}({groupId:o}),f=(()=>{const e=c??x;return m({value:e,tabValues:r})?e:null})();(0,l.Z)((()=>{f&&i(f)}),[f]);return{selectedValue:a,selectValue:(0,t.useCallback)((e=>{if(!m({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),y(e)}),[d,y,r]),tabValues:r}}var y=s(2389);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var j=s(5893);function g(e){let{className:n,block:s,selectedValue:t,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.o5)(),u=e=>{const n=e.currentTarget,s=i.indexOf(n),o=l[s].value;o!==t&&(c(n),a(o))},d=e=>{let n=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=i.indexOf(e.currentTarget)+1;n=i[s]??i[0];break}case"ArrowLeft":{const s=i.indexOf(e.currentTarget)-1;n=i[s]??i[i.length-1];break}}n?.focus()};return(0,j.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":s},n),children:l.map((e=>{let{value:n,label:s,attributes:r}=e;return(0,j.jsx)("li",{role:"tab",tabIndex:t===n?0:-1,"aria-selected":t===n,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,o.Z)("tabs__item",f.tabItem,r?.className,{"tabs__item--active":t===n}),children:s??n},n)}))})}function b(e){let{lazy:n,children:s,selectedValue:o}=e;const r=(Array.isArray(s)?s:[s]).filter(Boolean);if(n){const e=r.find((e=>e.props.value===o));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,j.jsx)("div",{className:"margin-top--md",children:r.map(((e,n)=>(0,t.cloneElement)(e,{key:n,hidden:e.props.value!==o})))})}function v(e){const n=x(e);return(0,j.jsxs)("div",{className:(0,o.Z)("tabs-container",f.tabList),children:[(0,j.jsx)(g,{...e,...n}),(0,j.jsx)(b,{...e,...n})]})}function q(e){const n=(0,y.Z)();return(0,j.jsx)(v,{...e,children:d(e.children)},String(n))}},4442:(e,n,s)=>{s.d(n,{V:()=>r});var t=s(5742),o=s(5893);const r=e=>{let{title:n}=e;return(0,o.jsx)(t.Z,{children:(0,o.jsx)("title",{children:n})})}},1151:(e,n,s)=>{s.d(n,{Z:()=>l,a:()=>a});var t=s(7294);const o={},r=t.createContext(o);function a(e){const n=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),t.createElement(r.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/4edc808e.4fde5883.js b/assets/js/4edc808e.4fde5883.js deleted file mode 100644 index ec12d829ca..0000000000 --- a/assets/js/4edc808e.4fde5883.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[4173],{7559:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>d,contentTitle:()=>c,default:()=>p,frontMatter:()=>i,metadata:()=>u,toc:()=>h});var s=t(5893),o=t(1151),r=t(4866),a=t(5162),l=t(4442);const i={slug:"/",position:1,title:"Quickstart",description:"MySQL client for Node.js with focus on performance"},c="MySQL2",u={id:"index",title:"Quickstart",description:"MySQL client for Node.js with focus on performance",source:"@site/docs/index.mdx",sourceDirName:".",slug:"/",permalink:"/node-mysql2/docs/",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/index.mdx",tags:[],version:"current",frontMatter:{slug:"/",position:1,title:"Quickstart",description:"MySQL client for Node.js with focus on performance"},sidebar:"docs",next:{title:"History and Why MySQL2",permalink:"/node-mysql2/docs/history-and-why-mysq2"}},d={},h=[{value:"Installation",id:"installation",level:2},{value:"First Query",id:"first-query",level:3},{value:"Using Prepared Statements",id:"using-prepared-statements",level:3},{value:"Using Connection Pools",id:"using-connection-pools",level:3},{value:"Using Promise Wrapper",id:"using-promise-wrapper",level:3},{value:"Array Results",id:"array-results",level:3},{value:"Connection Level",id:"connection-level",level:4},{value:"Query Level",id:"query-level",level:4}];function m(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",h4:"h4",hr:"hr",img:"img",li:"li",p:"p",pre:"pre",ul:"ul",...(0,o.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(l.V,{title:"MySQL2 | Quickstart"}),"\n",(0,s.jsx)(n.h1,{id:"mysql2",children:"MySQL2"}),"\n","\n",(0,s.jsx)(n.p,{children:"MySQL client for Node.js with focus on performance. Supports prepared statements, non-utf8 encodings, binary log protocol, compression, ssl much more."}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.a,{href:"https://npmjs.org/package/mysql2",children:(0,s.jsx)(n.img,{src:"https://img.shields.io/npm/v/mysql2.svg",alt:"NPM Version"})}),"\n",(0,s.jsx)(n.a,{href:"https://npmjs.org/package/mysql2",children:(0,s.jsx)(n.img,{src:"https://img.shields.io/npm/dm/mysql2.svg",alt:"NPM Downloads"})}),"\n",(0,s.jsx)(n.a,{href:"https://nodejs.org/download/",children:(0,s.jsx)(n.img,{src:"https://img.shields.io/node/v/mysql2.svg",alt:"Node.js Version"})}),"\n",(0,s.jsx)(n.a,{href:"https://github.com/sidorares/node-mysql2/blob/master/License",children:(0,s.jsx)(n.img,{src:"https://img.shields.io/npm/l/mysql2.svg?maxAge=2592000",alt:"License"})})]}),"\n",(0,s.jsx)(n.h2,{id:"installation",children:"Installation"}),"\n",(0,s.jsx)(n.p,{children:"MySQL2 is free from native bindings and can be installed on Linux, Mac OS or Windows without any issues."}),"\n",(0,s.jsxs)(r.Z,{children:[(0,s.jsx)(a.Z,{value:"JavaScript",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save mysql2\n"})})}),(0,s.jsxs)(a.Z,{value:"TypeScript",children:[(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"npm install --save mysql2\nnpm install --save-dev @types/node\n"})}),(0,s.jsxs)(n.p,{children:["For TypeScript documentation and examples, see ",(0,s.jsx)(n.a,{href:"/docs/documentation/typescript-examples",children:"here"}),"."]})]})]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h3,{id:"first-query",children:"First Query"}),"\n",(0,s.jsxs)(r.Z,{children:[(0,s.jsx)(a.Z,{value:"Promise",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// Get the client\nimport mysql from 'mysql2/promise';\n\n// Create the connection to database\nconst connection = await mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n});\n\n// A simple SELECT query\ntry {\n const [results, fields] = await connection.query(\n 'SELECT * FROM `table` WHERE `name` = \"Page\" AND `age` > 45'\n );\n\n console.log(results); // results contains rows returned by server\n console.log(fields); // fields contains extra meta data about results, if available\n} catch (err) {\n console.log(err);\n}\n\n// Using placeholders\ntry {\n const [results] = await connection.query(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Page', 45]\n );\n\n console.log(results);\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,s.jsx)(a.Z,{value:"Callback",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// Get the client\nconst mysql = require('mysql2');\n\n// Create the connection to database\nconst connection = mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n});\n\n// A simple SELECT query\nconnection.query(\n 'SELECT * FROM `table` WHERE `name` = \"Page\" AND `age` > 45',\n function (err, results, fields) {\n console.log(results); // results contains rows returned by server\n console.log(fields); // fields contains extra meta data about results, if available\n }\n);\n\n// Using placeholders\nconnection.query(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Page', 45],\n function (err, results) {\n console.log(results);\n }\n);\n"})})})]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h3,{id:"using-prepared-statements",children:"Using Prepared Statements"}),"\n",(0,s.jsx)(n.p,{children:"With MySQL2 you also get the prepared statements. With prepared statements MySQL doesn't have to prepare plan for same query every time, this results in better performance. If you don't know why they are important, please check these discussions:"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"https://stackoverflow.com/questions/8263371/how-can-prepared-statements-protect-from-sql-injection-attacks",children:"How prepared statements can protect from SQL Injection attacks"})}),"\n"]}),"\n",(0,s.jsxs)(n.p,{children:["MySQL2 provides ",(0,s.jsx)(n.code,{children:"execute"})," helper which will prepare and query the statement. You can also manually prepare / unprepare statement with ",(0,s.jsx)(n.code,{children:"prepare"})," / ",(0,s.jsx)(n.code,{children:"unprepare"})," methods."]}),"\n",(0,s.jsxs)(r.Z,{children:[(0,s.jsx)(a.Z,{value:"Promise",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\ntry {\n // create the connection to database\n const connection = await mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n });\n\n // execute will internally call prepare and query\n const [results, fields] = await connection.execute(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Rick C-137', 53]\n );\n\n console.log(results); // results contains rows returned by server\n console.log(fields); // fields contains extra meta data about results, if available\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,s.jsx)(a.Z,{value:"Callback",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\n// create the connection to database\nconst connection = mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n});\n\n// execute will internally call prepare and query\nconnection.execute(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Rick C-137', 53],\n function (err, results, fields) {\n console.log(results); // results contains rows returned by server\n console.log(fields); // fields contains extra meta data about results, if available\n }\n);\n"})})})]}),"\n",(0,s.jsx)(n.admonition,{type:"tip",children:(0,s.jsx)(n.p,{children:"If you execute same statement again, it will be picked from a LRU cache which will save query preparation time and give better performance."})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h3,{id:"using-connection-pools",children:"Using Connection Pools"}),"\n",(0,s.jsx)(n.p,{children:"Connection pools help reduce the time spent connecting to the MySQL server by reusing a previous connection, leaving them open instead of closing when you are done with them."}),"\n",(0,s.jsx)(n.p,{children:"This improves the latency of queries as you avoid all of the overhead that comes with establishing a new connection."}),"\n",(0,s.jsxs)(r.Z,{children:[(0,s.jsx)(a.Z,{value:"Promise",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\n// Create the connection pool. The pool-specific settings are the defaults\nconst pool = mysql.createPool({\n host: 'localhost',\n user: 'root',\n database: 'test',\n waitForConnections: true,\n connectionLimit: 10,\n maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit`\n idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000\n queueLimit: 0,\n enableKeepAlive: true,\n keepAliveInitialDelay: 0,\n});\n"})})}),(0,s.jsx)(a.Z,{value:"Callback",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\n// Create the connection pool. The pool-specific settings are the defaults\nconst pool = mysql.createPool({\n host: 'localhost',\n user: 'root',\n database: 'test',\n waitForConnections: true,\n connectionLimit: 10,\n maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit`\n idleTimeout: 60000, // idle connections timeout, in milliseconds, the default value 60000\n queueLimit: 0,\n enableKeepAlive: true,\n keepAliveInitialDelay: 0,\n});\n"})})})]}),"\n",(0,s.jsx)(n.admonition,{type:"note",children:(0,s.jsx)(n.p,{children:"The pool does not create all connections upfront but creates them on demand until the connection limit is reached."})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsxs)(n.p,{children:["You can use the pool in the same way as connections (using ",(0,s.jsx)(n.code,{children:"pool.query()"})," and ",(0,s.jsx)(n.code,{children:"pool.execute()"}),"):"]}),"\n",(0,s.jsxs)(r.Z,{children:[(0,s.jsx)(a.Z,{value:"Promise",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"try {\n // For pool initialization, see above\n const [rows, fields] = await pool.query('SELECT `field` FROM `table`');\n // Connection is automatically released when query resolves\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,s.jsx)(a.Z,{value:"Callback",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// For pool initialization, see above\npool.query('SELECT `field` FROM `table`', function (err, rows, fields) {\n // Connection is automatically released when query resolves\n});\n"})})})]}),"\n",(0,s.jsx)(n.p,{children:"Alternatively, there is also the possibility of manually acquiring a connection from the pool and returning it later:"}),"\n",(0,s.jsxs)(r.Z,{children:[(0,s.jsx)(a.Z,{value:"Promise",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// For pool initialization, see above\nconst conn = await pool.getConnection();\n\n// Do something with the connection\nawait conn.query(/* ... */);\n\n// Don't forget to release the connection when finished!\npool.releaseConnection(conn);\n"})})}),(0,s.jsx)(a.Z,{value:"Callback",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// For pool initialization, see above\npool.getConnection(function (err, conn) {\n // Do something with the connection\n conn.query(/* ... */);\n\n // Don't forget to release the connection when finished!\n pool.releaseConnection(conn);\n});\n"})})})]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Additionally, directly release the connection using the ",(0,s.jsx)(n.code,{children:"connection"})," object:"]}),"\n"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"conn.release();\n"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h3,{id:"using-promise-wrapper",children:"Using Promise Wrapper"}),"\n",(0,s.jsx)(n.p,{children:"MySQL2 also support Promise API. Which works very well with ES7 async await."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\nasync function main() {\n // create the connection\n const connection = await mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n });\n\n // query database\n const [rows, fields] = await connection.execute(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Morty', 14]\n );\n}\n"})}),"\n",(0,s.jsxs)(n.p,{children:["MySQL2 use default ",(0,s.jsx)(n.code,{children:"Promise"})," object available in scope. But you can choose which ",(0,s.jsx)(n.code,{children:"Promise"})," implementation you want to use."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"// get the client\nimport mysql from 'mysql2/promise';\n\n// get the promise implementation, we will use bluebird\nimport bluebird from 'bluebird';\n\n// create the connection, specify bluebird as Promise\nconst connection = await mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n Promise: bluebird,\n});\n\n// query database\nconst [rows, fields] = await connection.execute(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Morty', 14]\n);\n"})}),"\n",(0,s.jsxs)(n.p,{children:["MySQL2 also exposes a ",(0,s.jsx)(n.code,{children:".promise()"})," function on Pools, so you can create a promise/non-promise connections from the same pool."]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2';\n\nasync function main() {\n // create the pool\n const pool = mysql.createPool({\n host: 'localhost',\n user: 'root',\n database: 'test',\n });\n\n // now get a Promise wrapped instance of that pool\n const promisePool = pool.promise();\n\n // query database using promises\n const [rows, fields] = await promisePool.query('SELECT 1');\n}\n"})}),"\n",(0,s.jsxs)(n.p,{children:["MySQL2 exposes a ",(0,s.jsx)(n.code,{children:".promise()"}),' function on Connections, to "upgrade" an existing non-promise connection to use promise.']}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",metastring:"{11}",children:"const mysql = require('mysql2');\n\n// create the connection\nconst conn = mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n});\n\nconn\n .promise()\n .query('SELECT 1')\n .then(([rows, fields]) => {\n console.log(rows);\n })\n .catch(console.log)\n .then(() => conn.end());\n"})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h3,{id:"array-results",children:"Array Results"}),"\n",(0,s.jsxs)(n.p,{children:["If you have two columns with the same name, you might want to get results as an array rather than an object to prevent them from clashing. This is a deviation from the ",(0,s.jsx)(n.a,{href:"https://github.com/mysqljs/mysql",children:"Node MySQL"})," library."]}),"\n",(0,s.jsxs)(n.p,{children:["For example: ",(0,s.jsx)(n.code,{children:"SELECT 1 AS `foo`, 2 AS `foo`"}),"."]}),"\n",(0,s.jsx)(n.p,{children:"You can enable this setting at either the connection level (applies to all queries), or at the query level (applies only to that specific query)."}),"\n",(0,s.jsx)(n.h4,{id:"connection-level",children:"Connection Level"}),"\n",(0,s.jsxs)(r.Z,{children:[(0,s.jsx)(a.Z,{value:"Promise",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",metastring:"{5}",children:"const conn = await mysql.createConnection({\n host: 'localhost',\n database: 'test',\n user: 'root',\n rowsAsArray: true,\n});\n"})})}),(0,s.jsx)(a.Z,{value:"Callback",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",metastring:"{5}",children:"const conn = mysql.createConnection({\n host: 'localhost',\n database: 'test',\n user: 'root',\n rowsAsArray: true,\n});\n"})})})]}),"\n",(0,s.jsx)(n.h4,{id:"query-level",children:"Query Level"}),"\n",(0,s.jsxs)(r.Z,{children:[(0,s.jsx)(a.Z,{value:"Promise",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",metastring:"{4}",children:"try {\n const [results, fields] = await conn.query({\n sql: 'SELECT 1 AS `foo`, 2 AS `foo`',\n rowsAsArray: true,\n });\n\n console.log(results); // in this query, results will be an array of arrays rather than an array of objects\n console.log(fields); // fields are unchanged\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,s.jsx)(a.Z,{value:"Callback",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",metastring:"{4}",children:"conn.query(\n {\n sql: 'SELECT 1 AS `foo`, 2 AS `foo`',\n rowsAsArray: true,\n },\n function (err, results, fields) {\n console.log(results); // in this query, results will be an array of arrays rather than an array of objects\n console.log(fields); // fields are unchanged\n }\n);\n"})})})]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.admonition,{title:"Getting Help",type:"tip",children:(0,s.jsxs)(n.p,{children:["Need help? Ask your question on ",(0,s.jsx)(n.a,{href:"https://stackoverflow.com/questions/tagged/mysql2",children:"Stack Overflow"})," or ",(0,s.jsx)(n.a,{href:"https://github.com/sidorares/node-mysql2/discussions",children:"GitHub"}),".\nIf you've encountered an issue, please ",(0,s.jsx)(n.a,{href:"https://github.com/sidorares/node-mysql2/issues",children:"file it on GitHub"}),"."]})})]})}function p(e={}){const{wrapper:n}={...(0,o.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(m,{...e})}):m(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>a});t(7294);var s=t(512);const o={tabItem:"tabItem_Ymn6"};var r=t(5893);function a(e){let{children:n,hidden:t,className:a}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,s.Z)(o.tabItem,a),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>q});var s=t(7294),o=t(512),r=t(2466),a=t(6550),l=t(469),i=t(1980),c=t(7392),u=t(12);function d(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:n,children:t}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return d(e).map((e=>{let{props:{value:n,label:t,attributes:s,default:o}}=e;return{value:n,label:t,attributes:s,default:o}}))}(t);return function(e){const n=(0,c.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function m(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function p(e){let{queryString:n=!1,groupId:t}=e;const o=(0,a.k6)(),r=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:n,groupId:t});return[(0,i._X)(r),(0,s.useCallback)((e=>{if(!r)return;const n=new URLSearchParams(o.location.search);n.set(r,e),o.replace({...o.location,search:n.toString()})}),[r,o])]}function y(e){const{defaultValue:n,queryString:t=!1,groupId:o}=e,r=h(e),[a,i]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=t.find((e=>e.default))??t[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:r}))),[c,d]=p({queryString:t,groupId:o}),[y,f]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[o,r]=(0,u.Nk)(t);return[o,(0,s.useCallback)((e=>{t&&r.set(e)}),[t,r])]}({groupId:o}),g=(()=>{const e=c??y;return m({value:e,tabValues:r})?e:null})();(0,l.Z)((()=>{g&&i(g)}),[g]);return{selectedValue:a,selectValue:(0,s.useCallback)((e=>{if(!m({value:e,tabValues:r}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),f(e)}),[d,f,r]),tabValues:r}}var f=t(2389);const g={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=t(5893);function j(e){let{className:n,block:t,selectedValue:s,selectValue:a,tabValues:l}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,r.o5)(),u=e=>{const n=e.currentTarget,t=i.indexOf(n),o=l[t].value;o!==s&&(c(n),a(o))},d=e=>{let n=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const t=i.indexOf(e.currentTarget)+1;n=i[t]??i[0];break}case"ArrowLeft":{const t=i.indexOf(e.currentTarget)-1;n=i[t]??i[i.length-1];break}}n?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,o.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:r}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>i.push(e),onKeyDown:d,onClick:u,...r,className:(0,o.Z)("tabs__item",g.tabItem,r?.className,{"tabs__item--active":s===n}),children:t??n},n)}))})}function b(e){let{lazy:n,children:t,selectedValue:o}=e;const r=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=r.find((e=>e.props.value===o));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:r.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==o})))})}function v(e){const n=y(e);return(0,x.jsxs)("div",{className:(0,o.Z)("tabs-container",g.tabList),children:[(0,x.jsx)(j,{...e,...n}),(0,x.jsx)(b,{...e,...n})]})}function q(e){const n=(0,f.Z)();return(0,x.jsx)(v,{...e,children:d(e.children)},String(n))}},4442:(e,n,t)=>{t.d(n,{V:()=>r});var s=t(5742),o=t(5893);const r=e=>{let{title:n}=e;return(0,o.jsx)(s.Z,{children:(0,o.jsx)("title",{children:n})})}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>a});var s=t(7294);const o={},r=s.createContext(o);function a(e){const n=s.useContext(r);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),s.createElement(r.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5020.614bd897.js b/assets/js/5020.614bd897.js new file mode 100644 index 0000000000..b95a55ddd6 --- /dev/null +++ b/assets/js/5020.614bd897.js @@ -0,0 +1 @@ +(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[5020],{9286:(e,t,n)=>{"use strict";n.d(t,{Z:()=>H});var s=n(7294),o=n(2389),c=n(512),a=n(2949),r=n(6668);function l(){const{prism:e}=(0,r.L)(),{colorMode:t}=(0,a.I)(),n=e.theme,s=e.darkTheme||n;return"dark"===t?s:n}var i=n(5281),u=n(7594),d=n.n(u);const m=/title=(? ["'])(?.*?)\1/,p=/\{(? [\d,-]+)\}/,b={js:{start:"\\/\\/",end:""},jsBlock:{start:"\\/\\*",end:"\\*\\/"},jsx:{start:"\\{\\s*\\/\\*",end:"\\*\\/\\s*\\}"},bash:{start:"#",end:""},html:{start:"\x3c!--",end:"--\x3e"}},f={...b,lua:{start:"--",end:""},wasm:{start:"\\;\\;",end:""},tex:{start:"%",end:""},vb:{start:"['\u2018\u2019]",end:""},rem:{start:"[Rr][Ee][Mm]\\b",end:""},f90:{start:"!",end:""},ml:{start:"\\(\\*",end:"\\*\\)"},cobol:{start:"\\*>",end:""}},h=Object.keys(b);function g(e,t){const n=e.map((e=>{const{start:n,end:s}=f[e];return`(?:${n}\\s*(${t.flatMap((e=>[e.line,e.block?.start,e.block?.end].filter(Boolean))).join("|")})\\s*${s})`})).join("|");return new RegExp(`^\\s*(?:${n})\\s*$`)}function k(e,t){let n=e.replace(/\n$/,"");const{language:s,magicComments:o,metastring:c}=t;if(c&&p.test(c)){const e=c.match(p).groups.range;if(0===o.length)throw new Error(`A highlight range has been given in code block's metastring (\`\`\` ${c}), but no magic comment config is available. Docusaurus applies the first magic comment entry's className for metastring ranges.`);const t=o[0].className,s=d()(e).filter((e=>e>0)).map((e=>[e-1,[t]]));return{lineClassNames:Object.fromEntries(s),code:n}}if(void 0===s)return{lineClassNames:{},code:n};const a=function(e,t){switch(e){case"js":case"javascript":case"ts":case"typescript":return g(["js","jsBlock"],t);case"jsx":case"tsx":return g(["js","jsBlock","jsx"],t);case"html":return g(["js","jsBlock","html"],t);case"python":case"py":case"bash":return g(["bash"],t);case"markdown":case"md":return g(["html","jsx","bash"],t);case"tex":case"latex":case"matlab":return g(["tex"],t);case"lua":case"haskell":case"sql":return g(["lua"],t);case"wasm":return g(["wasm"],t);case"vb":case"vbnet":case"vba":case"visual-basic":return g(["vb","rem"],t);case"batch":return g(["rem"],t);case"basic":return g(["rem","f90"],t);case"fsharp":return g(["js","ml"],t);case"ocaml":case"sml":return g(["ml"],t);case"fortran":return g(["f90"],t);case"cobol":return g(["cobol"],t);default:return g(h,t)}}(s,o),r=n.split("\n"),l=Object.fromEntries(o.map((e=>[e.className,{start:0,range:""}]))),i=Object.fromEntries(o.filter((e=>e.line)).map((e=>{let{className:t,line:n}=e;return[n,t]}))),u=Object.fromEntries(o.filter((e=>e.block)).map((e=>{let{className:t,block:n}=e;return[n.start,t]}))),m=Object.fromEntries(o.filter((e=>e.block)).map((e=>{let{className:t,block:n}=e;return[n.end,t]})));for(let d=0;d void 0!==e));i[t]?l[i[t]].range+=`${d},`:u[t]?l[u[t]].start=d:m[t]&&(l[m[t]].range+=`${l[m[t]].start}-${d-1},`),r.splice(d,1)}n=r.join("\n");const b={};return Object.entries(l).forEach((e=>{let[t,{range:n}]=e;d()(n).forEach((e=>{b[e]??=[],b[e].push(t)}))})),{lineClassNames:b,code:n}}const x={codeBlockContainer:"codeBlockContainer_Ckt0"};var j=n(5893);function B(e){let{as:t,...n}=e;const s=function(e){const t={color:"--prism-color",backgroundColor:"--prism-background-color"},n={};return Object.entries(e.plain).forEach((e=>{let[s,o]=e;const c=t[s];c&&"string"==typeof o&&(n[c]=o)})),n}(l());return(0,j.jsx)(t,{...n,style:s,className:(0,c.Z)(n.className,x.codeBlockContainer,i.k.common.codeBlock)})}const y={codeBlockContent:"codeBlockContent_biex",codeBlockTitle:"codeBlockTitle_Ktv7",codeBlock:"codeBlock_bY9V",codeBlockStandalone:"codeBlockStandalone_MEMb",codeBlockLines:"codeBlockLines_e6Vv",codeBlockLinesWithNumbering:"codeBlockLinesWithNumbering_o6Pm",buttonGroup:"buttonGroup__atx"};function v(e){let{children:t,className:n}=e;return(0,j.jsx)(B,{as:"pre",tabIndex:0,className:(0,c.Z)(y.codeBlockStandalone,"thin-scrollbar",n),children:(0,j.jsx)("code",{className:y.codeBlockLines,children:t})})}var C=n(902);const N={attributes:!0,characterData:!0,childList:!0,subtree:!0};function w(e,t){const[n,o]=(0,s.useState)(),c=(0,s.useCallback)((()=>{o(e.current?.closest("[role=tabpanel][hidden]"))}),[e,o]);(0,s.useEffect)((()=>{c()}),[c]),function(e,t,n){void 0===n&&(n=N);const o=(0,C.zX)(t),c=(0,C.Ql)(n);(0,s.useEffect)((()=>{const t=new MutationObserver(o);return e&&t.observe(e,c),()=>t.disconnect()}),[e,o,c])}(n,(e=>{e.forEach((e=>{"attributes"===e.type&&"hidden"===e.attributeName&&(t(),c())}))}),{attributes:!0,characterData:!1,childList:!1,subtree:!1})}var E=n(2573);const L={codeLine:"codeLine_lJS_",codeLineNumber:"codeLineNumber_Tfdd",codeLineContent:"codeLineContent_feaV"};function S(e){let{line:t,classNames:n,showLineNumbers:s,getLineProps:o,getTokenProps:a}=e;1===t.length&&"\n"===t[0].content&&(t[0].content="");const r=o({line:t,className:(0,c.Z)(n,s&&L.codeLine)}),l=t.map(((e,t)=>(0,j.jsx)("span",{...a({token:e,key:t})},t)));return(0,j.jsxs)("span",{...r,children:[s?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("span",{className:L.codeLineNumber}),(0,j.jsx)("span",{className:L.codeLineContent,children:l})]}):l,(0,j.jsx)("br",{})]})}var _=n(5999);function I(e){return(0,j.jsx)("svg",{viewBox:"0 0 24 24",...e,children:(0,j.jsx)("path",{fill:"currentColor",d:"M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"})})}function A(e){return(0,j.jsx)("svg",{viewBox:"0 0 24 24",...e,children:(0,j.jsx)("path",{fill:"currentColor",d:"M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"})})}const T={copyButtonCopied:"copyButtonCopied_obH4",copyButtonIcons:"copyButtonIcons_eSgA",copyButtonIcon:"copyButtonIcon_y97N",copyButtonSuccessIcon:"copyButtonSuccessIcon_LjdS"};function Z(e){let{code:t,className:n}=e;const[o,a]=(0,s.useState)(!1),r=(0,s.useRef)(void 0),l=(0,s.useCallback)((()=>{!function(e,t){let{target:n=document.body}=void 0===t?{}:t;if("string"!=typeof e)throw new TypeError(`Expected parameter \`text\` to be a \`string\`, got \`${typeof e}\`.`);const s=document.createElement("textarea"),o=document.activeElement;s.value=e,s.setAttribute("readonly",""),s.style.contain="strict",s.style.position="absolute",s.style.left="-9999px",s.style.fontSize="12pt";const c=document.getSelection(),a=c.rangeCount>0&&c.getRangeAt(0);n.append(s),s.select(),s.selectionStart=0,s.selectionEnd=e.length;let r=!1;try{r=document.execCommand("copy")}catch{}s.remove(),a&&(c.removeAllRanges(),c.addRange(a)),o&&o.focus()}(t),a(!0),r.current=window.setTimeout((()=>{a(!1)}),1e3)}),[t]);return(0,s.useEffect)((()=>()=>window.clearTimeout(r.current)),[]),(0,j.jsx)("button",{type:"button","aria-label":o?(0,_.I)({id:"theme.CodeBlock.copied",message:"Copied",description:"The copied button label on code blocks"}):(0,_.I)({id:"theme.CodeBlock.copyButtonAriaLabel",message:"Copy code to clipboard",description:"The ARIA label for copy code blocks button"}),title:(0,_.I)({id:"theme.CodeBlock.copy",message:"Copy",description:"The copy button label on code blocks"}),className:(0,c.Z)("clean-btn",n,T.copyButton,o&&T.copyButtonCopied),onClick:l,children:(0,j.jsxs)("span",{className:T.copyButtonIcons,"aria-hidden":"true",children:[(0,j.jsx)(I,{className:T.copyButtonIcon}),(0,j.jsx)(A,{className:T.copyButtonSuccessIcon})]})})}function M(e){return(0,j.jsx)("svg",{viewBox:"0 0 24 24",...e,children:(0,j.jsx)("path",{fill:"currentColor",d:"M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3l3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"})})}const $={wordWrapButtonIcon:"wordWrapButtonIcon_Bwma",wordWrapButtonEnabled:"wordWrapButtonEnabled_EoeP"};function W(e){let{className:t,onClick:n,isEnabled:s}=e;const o=(0,_.I)({id:"theme.CodeBlock.wordWrapToggle",message:"Toggle word wrap",description:"The title attribute for toggle word wrapping button of code block lines"});return(0,j.jsx)("button",{type:"button",onClick:n,className:(0,c.Z)("clean-btn",t,s&&$.wordWrapButtonEnabled),"aria-label":o,title:o,children:(0,j.jsx)(M,{className:$.wordWrapButtonIcon,"aria-hidden":"true"})})}function R(e){let{children:t,className:n="",metastring:o,title:a,showLineNumbers:i,language:u}=e;const{prism:{defaultLanguage:d,magicComments:p}}=(0,r.L)(),b=function(e){return e?.toLowerCase()}(u??function(e){const t=e.split(" ").find((e=>e.startsWith("language-")));return t?.replace(/language-/,"")}(n)??d),f=l(),h=function(){const[e,t]=(0,s.useState)(!1),[n,o]=(0,s.useState)(!1),c=(0,s.useRef)(null),a=(0,s.useCallback)((()=>{const n=c.current.querySelector("code");e?n.removeAttribute("style"):(n.style.whiteSpace="pre-wrap",n.style.overflowWrap="anywhere"),t((e=>!e))}),[c,e]),r=(0,s.useCallback)((()=>{const{scrollWidth:e,clientWidth:t}=c.current,n=e>t||c.current.querySelector("code").hasAttribute("style");o(n)}),[c]);return w(c,r),(0,s.useEffect)((()=>{r()}),[e,r]),(0,s.useEffect)((()=>(window.addEventListener("resize",r,{passive:!0}),()=>{window.removeEventListener("resize",r)})),[r]),{codeBlockRef:c,isEnabled:e,isCodeScrollable:n,toggle:a}}(),g=function(e){return e?.match(m)?.groups.title??""}(o)||a,{lineClassNames:x,code:v}=k(t,{metastring:o,language:b,magicComments:p}),C=i??function(e){return Boolean(e?.includes("showLineNumbers"))}(o);return(0,j.jsxs)(B,{as:"div",className:(0,c.Z)(n,b&&!n.includes(`language-${b}`)&&`language-${b}`),children:[g&&(0,j.jsx)("div",{className:y.codeBlockTitle,children:g}),(0,j.jsxs)("div",{className:y.codeBlockContent,children:[(0,j.jsx)(E.y$,{theme:f,code:v,language:b??"text",children:e=>{let{className:t,style:n,tokens:s,getLineProps:o,getTokenProps:a}=e;return(0,j.jsx)("pre",{tabIndex:0,ref:h.codeBlockRef,className:(0,c.Z)(t,y.codeBlock,"thin-scrollbar"),style:n,children:(0,j.jsx)("code",{className:(0,c.Z)(y.codeBlockLines,C&&y.codeBlockLinesWithNumbering),children:s.map(((e,t)=>(0,j.jsx)(S,{line:e,getLineProps:o,getTokenProps:a,classNames:x[t],showLineNumbers:C},t)))})})}}),(0,j.jsxs)("div",{className:y.buttonGroup,children:[(h.isEnabled||h.isCodeScrollable)&&(0,j.jsx)(W,{className:y.codeButton,onClick:()=>h.toggle(),isEnabled:h.isEnabled}),(0,j.jsx)(Z,{className:y.codeButton,code:v})]})]})]})}function H(e){let{children:t,...n}=e;const c=(0,o.Z)(),a=function(e){return s.Children.toArray(e).some((e=>(0,s.isValidElement)(e)))?e:Array.isArray(e)?e.join(""):e}(t),r="string"==typeof a?R:v;return(0,j.jsx)(r,{...n,children:a},String(c))}},4673:(e,t,n)=>{"use strict";n.d(t,{Z:()=>b});var s=n(7294),o=n(512),c=n(2389),a=n(6043);const r={details:"details_lb9f",isBrowser:"isBrowser_bmU9",collapsibleContent:"collapsibleContent_i85q"};var l=n(5893);function i(e){return!!e&&("SUMMARY"===e.tagName||i(e.parentElement))}function u(e,t){return!!e&&(e===t||u(e.parentElement,t))}function d(e){let{summary:t,children:n,...d}=e;const m=(0,c.Z)(),p=(0,s.useRef)(null),{collapsed:b,setCollapsed:f}=(0,a.u)({initialState:!d.open}),[h,g]=(0,s.useState)(d.open),k=s.isValidElement(t)?t:(0,l.jsx)("summary",{children:t??"Details"});return(0,l.jsxs)("details",{...d,ref:p,open:h,"data-collapsed":b,className:(0,o.Z)(r.details,m&&r.isBrowser,d.className),onMouseDown:e=>{i(e.target)&&e.detail>1&&e.preventDefault()},onClick:e=>{e.stopPropagation();const t=e.target;i(t)&&u(t,p.current)&&(e.preventDefault(),b?(f(!1),g(!0)):f(!0))},children:[k,(0,l.jsx)(a.z,{lazy:!1,collapsed:b,disableSSRStyle:!0,onCollapseTransitionEnd:e=>{f(e),g(!e)},children:(0,l.jsx)("div",{className:r.collapsibleContent,children:n})})]})}const m={details:"details_b_Ee"},p="alert alert--info";function b(e){let{...t}=e;return(0,l.jsx)(d,{...t,className:(0,o.Z)(p,m.details,t.className)})}},7594:(e,t)=>{function n(e){let t,n=[];for(let s of e.split(",").map((e=>e.trim())))if(/^-?\d+$/.test(s))n.push(parseInt(s,10));else if(t=s.match(/^(-?\d+)(-|\.\.\.?|\u2025|\u2026|\u22EF)(-?\d+)$/)){let[e,s,o,c]=t;if(s&&c){s=parseInt(s),c=parseInt(c);const e=s {"use strict";n.d(t,{Z:()=>r,a:()=>a});var s=n(7294);const o={},c=s.createContext(o);function a(e){const t=s.useContext(c);return s.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function r(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(o):e.components||o:a(e.components),s.createElement(c.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/508f32b9.cc76f031.js b/assets/js/508f32b9.cc76f031.js new file mode 100644 index 0000000000..20a36215ce --- /dev/null +++ b/assets/js/508f32b9.cc76f031.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[8453],{6193:e=>{e.exports=JSON.parse('{"label":"RDS","permalink":"/node-mysql2/docs/tags/rds","allTagsPath":"/node-mysql2/docs/tags","count":3,"items":[{"id":"examples/connections/create-connection","title":"createConnection","description":"For queries please see the Simple Queries and Prepared Statements examples.","permalink":"/node-mysql2/docs/examples/connections/create-connection"},{"id":"examples/connections/create-pool","title":"createPool","description":"For queries please see the Simple Queries and Prepared Statements examples.","permalink":"/node-mysql2/docs/examples/connections/create-pool"},{"id":"examples/connections/createPoolCluster","title":"createPoolCluster","description":"For queries please see the Simple Queries and Prepared Statements examples.","permalink":"/node-mysql2/docs/examples/connections/createPoolCluster"}],"unlisted":false}')}}]); \ No newline at end of file diff --git a/assets/js/51824e23.17207933.js b/assets/js/51824e23.17207933.js deleted file mode 100644 index a768536447..0000000000 --- a/assets/js/51824e23.17207933.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[794],{8799:e=>{e.exports=JSON.parse('{"title":"SSL","slug":"/category/ssl","permalink":"/node-mysql2/docs/category/ssl","navigation":{"previous":{"title":"Server","permalink":"/node-mysql2/docs/examples/server"},"next":{"title":"RDS SSL","permalink":"/node-mysql2/docs/examples/ssl/rds-ssl"}}}')}}]); \ No newline at end of file diff --git a/assets/js/546b1c5f.9b265e0d.js b/assets/js/546b1c5f.a8bfad30.js similarity index 84% rename from assets/js/546b1c5f.9b265e0d.js rename to assets/js/546b1c5f.a8bfad30.js index 37500cfe72..0e9e62f40a 100644 --- a/assets/js/546b1c5f.9b265e0d.js +++ b/assets/js/546b1c5f.a8bfad30.js @@ -1 +1 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[8263],{403:(e,n,o)=>{o.r(n),o.d(n,{assets:()=>a,contentTitle:()=>c,default:()=>p,frontMatter:()=>t,metadata:()=>i,toc:()=>l});var s=o(5893),r=o(1151);const t={},c="Promise Wrappers",i={id:"documentation/promise-wrapper",title:"Promise Wrappers",description:"In addition to errback interface there is thin wrapper to expose Promise-based api",source:"@site/docs/documentation/promise-wrapper.mdx",sourceDirName:"documentation",slug:"/documentation/promise-wrapper",permalink:"/node-mysql2/docs/documentation/promise-wrapper",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/documentation/promise-wrapper.mdx",tags:[],version:"current",frontMatter:{},sidebar:"docs",previous:{title:"Prepared Statements",permalink:"/node-mysql2/docs/documentation/prepared-statements"},next:{title:"Using MySQL2 with TypeScript",permalink:"/node-mysql2/docs/documentation/typescript-examples"}},a={},l=[{value:"Basic Promise",id:"basic-promise",level:2},{value:"ES7 Async Await",id:"es7-async-await",level:2},{value:"With CO",id:"with-co",level:2}];function m(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.h1,{id:"promise-wrappers",children:"Promise Wrappers"}),"\n",(0,s.jsx)(n.p,{children:"In addition to errback interface there is thin wrapper to expose Promise-based api"}),"\n",(0,s.jsx)(n.h2,{id:"basic-promise",children:"Basic Promise"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"/* eslint-env es6 */\nconst mysql = require('mysql2/promise'); // or require('mysql2').createConnectionPromise\nmysql\n .createConnection({\n /* same parameters as for non-promise createConnection */\n })\n .then((conn) => conn.query('select foo from bar'))\n .then(([rows, fields]) => console.log(rows[0].foo));\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const pool = require('mysql2/promise').createPool({}); // or require('mysql2').createPoolPromise({}) or require('mysql2').createPool({}).promise()\npool\n .getConnection()\n .then((conn) => {\n const res = conn.query('select foo from bar');\n conn.release();\n return res;\n })\n .then((result) => {\n console.log(result[0][0].foo);\n })\n .catch((err) => {\n console.log(err); // any of connection time or query time errors from above\n });\n"})}),"\n",(0,s.jsx)(n.h2,{id:"es7-async-await",children:"ES7 Async Await"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"async function example1() {\n const mysql = require('mysql2/promise');\n const conn = await mysql.createConnection({ database: test });\n const [rows, fields] = await conn.execute('select ?+? as sum', [2, 2]);\n await conn.end();\n}\n\nasync function example2() {\n const mysql = require('mysql2/promise');\n const pool = mysql.createPool({ database: test });\n // execute in parallel, next console.log in 3 seconds\n await Promise.all([\n pool.query('select sleep(2)'),\n pool.query('select sleep(3)'),\n ]);\n console.log('3 seconds after');\n await pool.end();\n}\n"})}),"\n",(0,s.jsxs)(n.h2,{id:"with-co",children:["With ",(0,s.jsx)(n.a,{href:"https://github.com/tj/co",children:"CO"})]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\nconst co = require('co');\nco(function* () {\n const c = yield mysql.createConnectionPromise({\n user: 'root',\n namedPlaceholders: true,\n });\n const rows = yield c.query('show databases');\n console.log(rows);\n console.log(yield c.execute('select 1+:toAdd as qqq', { toAdd: 10 }));\n yield c.end();\n});\n"})}),"\n",(0,s.jsxs)(n.p,{children:["Examples in ",(0,s.jsx)(n.a,{href:"/docs/examples/promise-co-await",children:"/examples/promise-co-await"})]})]})}function p(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(m,{...e})}):m(e)}},1151:(e,n,o)=>{o.d(n,{Z:()=>i,a:()=>c});var s=o(7294);const r={},t=s.createContext(r);function c(e){const n=s.useContext(t);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),s.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[8263],{403:(e,n,o)=>{o.r(n),o.d(n,{assets:()=>a,contentTitle:()=>c,default:()=>m,frontMatter:()=>t,metadata:()=>i,toc:()=>l});var s=o(5893),r=o(1151);const t={},c="Promise Wrappers",i={id:"documentation/promise-wrapper",title:"Promise Wrappers",description:"In addition to errback interface there is thin wrapper to expose Promise-based api",source:"@site/docs/documentation/promise-wrapper.mdx",sourceDirName:"documentation",slug:"/documentation/promise-wrapper",permalink:"/node-mysql2/docs/documentation/promise-wrapper",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/documentation/promise-wrapper.mdx",tags:[],version:"current",frontMatter:{},sidebar:"docs",previous:{title:"Prepared Statements",permalink:"/node-mysql2/docs/documentation/prepared-statements"},next:{title:"Using MySQL2 with TypeScript",permalink:"/node-mysql2/docs/documentation/typescript-examples"}},a={},l=[{value:"Basic Promise",id:"basic-promise",level:2},{value:"ES7 Async Await",id:"es7-async-await",level:2},{value:"With CO",id:"with-co",level:2}];function p(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",p:"p",pre:"pre",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.h1,{id:"promise-wrappers",children:"Promise Wrappers"}),"\n",(0,s.jsx)(n.p,{children:"In addition to errback interface there is thin wrapper to expose Promise-based api"}),"\n",(0,s.jsx)(n.h2,{id:"basic-promise",children:"Basic Promise"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"/* eslint-env es6 */\nconst mysql = require('mysql2/promise'); // or require('mysql2').createConnectionPromise\nmysql\n .createConnection({\n /* same parameters as for non-promise createConnection */\n })\n .then((conn) => conn.query('select foo from bar'))\n .then(([rows, fields]) => console.log(rows[0].foo));\n"})}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const pool = require('mysql2/promise').createPool({}); // or require('mysql2').createPoolPromise({}) or require('mysql2').createPool({}).promise()\npool\n .getConnection()\n .then((conn) => {\n const res = conn.query('select foo from bar');\n conn.release();\n return res;\n })\n .then((result) => {\n console.log(result[0][0].foo);\n })\n .catch((err) => {\n console.log(err); // any of connection time or query time errors from above\n });\n"})}),"\n",(0,s.jsx)(n.h2,{id:"es7-async-await",children:"ES7 Async Await"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"async function example1() {\n const mysql = require('mysql2/promise');\n const conn = await mysql.createConnection({ database: test });\n const [rows, fields] = await conn.execute('select ?+? as sum', [2, 2]);\n await conn.end();\n}\n\nasync function example2() {\n const mysql = require('mysql2/promise');\n const pool = mysql.createPool({ database: test });\n // execute in parallel, next console.log in 3 seconds\n await Promise.all([\n pool.query('select sleep(2)'),\n pool.query('select sleep(3)'),\n ]);\n console.log('3 seconds after');\n await pool.end();\n}\n"})}),"\n",(0,s.jsxs)(n.h2,{id:"with-co",children:["With ",(0,s.jsx)(n.a,{href:"https://github.com/tj/co",children:"CO"})]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\nconst co = require('co');\nco(function* () {\n const c = yield mysql.createConnectionPromise({\n user: 'root',\n namedPlaceholders: true,\n });\n const rows = yield c.query('show databases');\n console.log(rows);\n console.log(yield c.execute('select 1+:toAdd as qqq', { toAdd: 10 }));\n yield c.end();\n});\n"})}),"\n",(0,s.jsxs)(n.p,{children:["Examples in ",(0,s.jsx)(n.a,{href:"/docs/examples/promise-wrapper/co-await",children:"/examples/promise-co-await"})]})]})}function m(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(p,{...e})}):p(e)}},1151:(e,n,o)=>{o.d(n,{Z:()=>i,a:()=>c});var s=o(7294);const r={},t=s.createContext(r);function c(e){const n=s.useContext(t);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function i(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:c(e.components),s.createElement(t.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/54768732.7adc3ec4.js b/assets/js/54768732.7adc3ec4.js new file mode 100644 index 0000000000..2238e60c91 --- /dev/null +++ b/assets/js/54768732.7adc3ec4.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[576],{3990:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>h,contentTitle:()=>c,default:()=>x,frontMatter:()=>u,metadata:()=>d,toc:()=>p});var t=n(5893),s=n(1151),l=n(4866),a=n(5162),o=n(6393),i=n(4379);const u={sidebar_position:2,tags:["query"]},c="UPDATE",d={id:"examples/queries/simple-queries/update",title:"UPDATE",description:"The examples below also work for the execute method.",source:"@site/docs/examples/queries/simple-queries/update.mdx",sourceDirName:"examples/queries/simple-queries",slug:"/examples/queries/simple-queries/update",permalink:"/node-mysql2/docs/examples/queries/simple-queries/update",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/queries/simple-queries/update.mdx",tags:[{label:"query",permalink:"/node-mysql2/docs/tags/query"}],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,tags:["query"]},sidebar:"examples",previous:{title:"SELECT",permalink:"/node-mysql2/docs/examples/queries/simple-queries/select"},next:{title:"DELETE",permalink:"/node-mysql2/docs/examples/queries/simple-queries/delete"}},h={},p=[{value:"query(sql)",id:"querysql",level:2},{value:"query(options)",id:"queryoptions",level:2},{value:"Glossary",id:"glossary",level:2},{value:"ResultSetHeader",id:"resultsetheader",level:3},{value:"QueryOptions",id:"queryoptions-1",level:3}];function m(e){const r={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h1:"h1",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.h1,{id:"update",children:"UPDATE"}),"\n",(0,t.jsxs)(r.p,{children:["The examples below also work for the ",(0,t.jsx)(r.a,{href:"/docs/examples/queries/prepared-statements/update",children:(0,t.jsx)(r.code,{children:"execute"})})," method."]}),"\n",(0,t.jsx)(r.h2,{id:"querysql",children:"query(sql)"}),"\n",(0,t.jsxs)(r.blockquote,{children:["\n",(0,t.jsx)(r.p,{children:(0,t.jsx)(r.strong,{children:"query(sql: string)"})}),"\n"]}),"\n",(0,t.jsxs)(l.Z,{children:[(0,t.jsx)(a.Z,{value:"promise.js",default:!0,children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-js",children:"try {\n const sql = 'UPDATE `users` SET `age` = 20 WHERE `name` = \"Josh\" LIMIT 1';\n\n // highlight-next-line\n const [result, fields] = await connection.query(sql);\n\n console.log(result);\n console.log(fields);\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,t.jsx)(a.Z,{value:"callback.js",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-js",children:"const sql = 'UPDATE `users` SET `age` = 20 WHERE `name` = \"Josh\" LIMIT 1';\n\nconnection.query(sql, (err, result, fields) => {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n console.log(result);\n console.log(fields);\n});\n"})})})]}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.strong,{children:"result"}),": contains a ",(0,t.jsx)(r.a,{href:"#resultsetheader",children:"ResultSetHeader"})," object, which provides details about the operation executed by the server."]}),"\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.strong,{children:"fields"})," contains extra meta data about the operation, if available"]}),"\n"]}),"\n",(0,t.jsx)(r.admonition,{type:"info",children:(0,t.jsxs)(r.p,{children:["The connection used for the query (",(0,t.jsx)(r.code,{children:".query()"}),") can be obtained through the ",(0,t.jsx)(r.code,{children:"createConnection"}),", ",(0,t.jsx)(r.code,{children:"createPool"})," or ",(0,t.jsx)(r.code,{children:"createPoolCluster"})," methods."]})}),"\n",(0,t.jsx)(r.hr,{}),"\n",(0,t.jsx)(r.h2,{id:"queryoptions",children:"query(options)"}),"\n",(0,t.jsxs)(r.blockquote,{children:["\n",(0,t.jsx)(r.p,{children:(0,t.jsxs)(r.strong,{children:["query(options: ",(0,t.jsx)(r.a,{href:"#queryoptions",children:"QueryOptions"}),")"]})}),"\n"]}),"\n",(0,t.jsxs)(l.Z,{children:[(0,t.jsx)(a.Z,{value:"promise.js",default:!0,children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-js",children:"try {\n const sql = 'UPDATE `users` SET `age` = 20 WHERE `name` = \"Josh\" LIMIT 1';\n\n // highlight-start\n const [result, fields] = await connection.query({\n sql,\n // ... other options\n });\n // highlight-end\n\n console.log(result);\n console.log(fields);\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,t.jsx)(a.Z,{value:"callback.js",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-js",children:"const sql = 'UPDATE `users` SET `age` = 20 WHERE `name` = \"Josh\" LIMIT 1';\n\nconnection.query(\n {\n sql,\n // ... other options\n },\n (err, result, fields) => {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n console.log(result);\n console.log(fields);\n }\n);\n"})})})]}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.strong,{children:"result"}),": contains a ",(0,t.jsx)(r.a,{href:"#resultsetheader",children:"ResultSetHeader"})," object, which provides details about the operation executed by the server."]}),"\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.strong,{children:"fields"})," contains extra meta data about the operation, if available"]}),"\n"]}),"\n",(0,t.jsx)(r.admonition,{type:"info",children:(0,t.jsxs)(r.p,{children:["The connection used for the query (",(0,t.jsx)(r.code,{children:".query()"}),") can be obtained through the ",(0,t.jsx)(r.code,{children:"createConnection"}),", ",(0,t.jsx)(r.code,{children:"createPool"})," or ",(0,t.jsx)(r.code,{children:"createPoolCluster"})," methods."]})}),"\n",(0,t.jsx)(r.hr,{}),"\n",(0,t.jsx)(r.h2,{id:"glossary",children:"Glossary"}),"\n",(0,t.jsx)(r.h3,{id:"resultsetheader",children:"ResultSetHeader"}),"\n",(0,t.jsx)(o.Z,{title:"ResultSetHeader Specification",children:(0,t.jsx)(i.I,{language:"ts",url:"https://raw.githubusercontent.com/sidorares/node-mysql2/master/typings/mysql/lib/protocol/packets/ResultSetHeader.d.ts",extractMethod:"ResultSetHeader",methodType:"interface"})}),"\n",(0,t.jsx)(r.h3,{id:"queryoptions-1",children:"QueryOptions"}),"\n",(0,t.jsx)(o.Z,{title:"QueryOptions Specification",children:(0,t.jsx)(i.I,{language:"ts",url:"https://raw.githubusercontent.com/sidorares/node-mysql2/master/typings/mysql/lib/protocol/sequences/Query.d.ts",extractMethod:"QueryOptions",methodType:"interface"})})]})}function x(e={}){const{wrapper:r}={...(0,s.a)(),...e.components};return r?(0,t.jsx)(r,{...e,children:(0,t.jsx)(m,{...e})}):m(e)}},5162:(e,r,n)=>{n.d(r,{Z:()=>a});n(7294);var t=n(512);const s={tabItem:"tabItem_Ymn6"};var l=n(5893);function a(e){let{children:r,hidden:n,className:a}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,t.Z)(s.tabItem,a),hidden:n,children:r})}},4866:(e,r,n)=>{n.d(r,{Z:()=>v});var t=n(7294),s=n(512),l=n(2466),a=n(6550),o=n(469),i=n(1980),u=n(7392),c=n(12);function d(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:r,children:n}=e;return(0,t.useMemo)((()=>{const e=r??function(e){return d(e).map((e=>{let{props:{value:r,label:n,attributes:t,default:s}}=e;return{value:r,label:n,attributes:t,default:s}}))}(n);return function(e){const r=(0,u.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[r,n])}function p(e){let{value:r,tabValues:n}=e;return n.some((e=>e.value===r))}function m(e){let{queryString:r=!1,groupId:n}=e;const s=(0,a.k6)(),l=function(e){let{queryString:r=!1,groupId:n}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:r,groupId:n});return[(0,i._X)(l),(0,t.useCallback)((e=>{if(!l)return;const r=new URLSearchParams(s.location.search);r.set(l,e),s.replace({...s.location,search:r.toString()})}),[l,s])]}function x(e){const{defaultValue:r,queryString:n=!1,groupId:s}=e,l=h(e),[a,i]=(0,t.useState)((()=>function(e){let{defaultValue:r,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(r){if(!p({value:r,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${r}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return r}const t=n.find((e=>e.default))??n[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:r,tabValues:l}))),[u,d]=m({queryString:n,groupId:s}),[x,f]=function(e){let{groupId:r}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(r),[s,l]=(0,c.Nk)(n);return[s,(0,t.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:s}),b=(()=>{const e=u??x;return p({value:e,tabValues:l})?e:null})();(0,o.Z)((()=>{b&&i(b)}),[b]);return{selectedValue:a,selectValue:(0,t.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),f(e)}),[d,f,l]),tabValues:l}}var f=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=n(5893);function j(e){let{className:r,block:n,selectedValue:t,selectValue:a,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,l.o5)(),c=e=>{const r=e.currentTarget,n=i.indexOf(r),s=o[n].value;s!==t&&(u(r),a(s))},d=e=>{let r=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;r=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;r=i[n]??i[i.length-1];break}}r?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":n},r),children:o.map((e=>{let{value:r,label:n,attributes:l}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:t===r?0:-1,"aria-selected":t===r,ref:e=>i.push(e),onKeyDown:d,onClick:c,...l,className:(0,s.Z)("tabs__item",b.tabItem,l?.className,{"tabs__item--active":t===r}),children:n??r},r)}))})}function q(e){let{lazy:r,children:n,selectedValue:s}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(r){const e=l.find((e=>e.props.value===s));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:l.map(((e,r)=>(0,t.cloneElement)(e,{key:r,hidden:e.props.value!==s})))})}function y(e){const r=x(e);return(0,g.jsxs)("div",{className:(0,s.Z)("tabs-container",b.tabList),children:[(0,g.jsx)(j,{...e,...r}),(0,g.jsx)(q,{...e,...r})]})}function v(e){const r=(0,f.Z)();return(0,g.jsx)(y,{...e,children:d(e.children)},String(r))}},4379:(e,r,n)=>{n.d(r,{I:()=>i});var t=n(7294),s=n(2263),l=n(9286),a=n(5893);const o=()=>(0,a.jsx)("span",{className:"loader"}),i=e=>{let{url:r,language:n,extractMethod:i,methodType:u}=e;const[c,d]=(0,t.useState)(""),[h,p]=(0,t.useState)(!0),[m,x]=(0,t.useState)(!0),{siteConfig:f}=(0,s.Z)(),b=f.baseUrl.replace(/\/$/,""),g=/^\//.test(r)?`${b}${r}`:r;return(0,t.useEffect)((()=>{const e=new AbortController,r=e.signal;return fetch(g,{signal:r}).then((e=>e.text())).then((e=>{const r=i&&u?((e,r,n)=>{const t=e.split("\n"),s=`${n} ${r}`;let l=!1,a=0,o="";for(const i of t)if(i.includes(s)&&(l=!0),l&&(i.includes("{")&&a++,o+=i+"\n",i.includes("}")&&(a--,0===a)))break;return o.trim()||e})(e,i,u):e;d(r||e),p(!1),x(!1)})).catch((()=>{x(!0),p(!1)})),()=>{e.abort()}}),[g,i,u]),(0,a.jsx)(a.Fragment,{children:h?(0,a.jsx)(o,{}):(0,a.jsx)(a.Fragment,{children:m?(0,a.jsxs)("div",{children:["Unable to access the requested link: ",(0,a.jsx)("code",{children:g}),". Please verify the link or try again later."]}):(0,a.jsx)(l.Z,{className:`language-${n}`,children:c})})})}},6393:(e,r,n)=>{n.d(r,{Z:()=>l});var t=n(4673),s=n(5893);const l=e=>{let{children:r,open:n,title:l}=e;return(0,s.jsx)(t.Z,{open:n,className:"faq",summary:(0,s.jsx)("summary",{children:(0,s.jsx)("strong",{children:l})}),children:(0,s.jsx)("section",{children:r})})}}}]); \ No newline at end of file diff --git a/assets/js/54dbd6f3.7311dfcb.js b/assets/js/54dbd6f3.7311dfcb.js deleted file mode 100644 index 1b7457630b..0000000000 --- a/assets/js/54dbd6f3.7311dfcb.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[4917],{929:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>i,contentTitle:()=>u,default:()=>p,frontMatter:()=>o,metadata:()=>c,toc:()=>d});var r=n(5893),a=n(1151),s=n(4866),l=n(5162);const o={},u="SELECT",c={id:"examples/queries/select",title:"SELECT",description:"",source:"@site/docs/examples/queries/select.mdx",sourceDirName:"examples/queries",slug:"/examples/queries/select",permalink:"/node-mysql2/docs/examples/queries/select",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/queries/select.mdx",tags:[],version:"current",frontMatter:{},sidebar:"examples",previous:{title:"Queries",permalink:"/node-mysql2/docs/category/queries"},next:{title:"Server",permalink:"/node-mysql2/docs/examples/server"}},i={},d=[];function m(e){const t={code:"code",h1:"h1",pre:"pre",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(t.h1,{id:"select",children:"SELECT"}),"\n",(0,r.jsx)(s.Z,{children:(0,r.jsx)(l.Z,{value:"index.js",default:!0,children:(0,r.jsx)(t.pre,{children:(0,r.jsx)(t.code,{className:"language-js",children:"'use strict';\n\n// get the client\nconst mysql = require('mysql2');\n\n// create the connection to database\nconst connection = mysql.createConnection({\n host: 'localhost',\n user: 'root',\n database: 'test',\n});\n\n// simple query\nconnection.query(\n 'SELECT * FROM `table` WHERE `name` = \"Page\" AND `age` > 45',\n (err, results, fields) => {\n console.log(results); // results contains rows returned by server\n console.log(fields); // fields contains extra meta data about results, if available\n }\n);\n\n// with placeholder\nconnection.query(\n 'SELECT * FROM `table` WHERE `name` = ? AND `age` > ?',\n ['Page', 45],\n (err, results) => {\n console.log(results);\n }\n);\n"})})})})]})}function p(e={}){const{wrapper:t}={...(0,a.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>l});n(7294);var r=n(512);const a={tabItem:"tabItem_Ymn6"};var s=n(5893);function l(e){let{children:t,hidden:n,className:l}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,l),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7294),a=n(512),s=n(2466),l=n(6550),o=n(469),u=n(1980),c=n(7392),i=n(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:a}}=e;return{value:t,label:n,attributes:r,default:a}}))}(n);return function(e){const t=(0,c.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function p(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const a=(0,l.k6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,u._X)(s),(0,r.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(a.location.search);t.set(s,e),a.replace({...a.location,search:t.toString()})}),[s,a])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:a}=e,s=m(e),[l,u]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!p({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:s}))),[c,d]=f({queryString:n,groupId:a}),[b,h]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[a,s]=(0,i.Nk)(n);return[a,(0,r.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:a}),v=(()=>{const e=c??b;return p({value:e,tabValues:s})?e:null})();(0,o.Z)((()=>{v&&u(v)}),[v]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),h(e)}),[d,h,s]),tabValues:s}}var h=n(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=n(5893);function x(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:o}=e;const u=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),i=e=>{const t=e.currentTarget,n=u.indexOf(t),a=o[n].value;a!==r&&(c(t),l(a))},d=e=>{let t=null;switch(e.key){case"Enter":i(e);break;case"ArrowRight":{const n=u.indexOf(e.currentTarget)+1;t=u[n]??u[0];break}case"ArrowLeft":{const n=u.indexOf(e.currentTarget)-1;t=u[n]??u[u.length-1];break}}t?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>u.push(e),onKeyDown:d,onClick:i,...s,className:(0,a.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function y(e){let{lazy:t,children:n,selectedValue:a}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==a})))})}function q(e){const t=b(e);return(0,g.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,g.jsx)(x,{...e,...t}),(0,g.jsx)(y,{...e,...t})]})}function w(e){const t=(0,h.Z)();return(0,g.jsx)(q,{...e,children:d(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>l});var r=n(7294);const a={},s=r.createContext(a);function l(e){const t=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:l(e.components),r.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/54eaaaae.22d6bdf5.js b/assets/js/54eaaaae.22d6bdf5.js new file mode 100644 index 0000000000..6798dab7c5 --- /dev/null +++ b/assets/js/54eaaaae.22d6bdf5.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[1420],{1:(e,n,o)=>{o.r(n),o.d(n,{assets:()=>u,contentTitle:()=>d,default:()=>g,frontMatter:()=>a,metadata:()=>h,toc:()=>p});var s=o(5893),r=o(1151),l=o(4866),t=o(5162),c=o(6393),i=o(4379);const a={sidebar_position:2,tags:["createPool","URI","SHA1","RDS","SSL","Socks"]},d="createPool",h={id:"examples/connections/create-pool",title:"createPool",description:"For queries please see the Simple Queries and Prepared Statements examples.",source:"@site/docs/examples/connections/create-pool.mdx",sourceDirName:"examples/connections",slug:"/examples/connections/create-pool",permalink:"/node-mysql2/docs/examples/connections/create-pool",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/connections/create-pool.mdx",tags:[{label:"createPool",permalink:"/node-mysql2/docs/tags/create-pool"},{label:"URI",permalink:"/node-mysql2/docs/tags/uri"},{label:"SHA1",permalink:"/node-mysql2/docs/tags/sha-1"},{label:"RDS",permalink:"/node-mysql2/docs/tags/rds"},{label:"SSL",permalink:"/node-mysql2/docs/tags/ssl"},{label:"Socks",permalink:"/node-mysql2/docs/tags/socks"}],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,tags:["createPool","URI","SHA1","RDS","SSL","Socks"]},sidebar:"examples",previous:{title:"createConnection",permalink:"/node-mysql2/docs/examples/connections/create-connection"},next:{title:"createPoolCluster",permalink:"/node-mysql2/docs/examples/connections/createPoolCluster"}},u={},p=[{value:"createPool(connectionUri)",id:"createpoolconnectionuri",level:2},{value:"createPool(config)",id:"createpoolconfig",level:2},{value:"createPool(config) \u2014 SHA1",id:"createpoolconfig--sha1",level:2},{value:"createPool(config) \u2014 SSL",id:"createpoolconfig--ssl",level:2},{value:"createPool(config) \u2014 RDS SSL",id:"createpoolconfig--rds-ssl",level:2},{value:"Related Links",id:"related-links",level:3},{value:"createPool(config) \u2014 Socks",id:"createpoolconfig--socks",level:2},{value:"Glossary",id:"glossary",level:2},{value:"PoolOptions",id:"pooloptions",level:3}];function m(e){const n={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h1:"h1",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,r.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.h1,{id:"createpool",children:"createPool"}),"\n",(0,s.jsx)(n.admonition,{type:"info",children:(0,s.jsxs)(n.p,{children:["For queries please see the ",(0,s.jsx)(n.a,{href:"/docs/examples/queries/simple-queries",children:(0,s.jsx)(n.strong,{children:"Simple Queries"})})," and ",(0,s.jsx)(n.a,{href:"/docs/examples/queries/prepared-statements",children:(0,s.jsx)(n.strong,{children:"Prepared Statements"})})," examples."]})}),"\n",(0,s.jsx)(n.h2,{id:"createpoolconnectionuri",children:"createPool(connectionUri)"}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsx)(n.strong,{children:"createPool(connectionUri: string)"})}),"\n"]}),"\n",(0,s.jsxs)(l.Z,{children:[(0,s.jsx)(t.Z,{value:"promise.js",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\ntry {\n // highlight-start\n const pool = mysql.createPool('mysql://root:password@localhost:3306/test');\n const connection = await pool.getConnection();\n // highlight-end\n // ... some query\n\n // highlight-next-line\n connection.release();\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,s.jsx)(t.Z,{value:"callback.js",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\nconst pool = mysql.createPool('mysql://root:password@localhost:3306/test');\n\npool.getConnection(function (err, connection) {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n // ... some query\n\n connection.release();\n});\n"})})})]}),"\n",(0,s.jsxs)(n.admonition,{type:"warning",children:[(0,s.jsx)(n.p,{children:"Don't forget to release the connection when finished by using:"}),(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"pool.releaseConnection(connection)"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"connection.release()"})}),"\n"]})]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"createpoolconfig",children:"createPool(config)"}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.strong,{children:["createPool(config: ",(0,s.jsx)(n.a,{href:"#pooloptions",children:"PoolOptions"}),")"]})}),"\n"]}),"\n",(0,s.jsxs)(l.Z,{children:[(0,s.jsx)(t.Z,{value:"promise.js",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\ntry {\n // highlight-start\n const pool = mysql.createPool({\n host: 'localhost',\n user: 'root',\n database: 'test',\n // port: 3306,\n // password: '',\n });\n const connection = await pool.getConnection();\n // highlight-end\n // ... some query\n\n // highlight-next-line\n connection.release();\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,s.jsx)(t.Z,{value:"callback.js",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\nconst pool = mysql.createPool({\n host: 'localhost',\n user: 'root',\n database: 'test',\n // port: 3306,\n // password: '',\n});\n\npool.getConnection(function (err, connection) {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n // ... some query\n\n connection.release();\n});\n"})})})]}),"\n",(0,s.jsxs)(n.admonition,{type:"warning",children:[(0,s.jsx)(n.p,{children:"Don't forget to release the connection when finished by using:"}),(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"pool.releaseConnection(connection)"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"connection.release()"})}),"\n"]})]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"createpoolconfig--sha1",children:"createPool(config) \u2014 SHA1"}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.strong,{children:["createPool(config: ",(0,s.jsx)(n.a,{href:"#pooloptions",children:"PoolOptions"}),")"]})}),"\n"]}),"\n",(0,s.jsxs)(l.Z,{children:[(0,s.jsx)(t.Z,{value:"promise.js",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\ntry {\n // highlight-start\n const pool = mysql.createPool({\n // ...\n passwordSha1: Buffer.from(\n '8bb6118f8fd6935ad0876a3be34a717d32708ffd',\n 'hex'\n ),\n });\n const connection = await pool.getConnection();\n // highlight-end\n // ... some query\n\n // highlight-next-line\n connection.release();\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,s.jsx)(t.Z,{value:"callback.js",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\nconst pool = mysql.createPool({\n // ...\n passwordSha1: Buffer.from('8bb6118f8fd6935ad0876a3be34a717d32708ffd', 'hex'),\n});\n\npool.getConnection(function (err, connection) {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n // ... some query\n\n connection.release();\n});\n"})})})]}),"\n",(0,s.jsxs)(n.admonition,{type:"warning",children:[(0,s.jsx)(n.p,{children:"Don't forget to release the connection when finished by using:"}),(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"pool.releaseConnection(connection)"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"connection.release()"})}),"\n"]})]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"createpoolconfig--ssl",children:"createPool(config) \u2014 SSL"}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.strong,{children:["createPool(config: ",(0,s.jsx)(n.a,{href:"#pooloptions",children:"PoolOptions"}),")"]})}),"\n"]}),"\n",(0,s.jsxs)(l.Z,{children:[(0,s.jsx)(t.Z,{value:"promise.js",default:!0,children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\ntry {\n // highlight-start\n const pool = mysql.createPool({\n // ...\n ssl: {\n // key: fs.readFileSync('./certs/client-key.pem'),\n // cert: fs.readFileSync('./certs/client-cert.pem')\n ca: fs.readFileSync('./certs/ca-cert.pem'),\n },\n });\n const connection = await pool.getConnection();\n // highlight-end\n // ... some query\n\n // highlight-next-line\n connection.release();\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,s.jsx)(t.Z,{value:"callback.js",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\nconst pool = mysql.createPool({\n // ...\n ssl: {\n // key: fs.readFileSync('./certs/client-key.pem'),\n // cert: fs.readFileSync('./certs/client-cert.pem')\n ca: fs.readFileSync('./certs/ca-cert.pem'),\n },\n});\n\npool.getConnection(function (err, connection) {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n // ... some query\n\n connection.release();\n});\n"})})}),(0,s.jsxs)(t.Z,{value:"certs/ca-cert.pem",children:[(0,s.jsx)(i.I,{language:"plan",url:"https://raw.githubusercontent.com/sidorares/node-mysql2/master/test/fixtures/ssl/certs/ca.pem"}),(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["See ",(0,s.jsx)(n.a,{href:"https://github.com/sidorares/node-mysql2/tree/master/test/fixtures/ssl/certs",children:"ssl/certs"}),"."]}),"\n"]})]})]}),"\n",(0,s.jsxs)(n.admonition,{type:"warning",children:[(0,s.jsx)(n.p,{children:"Don't forget to release the connection when finished by using:"}),(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"pool.releaseConnection(connection)"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"connection.release()"})}),"\n"]})]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"createpoolconfig--rds-ssl",children:"createPool(config) \u2014 RDS SSL"}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.strong,{children:["createPool(config: ",(0,s.jsx)(n.a,{href:"#pooloptions",children:"PoolOptions"}),")"]})}),"\n"]}),"\n",(0,s.jsxs)(n.p,{children:["You can use ",(0,s.jsx)(n.strong,{children:"Amazon RDS"})," string as value to ssl property to connect to ",(0,s.jsx)(n.strong,{children:"Amazon RDS"})," MySQL over SSL."]}),"\n",(0,s.jsxs)(n.p,{children:["In that case ",(0,s.jsx)(n.a,{href:"https://s3.amazonaws.com/rds-downloads/mysql-ssl-ca-cert.pem",children:"https://s3.amazonaws.com/rds-downloads/mysql-ssl-ca-cert.pem"})," CA cert is used:"]}),"\n",(0,s.jsxs)(l.Z,{children:[(0,s.jsxs)(t.Z,{value:"promise.js",default:!0,children:[(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\ntry {\n // highlight-start\n const pool = mysql.createPool({\n // ...\n host: 'db.id.ap-southeast-2.rds.amazonaws.com',\n ssl: 'Amazon RDS',\n });\n const connection = await pool.getConnection();\n // highlight-end\n // ... some query\n\n // highlight-next-line\n connection.release();\n} catch (err) {\n console.log(err);\n}\n"})}),(0,s.jsx)(n.admonition,{title:"Testing",type:"tip",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"try {\n const [res] = await connection.query('SHOW `status` LIKE \"Ssl_cipher\"');\n await pool.end();\n\n console.log(res);\n} catch (err) {\n console.log(err);\n}\n"})})})]}),(0,s.jsxs)(t.Z,{value:"callback.js",children:[(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\nconst pool = mysql.createPool({\n // ...\n host: 'db.id.ap-southeast-2.rds.amazonaws.com',\n ssl: 'Amazon RDS',\n});\n\npool.getConnection(function (err, connection) {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n // ... some query\n\n connection.release();\n});\n"})}),(0,s.jsx)(n.admonition,{title:"Testing",type:"tip",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"connectionquery('SHOW `status` LIKE \"Ssl_cipher\"', function (err, res) {\n pool.end();\n\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n console.log(res);\n});\n"})})})]})]}),"\n",(0,s.jsxs)(n.admonition,{type:"warning",children:[(0,s.jsx)(n.p,{children:"Don't forget to release the connection when finished by using:"}),(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"pool.releaseConnection(connection)"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.code,{children:"connection.release()"})}),"\n"]})]}),"\n",(0,s.jsx)(n.h3,{id:"related-links",children:"Related Links"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Issues"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"https://github.com/sidorares/node-mysql2/issues/2130",children:"#2130 \u2014 Update TLS certs for Amazon RDS instances"})}),"\n"]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:[(0,s.jsx)(n.strong,{children:"Pull Requests"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"https://github.com/sidorares/node-mysql2/pull/2119",children:"#2119 \u2014 fix: make startTls code compatible with Bun"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"https://github.com/sidorares/node-mysql2/pull/2131",children:"#2131 \u2014 Update Amazon RDS SSL CA cert"})}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"createpoolconfig--socks",children:"createPool(config) \u2014 Socks"}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsx)(n.p,{children:(0,s.jsxs)(n.strong,{children:["createPool(config: ",(0,s.jsx)(n.a,{href:"#pooloptions",children:"PoolOptions"}),")"]})}),"\n"]}),"\n",(0,s.jsxs)(l.Z,{children:[(0,s.jsx)(t.Z,{value:"A.js",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\nconst SocksConnection = require('socksjs');\n\nconst socksProxy = new SocksConnection({ port: 3306 });\n// highlight-start\nconst pool = mysql.createPool({\n stream: socksProxy,\n});\n// highlight-end\n"})})}),(0,s.jsx)(t.Z,{value:"B.js",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\nconst SocksConnection = require('socksjs');\n\n// highlight-start\nconst pool = mysql.createPool({\n debug: 1,\n stream: function () {\n return new SocksConnection({ port: 3306 });\n },\n});\n// highlight-end\n"})})})]}),"\n",(0,s.jsx)(n.admonition,{title:"Testing",type:"tip",children:(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-js",children:"pool.execute('SELECT SLEEP(1.1) AS `www`', (err, rows, fields) => {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n console.log(rows, fields);\n});\n\npool.execute('SELECT SLEEP(1) AS `qqq`', (err, rows, fields) => {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n console.log(rows, fields);\n});\n\npool.execute('SELECT SLEEP(1) AS `qqq`', (err, rows, fields) => {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n console.log(rows, fields);\n});\n"})})}),"\n",(0,s.jsx)(n.hr,{}),"\n",(0,s.jsx)(n.h2,{id:"glossary",children:"Glossary"}),"\n",(0,s.jsx)(n.h3,{id:"pooloptions",children:"PoolOptions"}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"PoolOptions"})," extends all options from ",(0,s.jsx)(n.strong,{children:"ConnectionOptions"}),":"]}),"\n",(0,s.jsx)(c.Z,{title:"ConnectionOptions Specification",children:(0,s.jsx)(i.I,{language:"ts",url:"https://raw.githubusercontent.com/sidorares/node-mysql2/master/typings/mysql/lib/Connection.d.ts",extractMethod:"ConnectionOptions",methodType:"interface"})}),"\n"]}),"\n",(0,s.jsx)(c.Z,{title:"PoolOptions Specification",children:(0,s.jsx)(i.I,{language:"ts",url:"https://raw.githubusercontent.com/sidorares/node-mysql2/master/typings/mysql/lib/Pool.d.ts",extractMethod:"PoolOptions",methodType:"interface"})})]})}function g(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(m,{...e})}):m(e)}},5162:(e,n,o)=>{o.d(n,{Z:()=>t});o(7294);var s=o(512);const r={tabItem:"tabItem_Ymn6"};var l=o(5893);function t(e){let{children:n,hidden:o,className:t}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,s.Z)(r.tabItem,t),hidden:o,children:n})}},4866:(e,n,o)=>{o.d(n,{Z:()=>S});var s=o(7294),r=o(512),l=o(2466),t=o(6550),c=o(469),i=o(1980),a=o(7392),d=o(12);function h(e){return s.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,s.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function u(e){const{values:n,children:o}=e;return(0,s.useMemo)((()=>{const e=n??function(e){return h(e).map((e=>{let{props:{value:n,label:o,attributes:s,default:r}}=e;return{value:n,label:o,attributes:s,default:r}}))}(o);return function(e){const n=(0,a.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,o])}function p(e){let{value:n,tabValues:o}=e;return o.some((e=>e.value===n))}function m(e){let{queryString:n=!1,groupId:o}=e;const r=(0,t.k6)(),l=function(e){let{queryString:n=!1,groupId:o}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!o)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return o??null}({queryString:n,groupId:o});return[(0,i._X)(l),(0,s.useCallback)((e=>{if(!l)return;const n=new URLSearchParams(r.location.search);n.set(l,e),r.replace({...r.location,search:n.toString()})}),[l,r])]}function g(e){const{defaultValue:n,queryString:o=!1,groupId:r}=e,l=u(e),[t,i]=(0,s.useState)((()=>function(e){let{defaultValue:n,tabValues:o}=e;if(0===o.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:o}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${o.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const s=o.find((e=>e.default))??o[0];if(!s)throw new Error("Unexpected error: 0 tabValues");return s.value}({defaultValue:n,tabValues:l}))),[a,h]=m({queryString:o,groupId:r}),[g,x]=function(e){let{groupId:n}=e;const o=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,l]=(0,d.Nk)(o);return[r,(0,s.useCallback)((e=>{o&&l.set(e)}),[o,l])]}({groupId:r}),j=(()=>{const e=a??g;return p({value:e,tabValues:l})?e:null})();(0,c.Z)((()=>{j&&i(j)}),[j]);return{selectedValue:t,selectValue:(0,s.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),h(e),x(e)}),[h,x,l]),tabValues:l}}var x=o(2389);const j={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var f=o(5893);function y(e){let{className:n,block:o,selectedValue:s,selectValue:t,tabValues:c}=e;const i=[],{blockElementScrollPositionUntilNextRender:a}=(0,l.o5)(),d=e=>{const n=e.currentTarget,o=i.indexOf(n),r=c[o].value;r!==s&&(a(n),t(r))},h=e=>{let n=null;switch(e.key){case"Enter":d(e);break;case"ArrowRight":{const o=i.indexOf(e.currentTarget)+1;n=i[o]??i[0];break}case"ArrowLeft":{const o=i.indexOf(e.currentTarget)-1;n=i[o]??i[i.length-1];break}}n?.focus()};return(0,f.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":o},n),children:c.map((e=>{let{value:n,label:o,attributes:l}=e;return(0,f.jsx)("li",{role:"tab",tabIndex:s===n?0:-1,"aria-selected":s===n,ref:e=>i.push(e),onKeyDown:h,onClick:d,...l,className:(0,r.Z)("tabs__item",j.tabItem,l?.className,{"tabs__item--active":s===n}),children:o??n},n)}))})}function b(e){let{lazy:n,children:o,selectedValue:r}=e;const l=(Array.isArray(o)?o:[o]).filter(Boolean);if(n){const e=l.find((e=>e.props.value===r));return e?(0,s.cloneElement)(e,{className:"margin-top--md"}):null}return(0,f.jsx)("div",{className:"margin-top--md",children:l.map(((e,n)=>(0,s.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function q(e){const n=g(e);return(0,f.jsxs)("div",{className:(0,r.Z)("tabs-container",j.tabList),children:[(0,f.jsx)(y,{...e,...n}),(0,f.jsx)(b,{...e,...n})]})}function S(e){const n=(0,x.Z)();return(0,f.jsx)(q,{...e,children:h(e.children)},String(n))}},4379:(e,n,o)=>{o.d(n,{I:()=>i});var s=o(7294),r=o(2263),l=o(9286),t=o(5893);const c=()=>(0,t.jsx)("span",{className:"loader"}),i=e=>{let{url:n,language:o,extractMethod:i,methodType:a}=e;const[d,h]=(0,s.useState)(""),[u,p]=(0,s.useState)(!0),[m,g]=(0,s.useState)(!0),{siteConfig:x}=(0,r.Z)(),j=x.baseUrl.replace(/\/$/,""),f=/^\//.test(n)?`${j}${n}`:n;return(0,s.useEffect)((()=>{const e=new AbortController,n=e.signal;return fetch(f,{signal:n}).then((e=>e.text())).then((e=>{const n=i&&a?((e,n,o)=>{const s=e.split("\n"),r=`${o} ${n}`;let l=!1,t=0,c="";for(const i of s)if(i.includes(r)&&(l=!0),l&&(i.includes("{")&&t++,c+=i+"\n",i.includes("}")&&(t--,0===t)))break;return c.trim()||e})(e,i,a):e;h(n||e),p(!1),g(!1)})).catch((()=>{g(!0),p(!1)})),()=>{e.abort()}}),[f,i,a]),(0,t.jsx)(t.Fragment,{children:u?(0,t.jsx)(c,{}):(0,t.jsx)(t.Fragment,{children:m?(0,t.jsxs)("div",{children:["Unable to access the requested link: ",(0,t.jsx)("code",{children:f}),". Please verify the link or try again later."]}):(0,t.jsx)(l.Z,{className:`language-${o}`,children:d})})})}},6393:(e,n,o)=>{o.d(n,{Z:()=>l});var s=o(4673),r=o(5893);const l=e=>{let{children:n,open:o,title:l}=e;return(0,r.jsx)(s.Z,{open:o,className:"faq",summary:(0,r.jsx)("summary",{children:(0,r.jsx)("strong",{children:l})}),children:(0,r.jsx)("section",{children:n})})}}}]); \ No newline at end of file diff --git a/assets/js/55960ee5.4f929515.js b/assets/js/55960ee5.4f929515.js new file mode 100644 index 0000000000..5906fec181 --- /dev/null +++ b/assets/js/55960ee5.4f929515.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[4121],{8070:e=>{e.exports=JSON.parse('[{"label":"Prepared Statements","permalink":"/node-mysql2/docs/tags/prepared-statements","count":5},{"label":"execute","permalink":"/node-mysql2/docs/tags/execute","count":5},{"label":"createConnection","permalink":"/node-mysql2/docs/tags/create-connection","count":1},{"label":"URI","permalink":"/node-mysql2/docs/tags/uri","count":3},{"label":"SHA1","permalink":"/node-mysql2/docs/tags/sha-1","count":3},{"label":"RDS","permalink":"/node-mysql2/docs/tags/rds","count":3},{"label":"SSL","permalink":"/node-mysql2/docs/tags/ssl","count":3},{"label":"Socks","permalink":"/node-mysql2/docs/tags/socks","count":3},{"label":"createPool","permalink":"/node-mysql2/docs/tags/create-pool","count":1},{"label":"createPoolCluster","permalink":"/node-mysql2/docs/tags/create-pool-cluster","count":1},{"label":"Placeholders","permalink":"/node-mysql2/docs/tags/placeholders","count":4},{"label":"Parameters","permalink":"/node-mysql2/docs/tags/parameters","count":4},{"label":"query","permalink":"/node-mysql2/docs/tags/query","count":4}]')}}]); \ No newline at end of file diff --git a/assets/js/5748a325.8eecc32c.js b/assets/js/5748a325.8eecc32c.js deleted file mode 100644 index 9320beefc0..0000000000 --- a/assets/js/5748a325.8eecc32c.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[1647],{4444:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>i,contentTitle:()=>u,default:()=>f,frontMatter:()=>l,metadata:()=>c,toc:()=>d});var r=t(5893),a=t(1151),s=t(4866),o=t(5162);const l={},u="Server",c={id:"examples/server",title:"Server",description:"",source:"@site/docs/examples/server.mdx",sourceDirName:"examples",slug:"/examples/server",permalink:"/node-mysql2/docs/examples/server",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/server.mdx",tags:[],version:"current",frontMatter:{},sidebar:"examples",previous:{title:"SELECT",permalink:"/node-mysql2/docs/examples/queries/select"},next:{title:"SSL",permalink:"/node-mysql2/docs/category/ssl"}},i={},d=[];function m(e){const n={code:"code",h1:"h1",pre:"pre",...(0,a.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h1,{id:"server",children:"Server"}),"\n",(0,r.jsx)(s.Z,{children:(0,r.jsx)(o.Z,{value:"index.js",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"'use strict';\n\nconst mysql = require('mysql2');\nconst flags = require('mysql2/lib/constants/client.js');\nconst auth = require('mysql2/lib/auth_41.js');\n\nfunction authenticate(params, cb) {\n console.log(params);\n const doubleSha = auth.doubleSha1('pass123');\n const isValid = auth.verifyToken(\n params.authPluginData1,\n params.authPluginData2,\n params.authToken,\n doubleSha\n );\n if (isValid) {\n cb(null);\n } else {\n // for list of codes lib/constants/errors.js\n cb(null, { message: 'wrong password dude', code: 1045 });\n }\n}\n\nconst server = mysql.createServer();\nserver.listen(3333);\nserver.on('connection', (conn) => {\n // we can deny connection here:\n // conn.writeError({ message: 'secret', code: 123 });\n // conn.close();\n conn.serverHandshake({\n protocolVersion: 10,\n serverVersion: '5.6.10', // 'node.js rocks',\n connectionId: 1234,\n statusFlags: 2,\n characterSet: 8,\n // capabilityFlags: 0xffffff,\n // capabilityFlags: -2113931265,\n capabilityFlags: 2181036031,\n authCallback: authenticate,\n });\n\n conn.on('field_list', (table, fields) => {\n console.log('FIELD LIST:', table, fields);\n conn.writeEof();\n });\n\n conn.on('query', (query) => {\n conn.writeColumns([\n {\n catalog: 'def',\n schema: 'test',\n table: 'test_table',\n orgTable: 'test_table',\n name: 'beta',\n orgName: 'beta',\n characterSet: 33,\n columnLength: 384,\n columnType: 253,\n flags: 0,\n decimals: 0,\n },\n ]);\n conn.writeTextRow(['test \u0442\u0435\u0441\u0442 \u30c6\u30b9\u30c8 \u0583\u0578\u0580\u0571\u0561\u0580\u056f\u0578\u0582\u0574 \u09aa\u09b0\u09c0\u0995\u09cd\u09b7\u09be ki\u1ec3m tra ']);\n conn.writeTextRow(['\u10e2\u10d4\u10e1\u10e2\u10d8 \u0aaa\u0ab0\u0ac0\u0a95\u0acd\u0ab7\u0aa3 \u05de\u05d1\u05d7\u05df \u05e4\u05bc\u05e8\u05d5\u05d1\u05d9\u05e8\u05df \u0627\u062e\u062a\u0628\u0627\u0631 \u092a\u0930\u0940\u0915\u094d\u0937\u0923']);\n conn.writeEof();\n conn.close();\n });\n});\n"})})})})]})}function f(e={}){const{wrapper:n}={...(0,a.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(m,{...e})}):m(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>o});t(7294);var r=t(512);const a={tabItem:"tabItem_Ymn6"};var s=t(5893);function o(e){let{children:n,hidden:t,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,r.Z)(a.tabItem,o),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>k});var r=t(7294),a=t(512),s=t(2466),o=t(6550),l=t(469),u=t(1980),c=t(7392),i=t(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:n,children:t}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return d(e).map((e=>{let{props:{value:n,label:t,attributes:r,default:a}}=e;return{value:n,label:t,attributes:r,default:a}}))}(t);return function(e){const n=(0,c.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function f(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function p(e){let{queryString:n=!1,groupId:t}=e;const a=(0,o.k6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:n,groupId:t});return[(0,u._X)(s),(0,r.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(a.location.search);n.set(s,e),a.replace({...a.location,search:n.toString()})}),[s,a])]}function b(e){const{defaultValue:n,queryString:t=!1,groupId:a}=e,s=m(e),[o,u]=(0,r.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!f({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const r=t.find((e=>e.default))??t[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:n,tabValues:s}))),[c,d]=p({queryString:t,groupId:a}),[b,h]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[a,s]=(0,i.Nk)(t);return[a,(0,r.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:a}),v=(()=>{const e=c??b;return f({value:e,tabValues:s})?e:null})();(0,l.Z)((()=>{v&&u(v)}),[v]);return{selectedValue:o,selectValue:(0,r.useCallback)((e=>{if(!f({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),h(e)}),[d,h,s]),tabValues:s}}var h=t(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=t(5893);function y(e){let{className:n,block:t,selectedValue:r,selectValue:o,tabValues:l}=e;const u=[],{blockElementScrollPositionUntilNextRender:c}=(0,s.o5)(),i=e=>{const n=e.currentTarget,t=u.indexOf(n),a=l[t].value;a!==r&&(c(n),o(a))},d=e=>{let n=null;switch(e.key){case"Enter":i(e);break;case"ArrowRight":{const t=u.indexOf(e.currentTarget)+1;n=u[t]??u[0];break}case"ArrowLeft":{const t=u.indexOf(e.currentTarget)-1;n=u[t]??u[u.length-1];break}}n?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.Z)("tabs",{"tabs--block":t},n),children:l.map((e=>{let{value:n,label:t,attributes:s}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:r===n?0:-1,"aria-selected":r===n,ref:e=>u.push(e),onKeyDown:d,onClick:i,...s,className:(0,a.Z)("tabs__item",v.tabItem,s?.className,{"tabs__item--active":r===n}),children:t??n},n)}))})}function x(e){let{lazy:n,children:t,selectedValue:a}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===a));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==a})))})}function w(e){const n=b(e);return(0,g.jsxs)("div",{className:(0,a.Z)("tabs-container",v.tabList),children:[(0,g.jsx)(y,{...e,...n}),(0,g.jsx)(x,{...e,...n})]})}function k(e){const n=(0,h.Z)();return(0,g.jsx)(w,{...e,children:d(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>l,a:()=>o});var r=t(7294);const a={},s=r.createContext(a);function o(e){const n=r.useContext(s);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(a):e.components||a:o(e.components),r.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5814edec.a7313a34.js b/assets/js/5814edec.a7313a34.js deleted file mode 100644 index 988641b457..0000000000 --- a/assets/js/5814edec.a7313a34.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[3561],{3788:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>c,contentTitle:()=>l,default:()=>m,frontMatter:()=>u,metadata:()=>i,toc:()=>d});var a=n(5893),r=n(1151),s=n(4866),o=n(5162);const u={},l="Row Data Packet (Row as Array)",i={id:"examples/typescript/row-data/row-as-array",title:"Row Data Packet (Row as Array)",description:"",source:"@site/docs/examples/typescript/row-data/01-row-as-array.mdx",sourceDirName:"examples/typescript/row-data",slug:"/examples/typescript/row-data/row-as-array",permalink:"/node-mysql2/docs/examples/typescript/row-data/row-as-array",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/typescript/row-data/01-row-as-array.mdx",tags:[],version:"current",sidebarPosition:1,frontMatter:{},sidebar:"examples",previous:{title:"Row Data Packet",permalink:"/node-mysql2/docs/examples/typescript/row-data/row-data-packet"},next:{title:"Row Data Packet (Multi Statements)",permalink:"/node-mysql2/docs/examples/typescript/row-data/multi-statements"}},c={},d=[];function p(e){const t={code:"code",h1:"h1",pre:"pre",...(0,r.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(t.h1,{id:"row-data-packet-row-as-array",children:"Row Data Packet (Row as Array)"}),"\n",(0,a.jsx)(s.Z,{children:(0,a.jsx)(o.Z,{value:"index.ts",default:!0,children:(0,a.jsx)(t.pre,{children:(0,a.jsx)(t.code,{className:"language-ts",children:"/**\n * The types are explicity for learning purpose\n * By extending the `RowDataPacket`, you can use your Interface in `query` and `execute`\n */\n\nimport mysql, {\n ConnectionOptions,\n ResultSetHeader,\n RowDataPacket,\n} from 'mysql2/promise';\n\ninterface User extends RowDataPacket {\n /** id */\n 0: number;\n /** name */\n 1: string;\n}\n\n(async () => {\n const access: ConnectionOptions = {\n host: '',\n user: '',\n password: '',\n database: '',\n rowsAsArray: true,\n };\n\n const conn = await mysql.createConnection(access);\n\n /** Deleting the `users` table, if it exists */\n await conn.query ('DROP TABLE IF EXISTS `users`;');\n\n /** Creating a minimal user table */\n await conn.query (\n 'CREATE TABLE `users` (`id` INT(11) AUTO_INCREMENT, `name` VARCHAR(50), PRIMARY KEY (`id`));'\n );\n\n /** Inserting some users */\n const [inserted] = await conn.execute (\n 'INSERT INTO `users`(`name`) VALUES(?), (?), (?), (?);',\n ['Josh', 'John', 'Marie', 'Gween']\n );\n\n console.log('Inserted:', inserted.affectedRows);\n\n /** Getting users */\n const [users] = await conn.query (\n 'SELECT * FROM `users` ORDER BY `name` ASC;'\n );\n\n users.forEach((user) => {\n console.log('-----------');\n console.log('id: ', user[0]);\n console.log('name:', user[1]);\n });\n\n await conn.end();\n})();\n\n/** Output\n *\n * Inserted: 4\n * -----------\n * id: 4\n * name: Gween\n * -----------\n * id: 2\n * name: John\n * -----------\n * id: 1\n * name: Josh\n * -----------\n * id: 3\n * name: Marie\n */\n"})})})})]})}function m(e={}){const{wrapper:t}={...(0,r.a)(),...e.components};return t?(0,a.jsx)(t,{...e,children:(0,a.jsx)(p,{...e})}):p(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>o});n(7294);var a=n(512);const r={tabItem:"tabItem_Ymn6"};var s=n(5893);function o(e){let{children:t,hidden:n,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,a.Z)(r.tabItem,o),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>k});var a=n(7294),r=n(512),s=n(2466),o=n(6550),u=n(469),l=n(1980),i=n(7392),c=n(12);function d(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,a.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:a,default:r}}=e;return{value:t,label:n,attributes:a,default:r}}))}(n);return function(e){const t=(0,i.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function m(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:n}=e;const r=(0,o.k6)(),s=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,l._X)(s),(0,a.useCallback)((e=>{if(!s)return;const t=new URLSearchParams(r.location.search);t.set(s,e),r.replace({...r.location,search:t.toString()})}),[s,r])]}function h(e){const{defaultValue:t,queryString:n=!1,groupId:r}=e,s=p(e),[o,l]=(0,a.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const a=n.find((e=>e.default))??n[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:t,tabValues:s}))),[i,d]=f({queryString:n,groupId:r}),[h,b]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[r,s]=(0,c.Nk)(n);return[r,(0,a.useCallback)((e=>{n&&s.set(e)}),[n,s])]}({groupId:r}),w=(()=>{const e=i??h;return m({value:e,tabValues:s})?e:null})();(0,u.Z)((()=>{w&&l(w)}),[w]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),b(e)}),[d,b,s]),tabValues:s}}var b=n(2389);const w={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=n(5893);function v(e){let{className:t,block:n,selectedValue:a,selectValue:o,tabValues:u}=e;const l=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.o5)(),c=e=>{const t=e.currentTarget,n=l.indexOf(t),r=u[n].value;r!==a&&(i(t),o(r))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=l.indexOf(e.currentTarget)+1;t=l[n]??l[0];break}case"ArrowLeft":{const n=l.indexOf(e.currentTarget)-1;t=l[n]??l[l.length-1];break}}t?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":n},t),children:u.map((e=>{let{value:t,label:n,attributes:s}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:a===t?0:-1,"aria-selected":a===t,ref:e=>l.push(e),onKeyDown:d,onClick:c,...s,className:(0,r.Z)("tabs__item",w.tabItem,s?.className,{"tabs__item--active":a===t}),children:n??t},t)}))})}function g(e){let{lazy:t,children:n,selectedValue:r}=e;const s=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=s.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:s.map(((e,t)=>(0,a.cloneElement)(e,{key:t,hidden:e.props.value!==r})))})}function x(e){const t=h(e);return(0,y.jsxs)("div",{className:(0,r.Z)("tabs-container",w.tabList),children:[(0,y.jsx)(v,{...e,...t}),(0,y.jsx)(g,{...e,...t})]})}function k(e){const t=(0,b.Z)();return(0,y.jsx)(x,{...e,children:d(e.children)},String(t))}},1151:(e,t,n)=>{n.d(t,{Z:()=>u,a:()=>o});var a=n(7294);const r={},s=a.createContext(r);function o(e){const t=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function u(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),a.createElement(s.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/5814edec.dcf7d68b.js b/assets/js/5814edec.dcf7d68b.js new file mode 100644 index 0000000000..457291315c --- /dev/null +++ b/assets/js/5814edec.dcf7d68b.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[3561],{3788:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>m,frontMatter:()=>u,metadata:()=>i,toc:()=>d});var a=t(5893),r=t(1151),s=t(4866),o=t(5162);const u={},l="Row Data Packet (Row as Array)",i={id:"examples/typescript/row-data/row-as-array",title:"Row Data Packet (Row as Array)",description:"",source:"@site/docs/examples/typescript/row-data/01-row-as-array.mdx",sourceDirName:"examples/typescript/row-data",slug:"/examples/typescript/row-data/row-as-array",permalink:"/node-mysql2/docs/examples/typescript/row-data/row-as-array",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/typescript/row-data/01-row-as-array.mdx",tags:[],version:"current",sidebarPosition:1,frontMatter:{},sidebar:"examples",previous:{title:"Row Data Packet",permalink:"/node-mysql2/docs/examples/typescript/row-data/index"},next:{title:"Row Data Packet (Multi Statements)",permalink:"/node-mysql2/docs/examples/typescript/row-data/multi-statements"}},c={},d=[];function p(e){const n={code:"code",h1:"h1",pre:"pre",...(0,r.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.h1,{id:"row-data-packet-row-as-array",children:"Row Data Packet (Row as Array)"}),"\n",(0,a.jsx)(s.Z,{children:(0,a.jsx)(o.Z,{value:"index.ts",default:!0,children:(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-ts",children:"/**\n * The types are explicity for learning purpose\n * By extending the `RowDataPacket`, you can use your Interface in `query` and `execute`\n */\n\nimport mysql, {\n ConnectionOptions,\n ResultSetHeader,\n RowDataPacket,\n} from 'mysql2/promise';\n\ninterface User extends RowDataPacket {\n /** id */\n 0: number;\n /** name */\n 1: string;\n}\n\n(async () => {\n const access: ConnectionOptions = {\n host: '',\n user: '',\n password: '',\n database: '',\n rowsAsArray: true,\n };\n\n const conn = await mysql.createConnection(access);\n\n /** Deleting the `users` table, if it exists */\n await conn.query ('DROP TABLE IF EXISTS `users`;');\n\n /** Creating a minimal user table */\n await conn.query (\n 'CREATE TABLE `users` (`id` INT(11) AUTO_INCREMENT, `name` VARCHAR(50), PRIMARY KEY (`id`));'\n );\n\n /** Inserting some users */\n const [inserted] = await conn.execute (\n 'INSERT INTO `users`(`name`) VALUES(?), (?), (?), (?);',\n ['Josh', 'John', 'Marie', 'Gween']\n );\n\n console.log('Inserted:', inserted.affectedRows);\n\n /** Getting users */\n const [users] = await conn.query (\n 'SELECT * FROM `users` ORDER BY `name` ASC;'\n );\n\n users.forEach((user) => {\n console.log('-----------');\n console.log('id: ', user[0]);\n console.log('name:', user[1]);\n });\n\n await conn.end();\n})();\n\n/** Output\n *\n * Inserted: 4\n * -----------\n * id: 4\n * name: Gween\n * -----------\n * id: 2\n * name: John\n * -----------\n * id: 1\n * name: Josh\n * -----------\n * id: 3\n * name: Marie\n */\n"})})})})]})}function m(e={}){const{wrapper:n}={...(0,r.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(p,{...e})}):p(e)}},5162:(e,n,t)=>{t.d(n,{Z:()=>o});t(7294);var a=t(512);const r={tabItem:"tabItem_Ymn6"};var s=t(5893);function o(e){let{children:n,hidden:t,className:o}=e;return(0,s.jsx)("div",{role:"tabpanel",className:(0,a.Z)(r.tabItem,o),hidden:t,children:n})}},4866:(e,n,t)=>{t.d(n,{Z:()=>k});var a=t(7294),r=t(512),s=t(2466),o=t(6550),u=t(469),l=t(1980),i=t(7392),c=t(12);function d(e){return a.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,a.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:n,children:t}=e;return(0,a.useMemo)((()=>{const e=n??function(e){return d(e).map((e=>{let{props:{value:n,label:t,attributes:a,default:r}}=e;return{value:n,label:t,attributes:a,default:r}}))}(t);return function(e){const n=(0,i.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,t])}function m(e){let{value:n,tabValues:t}=e;return t.some((e=>e.value===n))}function f(e){let{queryString:n=!1,groupId:t}=e;const r=(0,o.k6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return t??null}({queryString:n,groupId:t});return[(0,l._X)(s),(0,a.useCallback)((e=>{if(!s)return;const n=new URLSearchParams(r.location.search);n.set(s,e),r.replace({...r.location,search:n.toString()})}),[s,r])]}function h(e){const{defaultValue:n,queryString:t=!1,groupId:r}=e,s=p(e),[o,l]=(0,a.useState)((()=>function(e){let{defaultValue:n,tabValues:t}=e;if(0===t.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!m({value:n,tabValues:t}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${t.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const a=t.find((e=>e.default))??t[0];if(!a)throw new Error("Unexpected error: 0 tabValues");return a.value}({defaultValue:n,tabValues:s}))),[i,d]=f({queryString:t,groupId:r}),[h,b]=function(e){let{groupId:n}=e;const t=function(e){return e?`docusaurus.tab.${e}`:null}(n),[r,s]=(0,c.Nk)(t);return[r,(0,a.useCallback)((e=>{t&&s.set(e)}),[t,s])]}({groupId:r}),w=(()=>{const e=i??h;return m({value:e,tabValues:s})?e:null})();(0,u.Z)((()=>{w&&l(w)}),[w]);return{selectedValue:o,selectValue:(0,a.useCallback)((e=>{if(!m({value:e,tabValues:s}))throw new Error(`Can't select invalid tab value=${e}`);l(e),d(e),b(e)}),[d,b,s]),tabValues:s}}var b=t(2389);const w={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var y=t(5893);function v(e){let{className:n,block:t,selectedValue:a,selectValue:o,tabValues:u}=e;const l=[],{blockElementScrollPositionUntilNextRender:i}=(0,s.o5)(),c=e=>{const n=e.currentTarget,t=l.indexOf(n),r=u[t].value;r!==a&&(i(n),o(r))},d=e=>{let n=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const t=l.indexOf(e.currentTarget)+1;n=l[t]??l[0];break}case"ArrowLeft":{const t=l.indexOf(e.currentTarget)-1;n=l[t]??l[l.length-1];break}}n?.focus()};return(0,y.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.Z)("tabs",{"tabs--block":t},n),children:u.map((e=>{let{value:n,label:t,attributes:s}=e;return(0,y.jsx)("li",{role:"tab",tabIndex:a===n?0:-1,"aria-selected":a===n,ref:e=>l.push(e),onKeyDown:d,onClick:c,...s,className:(0,r.Z)("tabs__item",w.tabItem,s?.className,{"tabs__item--active":a===n}),children:t??n},n)}))})}function g(e){let{lazy:n,children:t,selectedValue:r}=e;const s=(Array.isArray(t)?t:[t]).filter(Boolean);if(n){const e=s.find((e=>e.props.value===r));return e?(0,a.cloneElement)(e,{className:"margin-top--md"}):null}return(0,y.jsx)("div",{className:"margin-top--md",children:s.map(((e,n)=>(0,a.cloneElement)(e,{key:n,hidden:e.props.value!==r})))})}function x(e){const n=h(e);return(0,y.jsxs)("div",{className:(0,r.Z)("tabs-container",w.tabList),children:[(0,y.jsx)(v,{...e,...n}),(0,y.jsx)(g,{...e,...n})]})}function k(e){const n=(0,b.Z)();return(0,y.jsx)(x,{...e,children:d(e.children)},String(n))}},1151:(e,n,t)=>{t.d(n,{Z:()=>u,a:()=>o});var a=t(7294);const r={},s=a.createContext(r);function o(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function u(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/59e52bc2.2b8c3e3c.js b/assets/js/59e52bc2.2b8c3e3c.js new file mode 100644 index 0000000000..dbcc2dc863 --- /dev/null +++ b/assets/js/59e52bc2.2b8c3e3c.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[641],{8602:(e,r,n)=>{n.r(r),n.d(r,{assets:()=>h,contentTitle:()=>u,default:()=>x,frontMatter:()=>c,metadata:()=>d,toc:()=>p});var t=n(5893),s=n(1151),l=n(4866),a=n(5162),o=n(6393),i=n(4379);const c={sidebar_position:3,tags:["query"]},u="DELETE",d={id:"examples/queries/simple-queries/delete",title:"DELETE",description:"The examples below also work for the execute method.",source:"@site/docs/examples/queries/simple-queries/delete.mdx",sourceDirName:"examples/queries/simple-queries",slug:"/examples/queries/simple-queries/delete",permalink:"/node-mysql2/docs/examples/queries/simple-queries/delete",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/queries/simple-queries/delete.mdx",tags:[{label:"query",permalink:"/node-mysql2/docs/tags/query"}],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3,tags:["query"]},sidebar:"examples",previous:{title:"UPDATE",permalink:"/node-mysql2/docs/examples/queries/simple-queries/update"},next:{title:"Prepared Statements",permalink:"/node-mysql2/docs/examples/queries/prepared-statements/"}},h={},p=[{value:"query(sql)",id:"querysql",level:2},{value:"query(options)",id:"queryoptions",level:2},{value:"Glossary",id:"glossary",level:2},{value:"ResultSetHeader",id:"resultsetheader",level:3},{value:"QueryOptions",id:"queryoptions-1",level:3}];function m(e){const r={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h1:"h1",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,s.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.h1,{id:"delete",children:"DELETE"}),"\n",(0,t.jsxs)(r.p,{children:["The examples below also work for the ",(0,t.jsx)(r.a,{href:"/docs/examples/queries/prepared-statements/delete",children:(0,t.jsx)(r.code,{children:"execute"})})," method."]}),"\n",(0,t.jsx)(r.h2,{id:"querysql",children:"query(sql)"}),"\n",(0,t.jsxs)(r.blockquote,{children:["\n",(0,t.jsx)(r.p,{children:(0,t.jsx)(r.strong,{children:"query(sql: string)"})}),"\n"]}),"\n",(0,t.jsxs)(l.Z,{children:[(0,t.jsx)(a.Z,{value:"promise.js",default:!0,children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-js",children:"try {\n const sql = 'DELETE FROM `users` WHERE `name` = \"Page\" LIMIT 1';\n\n // highlight-next-line\n const [result, fields] = await connection.query(sql);\n\n console.log(result);\n console.log(fields);\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,t.jsx)(a.Z,{value:"callback.js",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-js",children:"const sql = 'DELETE FROM `users` WHERE `name` = \"Page\" LIMIT 1';\n\nconnection.query(sql, (err, result, fields) => {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n console.log(result);\n console.log(fields);\n});\n"})})})]}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.strong,{children:"result"}),": contains a ",(0,t.jsx)(r.a,{href:"#resultsetheader",children:"ResultSetHeader"})," object, which provides details about the operation executed by the server."]}),"\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.strong,{children:"fields"})," contains extra meta data about the operation, if available"]}),"\n"]}),"\n",(0,t.jsx)(r.admonition,{type:"info",children:(0,t.jsxs)(r.p,{children:["The connection used for the query (",(0,t.jsx)(r.code,{children:".query()"}),") can be obtained through the ",(0,t.jsx)(r.code,{children:"createConnection"}),", ",(0,t.jsx)(r.code,{children:"createPool"})," or ",(0,t.jsx)(r.code,{children:"createPoolCluster"})," methods."]})}),"\n",(0,t.jsx)(r.hr,{}),"\n",(0,t.jsx)(r.h2,{id:"queryoptions",children:"query(options)"}),"\n",(0,t.jsxs)(r.blockquote,{children:["\n",(0,t.jsx)(r.p,{children:(0,t.jsxs)(r.strong,{children:["query(options: ",(0,t.jsx)(r.a,{href:"#queryoptions",children:"QueryOptions"}),")"]})}),"\n"]}),"\n",(0,t.jsxs)(l.Z,{children:[(0,t.jsx)(a.Z,{value:"promise.js",default:!0,children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-js",children:"try {\n const sql = 'DELETE FROM `users` WHERE `name` = \"Page\" LIMIT 1';\n\n // highlight-start\n const [result, fields] = await connection.query({\n sql,\n // ... other options\n });\n // highlight-end\n\n console.log(result);\n console.log(fields);\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,t.jsx)(a.Z,{value:"callback.js",children:(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-js",children:"const sql = 'DELETE FROM `users` WHERE `name` = \"Page\" LIMIT 1';\n\nconnection.query(\n {\n sql,\n // ... other options\n },\n (err, result, fields) => {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n console.log(result);\n console.log(fields);\n }\n);\n"})})})]}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.strong,{children:"result"}),": contains a ",(0,t.jsx)(r.a,{href:"#resultsetheader",children:"ResultSetHeader"})," object, which provides details about the operation executed by the server."]}),"\n",(0,t.jsxs)(r.li,{children:[(0,t.jsx)(r.strong,{children:"fields"})," contains extra meta data about the operation, if available"]}),"\n"]}),"\n",(0,t.jsx)(r.admonition,{type:"info",children:(0,t.jsxs)(r.p,{children:["The connection used for the query (",(0,t.jsx)(r.code,{children:".query()"}),") can be obtained through the ",(0,t.jsx)(r.code,{children:"createConnection"}),", ",(0,t.jsx)(r.code,{children:"createPool"})," or ",(0,t.jsx)(r.code,{children:"createPoolCluster"})," methods."]})}),"\n",(0,t.jsx)(r.hr,{}),"\n",(0,t.jsx)(r.h2,{id:"glossary",children:"Glossary"}),"\n",(0,t.jsx)(r.h3,{id:"resultsetheader",children:"ResultSetHeader"}),"\n",(0,t.jsx)(o.Z,{title:"ResultSetHeader Specification",children:(0,t.jsx)(i.I,{language:"ts",url:"https://raw.githubusercontent.com/sidorares/node-mysql2/master/typings/mysql/lib/protocol/packets/ResultSetHeader.d.ts",extractMethod:"ResultSetHeader",methodType:"interface"})}),"\n",(0,t.jsx)(r.h3,{id:"queryoptions-1",children:"QueryOptions"}),"\n",(0,t.jsx)(o.Z,{title:"QueryOptions Specification",children:(0,t.jsx)(i.I,{language:"ts",url:"https://raw.githubusercontent.com/sidorares/node-mysql2/master/typings/mysql/lib/protocol/sequences/Query.d.ts",extractMethod:"QueryOptions",methodType:"interface"})})]})}function x(e={}){const{wrapper:r}={...(0,s.a)(),...e.components};return r?(0,t.jsx)(r,{...e,children:(0,t.jsx)(m,{...e})}):m(e)}},5162:(e,r,n)=>{n.d(r,{Z:()=>a});n(7294);var t=n(512);const s={tabItem:"tabItem_Ymn6"};var l=n(5893);function a(e){let{children:r,hidden:n,className:a}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,t.Z)(s.tabItem,a),hidden:n,children:r})}},4866:(e,r,n)=>{n.d(r,{Z:()=>v});var t=n(7294),s=n(512),l=n(2466),a=n(6550),o=n(469),i=n(1980),c=n(7392),u=n(12);function d(e){return t.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,t.isValidElement)(e)&&function(e){const{props:r}=e;return!!r&&"object"==typeof r&&"value"in r}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:r,children:n}=e;return(0,t.useMemo)((()=>{const e=r??function(e){return d(e).map((e=>{let{props:{value:r,label:n,attributes:t,default:s}}=e;return{value:r,label:n,attributes:t,default:s}}))}(n);return function(e){const r=(0,c.l)(e,((e,r)=>e.value===r.value));if(r.length>0)throw new Error(`Docusaurus error: Duplicate values "${r.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[r,n])}function p(e){let{value:r,tabValues:n}=e;return n.some((e=>e.value===r))}function m(e){let{queryString:r=!1,groupId:n}=e;const s=(0,a.k6)(),l=function(e){let{queryString:r=!1,groupId:n}=e;if("string"==typeof r)return r;if(!1===r)return null;if(!0===r&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:r,groupId:n});return[(0,i._X)(l),(0,t.useCallback)((e=>{if(!l)return;const r=new URLSearchParams(s.location.search);r.set(l,e),s.replace({...s.location,search:r.toString()})}),[l,s])]}function x(e){const{defaultValue:r,queryString:n=!1,groupId:s}=e,l=h(e),[a,i]=(0,t.useState)((()=>function(e){let{defaultValue:r,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(r){if(!p({value:r,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${r}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return r}const t=n.find((e=>e.default))??n[0];if(!t)throw new Error("Unexpected error: 0 tabValues");return t.value}({defaultValue:r,tabValues:l}))),[c,d]=m({queryString:n,groupId:s}),[x,f]=function(e){let{groupId:r}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(r),[s,l]=(0,u.Nk)(n);return[s,(0,t.useCallback)((e=>{n&&l.set(e)}),[n,l])]}({groupId:s}),b=(()=>{const e=c??x;return p({value:e,tabValues:l})?e:null})();(0,o.Z)((()=>{b&&i(b)}),[b]);return{selectedValue:a,selectValue:(0,t.useCallback)((e=>{if(!p({value:e,tabValues:l}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),f(e)}),[d,f,l]),tabValues:l}}var f=n(2389);const b={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var g=n(5893);function j(e){let{className:r,block:n,selectedValue:t,selectValue:a,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:c}=(0,l.o5)(),u=e=>{const r=e.currentTarget,n=i.indexOf(r),s=o[n].value;s!==t&&(c(r),a(s))},d=e=>{let r=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;r=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;r=i[n]??i[i.length-1];break}}r?.focus()};return(0,g.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":n},r),children:o.map((e=>{let{value:r,label:n,attributes:l}=e;return(0,g.jsx)("li",{role:"tab",tabIndex:t===r?0:-1,"aria-selected":t===r,ref:e=>i.push(e),onKeyDown:d,onClick:u,...l,className:(0,s.Z)("tabs__item",b.tabItem,l?.className,{"tabs__item--active":t===r}),children:n??r},r)}))})}function y(e){let{lazy:r,children:n,selectedValue:s}=e;const l=(Array.isArray(n)?n:[n]).filter(Boolean);if(r){const e=l.find((e=>e.props.value===s));return e?(0,t.cloneElement)(e,{className:"margin-top--md"}):null}return(0,g.jsx)("div",{className:"margin-top--md",children:l.map(((e,r)=>(0,t.cloneElement)(e,{key:r,hidden:e.props.value!==s})))})}function q(e){const r=x(e);return(0,g.jsxs)("div",{className:(0,s.Z)("tabs-container",b.tabList),children:[(0,g.jsx)(j,{...e,...r}),(0,g.jsx)(y,{...e,...r})]})}function v(e){const r=(0,f.Z)();return(0,g.jsx)(q,{...e,children:d(e.children)},String(r))}},4379:(e,r,n)=>{n.d(r,{I:()=>i});var t=n(7294),s=n(2263),l=n(9286),a=n(5893);const o=()=>(0,a.jsx)("span",{className:"loader"}),i=e=>{let{url:r,language:n,extractMethod:i,methodType:c}=e;const[u,d]=(0,t.useState)(""),[h,p]=(0,t.useState)(!0),[m,x]=(0,t.useState)(!0),{siteConfig:f}=(0,s.Z)(),b=f.baseUrl.replace(/\/$/,""),g=/^\//.test(r)?`${b}${r}`:r;return(0,t.useEffect)((()=>{const e=new AbortController,r=e.signal;return fetch(g,{signal:r}).then((e=>e.text())).then((e=>{const r=i&&c?((e,r,n)=>{const t=e.split("\n"),s=`${n} ${r}`;let l=!1,a=0,o="";for(const i of t)if(i.includes(s)&&(l=!0),l&&(i.includes("{")&&a++,o+=i+"\n",i.includes("}")&&(a--,0===a)))break;return o.trim()||e})(e,i,c):e;d(r||e),p(!1),x(!1)})).catch((()=>{x(!0),p(!1)})),()=>{e.abort()}}),[g,i,c]),(0,a.jsx)(a.Fragment,{children:h?(0,a.jsx)(o,{}):(0,a.jsx)(a.Fragment,{children:m?(0,a.jsxs)("div",{children:["Unable to access the requested link: ",(0,a.jsx)("code",{children:g}),". Please verify the link or try again later."]}):(0,a.jsx)(l.Z,{className:`language-${n}`,children:u})})})}},6393:(e,r,n)=>{n.d(r,{Z:()=>l});var t=n(4673),s=n(5893);const l=e=>{let{children:r,open:n,title:l}=e;return(0,s.jsx)(t.Z,{open:n,className:"faq",summary:(0,s.jsx)("summary",{children:(0,s.jsx)("strong",{children:l})}),children:(0,s.jsx)("section",{children:r})})}}}]); \ No newline at end of file diff --git a/assets/js/75b440d9.c009f4a3.js b/assets/js/75b440d9.c009f4a3.js deleted file mode 100644 index a7034550a7..0000000000 --- a/assets/js/75b440d9.c009f4a3.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[9521],{3083:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>i,contentTitle:()=>u,default:()=>m,frontMatter:()=>o,metadata:()=>c,toc:()=>d});var n=r(5893),s=r(1151),a=r(4866),l=r(5162);const o={},u="Select Over SSL",c={id:"examples/ssl/select-over-ssl",title:"Select Over SSL",description:"- See examples/ssl/certs.",source:"@site/docs/examples/ssl/select-over-ssl.mdx",sourceDirName:"examples/ssl",slug:"/examples/ssl/select-over-ssl",permalink:"/node-mysql2/docs/examples/ssl/select-over-ssl",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/ssl/select-over-ssl.mdx",tags:[],version:"current",frontMatter:{},sidebar:"examples",previous:{title:"RDS SSL",permalink:"/node-mysql2/docs/examples/ssl/rds-ssl"},next:{title:"TypeScript",permalink:"/node-mysql2/docs/category/typescript"}},i={},d=[];function p(e){const t={a:"a",code:"code",h1:"h1",li:"li",pre:"pre",ul:"ul",...(0,s.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.h1,{id:"select-over-ssl",children:"Select Over SSL"}),"\n",(0,n.jsx)(a.Z,{children:(0,n.jsx)(l.Z,{value:"index.js",default:!0,children:(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:"language-js",children:"'use strict';\n\nconst fs = require('fs');\nconst mysql = require('mysql2');\n\nconst conn = mysql.createConnection({\n user: 'root',\n password: '',\n database: 'test',\n host: '127.0.0.1',\n port: '3306',\n ssl: {\n // key: fs.readFileSync('./certs/client-key.pem'),\n // cert: fs.readFileSync('./certs/client-cert.pem')\n ca: fs.readFileSync('./certs/ca-cert.pem'),\n },\n});\n\nconn.query('select 1+1 as test', function (err, res) {\n console.log(res);\n conn.query('select repeat(\"a\", 100) as test', function (err, res) {\n console.log(res);\n });\n});\n"})})})}),"\n",(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsxs)(t.li,{children:["See ",(0,n.jsx)(t.a,{href:"https://github.com/sidorares/node-mysql2/tree/master/examples/ssl/certs",children:"examples/ssl/certs"}),"."]}),"\n"]})]})}function m(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(p,{...e})}):p(e)}},5162:(e,t,r)=>{r.d(t,{Z:()=>l});r(7294);var n=r(512);const s={tabItem:"tabItem_Ymn6"};var a=r(5893);function l(e){let{children:t,hidden:r,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,n.Z)(s.tabItem,l),hidden:r,children:t})}},4866:(e,t,r)=>{r.d(t,{Z:()=>w});var n=r(7294),s=r(512),a=r(2466),l=r(6550),o=r(469),u=r(1980),c=r(7392),i=r(12);function d(e){return n.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,n.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:r}=e;return(0,n.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:r,attributes:n,default:s}}=e;return{value:t,label:r,attributes:n,default:s}}))}(r);return function(e){const t=(0,c.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,r])}function m(e){let{value:t,tabValues:r}=e;return r.some((e=>e.value===t))}function f(e){let{queryString:t=!1,groupId:r}=e;const s=(0,l.k6)(),a=function(e){let{queryString:t=!1,groupId:r}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!r)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return r??null}({queryString:t,groupId:r});return[(0,u._X)(a),(0,n.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(s.location.search);t.set(a,e),s.replace({...s.location,search:t.toString()})}),[a,s])]}function h(e){const{defaultValue:t,queryString:r=!1,groupId:s}=e,a=p(e),[l,u]=(0,n.useState)((()=>function(e){let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!m({value:t,tabValues:r}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${r.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const n=r.find((e=>e.default))??r[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:t,tabValues:a}))),[c,d]=f({queryString:r,groupId:s}),[h,b]=function(e){let{groupId:t}=e;const r=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,a]=(0,i.Nk)(r);return[s,(0,n.useCallback)((e=>{r&&a.set(e)}),[r,a])]}({groupId:s}),v=(()=>{const e=c??h;return m({value:e,tabValues:a})?e:null})();(0,o.Z)((()=>{v&&u(v)}),[v]);return{selectedValue:l,selectValue:(0,n.useCallback)((e=>{if(!m({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);u(e),d(e),b(e)}),[d,b,a]),tabValues:a}}var b=r(2389);const v={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var x=r(5893);function y(e){let{className:t,block:r,selectedValue:n,selectValue:l,tabValues:o}=e;const u=[],{blockElementScrollPositionUntilNextRender:c}=(0,a.o5)(),i=e=>{const t=e.currentTarget,r=u.indexOf(t),s=o[r].value;s!==n&&(c(t),l(s))},d=e=>{let t=null;switch(e.key){case"Enter":i(e);break;case"ArrowRight":{const r=u.indexOf(e.currentTarget)+1;t=u[r]??u[0];break}case"ArrowLeft":{const r=u.indexOf(e.currentTarget)-1;t=u[r]??u[u.length-1];break}}t?.focus()};return(0,x.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":r},t),children:o.map((e=>{let{value:t,label:r,attributes:a}=e;return(0,x.jsx)("li",{role:"tab",tabIndex:n===t?0:-1,"aria-selected":n===t,ref:e=>u.push(e),onKeyDown:d,onClick:i,...a,className:(0,s.Z)("tabs__item",v.tabItem,a?.className,{"tabs__item--active":n===t}),children:r??t},t)}))})}function g(e){let{lazy:t,children:r,selectedValue:s}=e;const a=(Array.isArray(r)?r:[r]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===s));return e?(0,n.cloneElement)(e,{className:"margin-top--md"}):null}return(0,x.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,n.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function S(e){const t=h(e);return(0,x.jsxs)("div",{className:(0,s.Z)("tabs-container",v.tabList),children:[(0,x.jsx)(y,{...e,...t}),(0,x.jsx)(g,{...e,...t})]})}function w(e){const t=(0,b.Z)();return(0,x.jsx)(S,{...e,children:d(e.children)},String(t))}},1151:(e,t,r)=>{r.d(t,{Z:()=>o,a:()=>l});var n=r(7294);const s={},a=n.createContext(s);function l(e){const t=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),n.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/76dfa484.7a147334.js b/assets/js/76dfa484.7a147334.js deleted file mode 100644 index 3d902766cd..0000000000 --- a/assets/js/76dfa484.7a147334.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[3433],{7345:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>d,contentTitle:()=>i,default:()=>h,frontMatter:()=>c,metadata:()=>u,toc:()=>m});var r=s(5893),t=s(1151),o=s(4866),a=s(5162),l=s(4442);const c={slug:"/examples",title:"Introduction"},i="Examples",u={id:"examples/index",title:"Introduction",description:"Simple SELECT",source:"@site/docs/examples/00-index.mdx",sourceDirName:"examples",slug:"/examples",permalink:"/node-mysql2/docs/examples",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/00-index.mdx",tags:[],version:"current",sidebarPosition:0,frontMatter:{slug:"/examples",title:"Introduction"},sidebar:"examples",next:{title:"Binlog Watcher",permalink:"/node-mysql2/docs/examples/binlog-watcher"}},d={},m=[{value:"Simple SELECT
",id:"simple-select",level:2},{value:"Prepared Statement and Parameters",id:"prepared-statement-and-parameters",level:2},{value:"Connecting over encrypted connection",id:"connecting-over-encrypted-connection",level:2},{value:"Simple MySQL proxy server",id:"simple-mysql-proxy-server",level:2},{value:"Examples using MySQL server API",id:"examples-using-mysql-server-api",level:2}];function p(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",hr:"hr",li:"li",p:"p",pre:"pre",ul:"ul",...(0,t.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(l.V,{title:"Examples"}),"\n",(0,r.jsx)(n.h1,{id:"examples",children:"Examples"}),"\n",(0,r.jsxs)(n.h2,{id:"simple-select",children:["Simple ",(0,r.jsx)(n.code,{children:"SELECT"})]}),"\n",(0,r.jsxs)(o.Z,{children:[(0,r.jsx)(a.Z,{value:"Promise",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\nconst connection = await mysql.createConnection({\n user: 'test',\n database: 'test',\n});\n\nconst [rows] = await connection.query('SELECT 1+1 AS `test1`');\n// ...\n"})})}),(0,r.jsx)(a.Z,{value:"Callback",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\nconst connection = mysql.createConnection({\n user: 'test',\n database: 'test',\n});\n\nconnection.query('SELECT 1+1 AS `test1`', (err, rows) => {\n // ...\n});\n"})})})]}),"\n",(0,r.jsx)(n.hr,{}),"\n",(0,r.jsx)(n.h2,{id:"prepared-statement-and-parameters",children:"Prepared Statement and Parameters"}),"\n",(0,r.jsxs)(o.Z,{children:[(0,r.jsx)(a.Z,{value:"Promise",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\nconst connection = await mysql.createConnection({\n user: 'test',\n database: 'test',\n});\n\nconst [rows] = await connection.execute('SELECT 1+? AS `test1`', [10]);\n// ...\n"})})}),(0,r.jsx)(a.Z,{value:"Callback",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\nconst connection = mysql.createConnection({\n user: 'test',\n database: 'test',\n});\n\nconnection.execute('SELECT 1+? as test1', [10], (err, rows) => {\n // ...\n});\n"})})})]}),"\n",(0,r.jsx)(n.hr,{}),"\n",(0,r.jsx)(n.h2,{id:"connecting-over-encrypted-connection",children:"Connecting over encrypted connection"}),"\n",(0,r.jsxs)(o.Z,{children:[(0,r.jsx)(a.Z,{value:"Promise",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"import fs from 'fs';\nimport mysql from 'mysql2/promise';\n\nconst connection = await mysql.createConnection({\n user: 'test',\n database: 'test',\n ssl: {\n key: fs.readFileSync('./certs/client-key.pem'),\n cert: fs.readFileSync('./certs/client-cert.pem'),\n },\n});\n\nconsole.log(await connection.query('SELECT 1+1 AS `test1`'));\n"})})}),(0,r.jsx)(a.Z,{value:"Callback",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"const fs = require('fs');\nconst mysql = require('mysql2');\n\nconst connection = mysql.createConnection({\n user: 'test',\n database: 'test',\n ssl: {\n key: fs.readFileSync('./certs/client-key.pem'),\n cert: fs.readFileSync('./certs/client-cert.pem'),\n },\n});\n\nconnection.query('SELECT 1+1 AS `test1`', console.log);\n"})})})]}),"\n",(0,r.jsxs)(n.p,{children:["You can use 'Amazon RDS' string as value to ssl property to connect to Amazon RDS mysql over ssl (in that case ",(0,r.jsx)(n.a,{href:"https://s3.amazonaws.com/rds-downloads/mysql-ssl-ca-cert.pem",children:"https://s3.amazonaws.com/rds-downloads/mysql-ssl-ca-cert.pem"})," CA cert is used)"]}),"\n",(0,r.jsxs)(o.Z,{children:[(0,r.jsx)(a.Z,{value:"Promise",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"import mysql from 'mysql2/promise';\n\ntry {\n const connection = await mysql.createConnection({\n user: 'foo',\n password: 'bar',\n host: 'db.id.ap-southeast-2.rds.amazonaws.com',\n ssl: 'Amazon RDS',\n });\n\n const [res] = await connection.query(\"SHOW `status` LIKE 'Ssl_cipher'\");\n\n console.log(res);\n connection.end();\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,r.jsx)(a.Z,{value:"Callback",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\nconst connection = mysql.createConnection({\n user: 'foo',\n password: 'bar',\n host: 'db.id.ap-southeast-2.rds.amazonaws.com',\n ssl: 'Amazon RDS',\n});\n\nconnection.query(\"SHOW `status` LIKE 'Ssl_cipher'\", (err, res) => {\n console.log(err, res);\n connection.end();\n});\n"})})})]}),"\n",(0,r.jsx)(n.hr,{}),"\n",(0,r.jsx)(n.h2,{id:"simple-mysql-proxy-server",children:"Simple MySQL proxy server"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"const mysql = require('mysql2');\n\nconst server = mysql.createServer();\nserver.listen(3307);\nserver.on('connection', (conn) => {\n console.log('connection');\n\n conn.serverHandshake({\n protocolVersion: 10,\n serverVersion: 'node.js rocks',\n connectionId: 1234,\n statusFlags: 2,\n characterSet: 8,\n capabilityFlags: 0xffffff,\n });\n\n conn.on('field_list', (table, fields) => {\n console.log('field list:', table, fields);\n conn.writeEof();\n });\n\n const remote = mysql.createConnection({\n user: 'root',\n database: 'dbname',\n host: 'server.example.com',\n password: 'secret',\n });\n\n conn.on('query', (sql) => {\n console.log(`proxying query: ${sql}`);\n remote.query(sql, function (err) {\n // overloaded args, either (err, result :object)\n // or (err, rows :array, columns :array)\n if (Array.isArray(arguments[1])) {\n // response to a 'select', 'show' or similar\n const rows = arguments[1],\n columns = arguments[2];\n console.log('rows', rows);\n console.log('columns', columns);\n conn.writeTextResult(rows, columns);\n } else {\n // response to an 'insert', 'update' or 'delete'\n const result = arguments[1];\n console.log('result', result);\n conn.writeOk(result);\n }\n });\n });\n\n conn.on('end', remote.end.bind(remote));\n});\n"})}),"\n",(0,r.jsx)(n.hr,{}),"\n",(0,r.jsx)(n.h2,{id:"examples-using-mysql-server-api",children:"Examples using MySQL server API"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"https://github.com/sidorares/mysql-pg-proxy",children:"MySQL-pg-proxy"})," - MySQL to Postgres proxy server."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"https://github.com/sidorares/mysqlite.js",children:"MySQLite.js"})," - MySQL server with JS-only (emscripten compiled) sqlite backend."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"https://github.com/eugeneware/sql-engine",children:"SQL-engine"})," - MySQL server with LevelDB backend."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"https://github.com/sidorares/mysql-osquery-proxy",children:"MySQL-osquery-proxy"})," - Connect to ",(0,r.jsx)(n.a,{href:"https://osquery.io/",children:"facebook osquery"})," using MySQL client"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.a,{href:"https://github.com/implydata/plyql",children:"PlyQL"})," - Connect to ",(0,r.jsx)(n.a,{href:"https://druid.io/",children:"Druid"})," using MySQL client"]}),"\n"]})]})}function h(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},5162:(e,n,s)=>{s.d(n,{Z:()=>a});s(7294);var r=s(512);const t={tabItem:"tabItem_Ymn6"};var o=s(5893);function a(e){let{children:n,hidden:s,className:a}=e;return(0,o.jsx)("div",{role:"tabpanel",className:(0,r.Z)(t.tabItem,a),hidden:s,children:n})}},4866:(e,n,s)=>{s.d(n,{Z:()=>q});var r=s(7294),t=s(512),o=s(2466),a=s(6550),l=s(469),c=s(1980),i=s(7392),u=s(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Badchild <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function m(e){const{values:n,children:s}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return d(e).map((e=>{let{props:{value:n,label:s,attributes:r,default:t}}=e;return{value:n,label:s,attributes:r,default:t}}))}(s);return function(e){const n=(0,i.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,s])}function p(e){let{value:n,tabValues:s}=e;return s.some((e=>e.value===n))}function h(e){let{queryString:n=!1,groupId:s}=e;const t=(0,a.k6)(),o=function(e){let{queryString:n=!1,groupId:s}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!s)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:n,groupId:s});return[(0,c._X)(o),(0,r.useCallback)((e=>{if(!o)return;const n=new URLSearchParams(t.location.search);n.set(o,e),t.replace({...t.location,search:n.toString()})}),[o,t])]}function y(e){const{defaultValue:n,queryString:s=!1,groupId:t}=e,o=m(e),[a,c]=(0,r.useState)((()=>function(e){let{defaultValue:n,tabValues:s}=e;if(0===s.length)throw new Error("Docusaurus error: the component requires at least one children component");if(n){if(!p({value:n,tabValues:s}))throw new Error(`Docusaurus error: The has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${s.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}const r=s.find((e=>e.default))??s[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:n,tabValues:o}))),[i,d]=h({queryString:s,groupId:t}),[y,x]=function(e){let{groupId:n}=e;const s=function(e){return e?`docusaurus.tab.${e}`:null}(n),[t,o]=(0,u.Nk)(s);return[t,(0,r.useCallback)((e=>{s&&o.set(e)}),[s,o])]}({groupId:t}),f=(()=>{const e=i??y;return p({value:e,tabValues:o})?e:null})();(0,l.Z)((()=>{f&&c(f)}),[f]);return{selectedValue:a,selectValue:(0,r.useCallback)((e=>{if(!p({value:e,tabValues:o}))throw new Error(`Can't select invalid tab value=${e}`);c(e),d(e),x(e)}),[d,x,o]),tabValues:o}}var x=s(2389);const f={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var b=s(5893);function g(e){let{className:n,block:s,selectedValue:r,selectValue:a,tabValues:l}=e;const c=[],{blockElementScrollPositionUntilNextRender:i}=(0,o.o5)(),u=e=>{const n=e.currentTarget,s=c.indexOf(n),t=l[s].value;t!==r&&(i(n),a(t))},d=e=>{let n=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=c.indexOf(e.currentTarget)+1;n=c[s]??c[0];break}case"ArrowLeft":{const s=c.indexOf(e.currentTarget)-1;n=c[s]??c[c.length-1];break}}n?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,t.Z)("tabs",{"tabs--block":s},n),children:l.map((e=>{let{value:n,label:s,attributes:o}=e;return(0,b.jsx)("li",{role:"tab",tabIndex:r===n?0:-1,"aria-selected":r===n,ref:e=>c.push(e),onKeyDown:d,onClick:u,...o,className:(0,t.Z)("tabs__item",f.tabItem,o?.className,{"tabs__item--active":r===n}),children:s??n},n)}))})}function v(e){let{lazy:n,children:s,selectedValue:t}=e;const o=(Array.isArray(s)?s:[s]).filter(Boolean);if(n){const e=o.find((e=>e.props.value===t));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:o.map(((e,n)=>(0,r.cloneElement)(e,{key:n,hidden:e.props.value!==t})))})}function j(e){const n=y(e);return(0,b.jsxs)("div",{className:(0,t.Z)("tabs-container",f.tabList),children:[(0,b.jsx)(g,{...e,...n}),(0,b.jsx)(v,{...e,...n})]})}function q(e){const n=(0,x.Z)();return(0,b.jsx)(j,{...e,children:d(e.children)},String(n))}},4442:(e,n,s)=>{s.d(n,{V:()=>o});var r=s(5742),t=s(5893);const o=e=>{let{title:n}=e;return(0,t.jsx)(r.Z,{children:(0,t.jsx)("title",{children:n})})}},1151:(e,n,s)=>{s.d(n,{Z:()=>l,a:()=>a});var r=s(7294);const t={},o=r.createContext(t);function a(e){const n=r.useContext(o);return r.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:a(e.components),r.createElement(o.Provider,{value:n},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/76dfa484.abc20e14.js b/assets/js/76dfa484.abc20e14.js new file mode 100644 index 0000000000..b85b9d3d0a --- /dev/null +++ b/assets/js/76dfa484.abc20e14.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[3433],{7345:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>u,contentTitle:()=>o,default:()=>p,frontMatter:()=>l,metadata:()=>i,toc:()=>c});var r=n(5893),s=n(1151),a=(n(4866),n(5162),n(4442));const l={slug:"/examples",title:"Introduction"},o="Examples",i={id:"examples/index",title:"Introduction",description:"To explore the examples, please use the sidebar navigation on desktop or access the menu on mobile devices.",source:"@site/docs/examples/00-index.mdx",sourceDirName:"examples",slug:"/examples",permalink:"/node-mysql2/docs/examples",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/00-index.mdx",tags:[],version:"current",sidebarPosition:0,frontMatter:{slug:"/examples",title:"Introduction"},sidebar:"examples",next:{title:"createConnection",permalink:"/node-mysql2/docs/examples/connections/create-connection"}},u={},c=[{value:"Examples using MySQL server API",id:"examples-using-mysql-server-api",level:2}];function d(e){const t={a:"a",admonition:"admonition",h1:"h1",h2:"h2",li:"li",p:"p",strong:"strong",ul:"ul",...(0,s.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(a.V,{title:"Examples"}),"\n",(0,r.jsx)(t.h1,{id:"examples",children:"Examples"}),"\n",(0,r.jsx)(t.admonition,{type:"tip",children:(0,r.jsxs)(t.p,{children:["To explore the examples, please use the ",(0,r.jsx)(t.strong,{children:"sidebar navigation"})," on desktop or access the ",(0,r.jsx)(t.strong,{children:"menu"})," on mobile devices."]})}),"\n",(0,r.jsx)(t.h2,{id:"examples-using-mysql-server-api",children:"Examples using MySQL server API"}),"\n",(0,r.jsxs)(t.ul,{children:["\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://github.com/sidorares/mysql-pg-proxy",children:"MySQL-pg-proxy"})," - MySQL to Postgres proxy server."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://github.com/sidorares/mysqlite.js",children:"MySQLite.js"})," - MySQL server with JS-only (emscripten compiled) sqlite backend."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://github.com/eugeneware/sql-engine",children:"SQL-engine"})," - MySQL server with LevelDB backend."]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://github.com/sidorares/mysql-osquery-proxy",children:"MySQL-osquery-proxy"})," - Connect to ",(0,r.jsx)(t.a,{href:"https://osquery.io/",children:"facebook osquery"})," using MySQL client"]}),"\n",(0,r.jsxs)(t.li,{children:[(0,r.jsx)(t.a,{href:"https://github.com/implydata/plyql",children:"PlyQL"})," - Connect to ",(0,r.jsx)(t.a,{href:"https://druid.io/",children:"Druid"})," using MySQL client"]}),"\n"]})]})}function p(e={}){const{wrapper:t}={...(0,s.a)(),...e.components};return t?(0,r.jsx)(t,{...e,children:(0,r.jsx)(d,{...e})}):d(e)}},5162:(e,t,n)=>{n.d(t,{Z:()=>l});n(7294);var r=n(512);const s={tabItem:"tabItem_Ymn6"};var a=n(5893);function l(e){let{children:t,hidden:n,className:l}=e;return(0,a.jsx)("div",{role:"tabpanel",className:(0,r.Z)(s.tabItem,l),hidden:n,children:t})}},4866:(e,t,n)=>{n.d(t,{Z:()=>w});var r=n(7294),s=n(512),a=n(2466),l=n(6550),o=n(469),i=n(1980),u=n(7392),c=n(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:t}=e;return!!t&&"object"==typeof t&&"value"in t}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function p(e){const{values:t,children:n}=e;return(0,r.useMemo)((()=>{const e=t??function(e){return d(e).map((e=>{let{props:{value:t,label:n,attributes:r,default:s}}=e;return{value:t,label:n,attributes:r,default:s}}))}(n);return function(e){const t=(0,u.l)(e,((e,t)=>e.value===t.value));if(t.length>0)throw new Error(`Docusaurus error: Duplicate values "${t.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[t,n])}function h(e){let{value:t,tabValues:n}=e;return n.some((e=>e.value===t))}function m(e){let{queryString:t=!1,groupId:n}=e;const s=(0,l.k6)(),a=function(e){let{queryString:t=!1,groupId:n}=e;if("string"==typeof t)return t;if(!1===t)return null;if(!0===t&&!n)throw new Error('Docusaurus error: The component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return n??null}({queryString:t,groupId:n});return[(0,i._X)(a),(0,r.useCallback)((e=>{if(!a)return;const t=new URLSearchParams(s.location.search);t.set(a,e),s.replace({...s.location,search:t.toString()})}),[a,s])]}function b(e){const{defaultValue:t,queryString:n=!1,groupId:s}=e,a=p(e),[l,i]=(0,r.useState)((()=>function(e){let{defaultValue:t,tabValues:n}=e;if(0===n.length)throw new Error("Docusaurus error: the component requires at least one children component");if(t){if(!h({value:t,tabValues:n}))throw new Error(`Docusaurus error: The has a defaultValue "${t}" but none of its children has the corresponding value. Available values are: ${n.map((e=>e.value)).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return t}const r=n.find((e=>e.default))??n[0];if(!r)throw new Error("Unexpected error: 0 tabValues");return r.value}({defaultValue:t,tabValues:a}))),[u,d]=m({queryString:n,groupId:s}),[b,f]=function(e){let{groupId:t}=e;const n=function(e){return e?`docusaurus.tab.${e}`:null}(t),[s,a]=(0,c.Nk)(n);return[s,(0,r.useCallback)((e=>{n&&a.set(e)}),[n,a])]}({groupId:s}),x=(()=>{const e=u??b;return h({value:e,tabValues:a})?e:null})();(0,o.Z)((()=>{x&&i(x)}),[x]);return{selectedValue:l,selectValue:(0,r.useCallback)((e=>{if(!h({value:e,tabValues:a}))throw new Error(`Can't select invalid tab value=${e}`);i(e),d(e),f(e)}),[d,f,a]),tabValues:a}}var f=n(2389);const x={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var v=n(5893);function g(e){let{className:t,block:n,selectedValue:r,selectValue:l,tabValues:o}=e;const i=[],{blockElementScrollPositionUntilNextRender:u}=(0,a.o5)(),c=e=>{const t=e.currentTarget,n=i.indexOf(t),s=o[n].value;s!==r&&(u(t),l(s))},d=e=>{let t=null;switch(e.key){case"Enter":c(e);break;case"ArrowRight":{const n=i.indexOf(e.currentTarget)+1;t=i[n]??i[0];break}case"ArrowLeft":{const n=i.indexOf(e.currentTarget)-1;t=i[n]??i[i.length-1];break}}t?.focus()};return(0,v.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,s.Z)("tabs",{"tabs--block":n},t),children:o.map((e=>{let{value:t,label:n,attributes:a}=e;return(0,v.jsx)("li",{role:"tab",tabIndex:r===t?0:-1,"aria-selected":r===t,ref:e=>i.push(e),onKeyDown:d,onClick:c,...a,className:(0,s.Z)("tabs__item",x.tabItem,a?.className,{"tabs__item--active":r===t}),children:n??t},t)}))})}function y(e){let{lazy:t,children:n,selectedValue:s}=e;const a=(Array.isArray(n)?n:[n]).filter(Boolean);if(t){const e=a.find((e=>e.props.value===s));return e?(0,r.cloneElement)(e,{className:"margin-top--md"}):null}return(0,v.jsx)("div",{className:"margin-top--md",children:a.map(((e,t)=>(0,r.cloneElement)(e,{key:t,hidden:e.props.value!==s})))})}function j(e){const t=b(e);return(0,v.jsxs)("div",{className:(0,s.Z)("tabs-container",x.tabList),children:[(0,v.jsx)(g,{...e,...t}),(0,v.jsx)(y,{...e,...t})]})}function w(e){const t=(0,f.Z)();return(0,v.jsx)(j,{...e,children:d(e.children)},String(t))}},4442:(e,t,n)=>{n.d(t,{V:()=>a});var r=n(5742),s=n(5893);const a=e=>{let{title:t}=e;return(0,s.jsx)(r.Z,{children:(0,s.jsx)("title",{children:t})})}},1151:(e,t,n)=>{n.d(t,{Z:()=>o,a:()=>l});var r=n(7294);const s={},a=r.createContext(s);function l(e){const t=r.useContext(a);return r.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function o(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),r.createElement(a.Provider,{value:t},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/76e64282.205811b1.js b/assets/js/76e64282.205811b1.js deleted file mode 100644 index 5f2a4f69a6..0000000000 --- a/assets/js/76e64282.205811b1.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[9416],{743:e=>{e.exports=JSON.parse('{"title":"Procedure Call Packet","slug":"/category/procedure-call-packet","permalink":"/node-mysql2/docs/category/procedure-call-packet","navigation":{"previous":{"title":"Basic Custom Class","permalink":"/node-mysql2/docs/examples/typescript/basic-custom-class"},"next":{"title":"Procedure Call Packet","permalink":"/node-mysql2/docs/examples/typescript/procedure-call/procedure-call-packet"}}}')}}]); \ No newline at end of file diff --git a/assets/js/7ccab252.53d7e12b.js b/assets/js/7ccab252.53d7e12b.js new file mode 100644 index 0000000000..083a7a7911 --- /dev/null +++ b/assets/js/7ccab252.53d7e12b.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[8054],{3467:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>c,contentTitle:()=>i,default:()=>o,frontMatter:()=>a,metadata:()=>d,toc:()=>l});var n=t(5893),r=t(1151);const a={},i="Prepared Statements",d={id:"examples/queries/prepared-statements/index",title:"Prepared Statements",description:"MySQL2 provides execute helper which will prepare and query the statement.",source:"@site/docs/examples/queries/prepared-statements/index.mdx",sourceDirName:"examples/queries/prepared-statements",slug:"/examples/queries/prepared-statements/",permalink:"/node-mysql2/docs/examples/queries/prepared-statements/",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/queries/prepared-statements/index.mdx",tags:[],version:"current",frontMatter:{},sidebar:"examples",previous:{title:"DELETE",permalink:"/node-mysql2/docs/examples/queries/simple-queries/delete"},next:{title:"INSERT",permalink:"/node-mysql2/docs/examples/queries/prepared-statements/insert"}},c={},l=[];function p(e){const s={a:"a",admonition:"admonition",code:"code",h1:"h1",hr:"hr",input:"input",li:"li",p:"p",strong:"strong",ul:"ul",...(0,r.a)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.h1,{id:"prepared-statements",children:"Prepared Statements"}),"\n",(0,n.jsxs)(s.p,{children:["MySQL2 provides ",(0,n.jsx)(s.code,{children:"execute"})," helper which will prepare and query the statement.\nYou can also manually prepare / unprepare statement with ",(0,n.jsx)(s.code,{children:"prepare"})," / ",(0,n.jsx)(s.code,{children:"unprepare"})," methods."]}),"\n",(0,n.jsxs)(s.p,{children:["See detailed documentaion in ",(0,n.jsx)(s.a,{href:"/docs/documentation/prepared-statements",children:"Prepared Statements"}),"."]}),"\n",(0,n.jsx)(s.admonition,{type:"tip",children:(0,n.jsxs)(s.p,{children:["If you execute same statement again, it will be picked form a ",(0,n.jsx)(s.strong,{children:"LRU cache"})," which will save query preparation time and give better performance."]})}),"\n",(0,n.jsx)(s.hr,{}),"\n",(0,n.jsx)(s.p,{children:"Usage examples:"}),"\n",(0,n.jsxs)(s.ul,{className:"contains-task-list",children:["\n",(0,n.jsxs)(s.li,{className:"task-list-item",children:[(0,n.jsx)(s.input,{type:"checkbox",checked:!0,disabled:!0})," ",(0,n.jsx)(s.a,{href:"/docs/examples/queries/prepared-statements/insert",children:(0,n.jsx)(s.strong,{children:"INSERT"})})]}),"\n",(0,n.jsxs)(s.li,{className:"task-list-item",children:[(0,n.jsx)(s.input,{type:"checkbox",checked:!0,disabled:!0})," ",(0,n.jsx)(s.a,{href:"/docs/examples/queries/prepared-statements/select",children:(0,n.jsx)(s.strong,{children:"SELECT"})})]}),"\n",(0,n.jsxs)(s.li,{className:"task-list-item",children:[(0,n.jsx)(s.input,{type:"checkbox",checked:!0,disabled:!0})," ",(0,n.jsx)(s.a,{href:"/docs/examples/queries/prepared-statements/update",children:(0,n.jsx)(s.strong,{children:"UPDATE"})})]}),"\n",(0,n.jsxs)(s.li,{className:"task-list-item",children:[(0,n.jsx)(s.input,{type:"checkbox",checked:!0,disabled:!0})," ",(0,n.jsx)(s.a,{href:"/docs/examples/queries/prepared-statements/delete",children:(0,n.jsx)(s.strong,{children:"DELETE"})})]}),"\n"]})]})}function o(e={}){const{wrapper:s}={...(0,r.a)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.jsx)(p,{...e})}):p(e)}},1151:(e,s,t)=>{t.d(s,{Z:()=>d,a:()=>i});var n=t(7294);const r={},a=n.createContext(r);function i(e){const s=n.useContext(a);return n.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function d(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),n.createElement(a.Provider,{value:s},e.children)}}}]); \ No newline at end of file diff --git a/assets/js/7fbd6b3a.b2a4ea36.js b/assets/js/7fbd6b3a.b2a4ea36.js new file mode 100644 index 0000000000..964d33c3b0 --- /dev/null +++ b/assets/js/7fbd6b3a.b2a4ea36.js @@ -0,0 +1 @@ +"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[9964],{8937:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>h,contentTitle:()=>u,default:()=>m,frontMatter:()=>i,metadata:()=>d,toc:()=>p});var r=s(5893),t=s(1151),l=s(4866),a=s(5162),o=s(6393),c=s(4379);const i={sidebar_position:1,tags:["Prepared Statements","Placeholders","Parameters","execute"]},u="SELECT",d={id:"examples/queries/prepared-statements/select",title:"SELECT",description:"execute(sql, values)",source:"@site/docs/examples/queries/prepared-statements/select.mdx",sourceDirName:"examples/queries/prepared-statements",slug:"/examples/queries/prepared-statements/select",permalink:"/node-mysql2/docs/examples/queries/prepared-statements/select",draft:!1,unlisted:!1,editUrl:"https://github.com/sidorares/node-mysql2/tree/master/website/docs/examples/queries/prepared-statements/select.mdx",tags:[{label:"Prepared Statements",permalink:"/node-mysql2/docs/tags/prepared-statements"},{label:"Placeholders",permalink:"/node-mysql2/docs/tags/placeholders"},{label:"Parameters",permalink:"/node-mysql2/docs/tags/parameters"},{label:"execute",permalink:"/node-mysql2/docs/tags/execute"}],version:"current",sidebarPosition:1,frontMatter:{sidebar_position:1,tags:["Prepared Statements","Placeholders","Parameters","execute"]},sidebar:"examples",previous:{title:"INSERT",permalink:"/node-mysql2/docs/examples/queries/prepared-statements/insert"},next:{title:"UPDATE",permalink:"/node-mysql2/docs/examples/queries/prepared-statements/update"}},h={},p=[{value:"execute(sql, values)",id:"executesql-values",level:2},{value:"execute(options)",id:"executeoptions",level:2},{value:"execute(options, values)",id:"executeoptions-values",level:2},{value:"Glossary",id:"glossary",level:2},{value:"QueryOptions",id:"queryoptions",level:3}];function x(e){const n={a:"a",admonition:"admonition",blockquote:"blockquote",code:"code",h1:"h1",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,t.a)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.h1,{id:"select",children:"SELECT"}),"\n",(0,r.jsx)(n.h2,{id:"executesql-values",children:"execute(sql, values)"}),"\n",(0,r.jsxs)(n.blockquote,{children:["\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.strong,{children:"execute(sql: string, values: any[])"})}),"\n"]}),"\n",(0,r.jsxs)(l.Z,{children:[(0,r.jsx)(a.Z,{value:"promise.js",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"try {\n const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';\n const values = ['Page', 45];\n\n // highlight-next-line\n const [rows, fields] = await connection.execute(sql, values);\n\n console.log(rows);\n console.log(fields);\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,r.jsx)(a.Z,{value:"callback.js",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';\nconst values = ['Page', 45];\n\nconnection.execute(sql, values, (err, rows, fields) => {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n console.log(rows);\n console.log(fields);\n});\n"})})})]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"rows"})," contains rows returned by server"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"fields"})," contains extra meta data about rows, if available"]}),"\n"]}),"\n",(0,r.jsx)(n.admonition,{type:"info",children:(0,r.jsxs)(n.p,{children:["The connection used for the query (",(0,r.jsx)(n.code,{children:"execute"}),") can be obtained through the ",(0,r.jsx)(n.code,{children:"createConnection"}),", ",(0,r.jsx)(n.code,{children:"createPool"})," or ",(0,r.jsx)(n.code,{children:"createPoolCluster"})," methods."]})}),"\n",(0,r.jsx)(n.hr,{}),"\n",(0,r.jsx)(n.h2,{id:"executeoptions",children:"execute(options)"}),"\n",(0,r.jsxs)(n.blockquote,{children:["\n",(0,r.jsx)(n.p,{children:(0,r.jsxs)(n.strong,{children:["execute(options: ",(0,r.jsx)(n.a,{href:"#queryoptions",children:"QueryOptions"}),")"]})}),"\n"]}),"\n",(0,r.jsxs)(l.Z,{children:[(0,r.jsx)(a.Z,{value:"promise.js",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"try {\n const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';\n const values = ['Page', 45];\n\n // highlight-start\n const [rows, fields] = await connection.execute({\n sql,\n values,\n // ... other options\n });\n // highlight-end\n\n console.log(rows);\n console.log(fields);\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,r.jsx)(a.Z,{value:"callback.js",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';\nconst values = ['Page', 45];\n\nconnection.execute(\n {\n sql,\n values,\n // ... other options\n },\n (err, rows, fields) => {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n console.log(rows);\n console.log(fields);\n }\n);\n"})})})]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"rows"})," contains rows returned by server"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"fields"})," contains extra meta data about rows, if available"]}),"\n"]}),"\n",(0,r.jsx)(n.admonition,{type:"info",children:(0,r.jsxs)(n.p,{children:["The connection used for the query (",(0,r.jsx)(n.code,{children:"execute"}),") can be obtained through the ",(0,r.jsx)(n.code,{children:"createConnection"}),", ",(0,r.jsx)(n.code,{children:"createPool"})," or ",(0,r.jsx)(n.code,{children:"createPoolCluster"})," methods."]})}),"\n",(0,r.jsx)(n.hr,{}),"\n",(0,r.jsx)(n.h2,{id:"executeoptions-values",children:"execute(options, values)"}),"\n",(0,r.jsxs)(n.blockquote,{children:["\n",(0,r.jsx)(n.p,{children:(0,r.jsxs)(n.strong,{children:["execute(options: ",(0,r.jsx)(n.a,{href:"#queryoptions",children:"QueryOptions"}),", values: any[])"]})}),"\n"]}),"\n",(0,r.jsxs)(l.Z,{children:[(0,r.jsx)(a.Z,{value:"promise.js",default:!0,children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"try {\n const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';\n const values = ['Page', 45];\n\n // highlight-start\n const [rows, fields] = await connection.execute(\n {\n sql,\n // ... other options\n },\n values\n );\n // highlight-end\n\n console.log(rows);\n console.log(fields);\n} catch (err) {\n console.log(err);\n}\n"})})}),(0,r.jsx)(a.Z,{value:"callback.js",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:"const sql = 'SELECT * FROM `users` WHERE `name` = ? AND `age` > ?';\nconst values = ['Page', 45];\n\nconnection.execute(\n {\n sql,\n // ... other options\n },\n values,\n (err, rows, fields) => {\n if (err instanceof Error) {\n console.log(err);\n return;\n }\n\n console.log(rows);\n console.log(fields);\n }\n);\n"})})})]}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"rows"})," contains rows returned by server"]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.strong,{children:"fields"})," contains extra meta data about rows, if available"]}),"\n"]}),"\n",(0,r.jsx)(n.admonition,{type:"info",children:(0,r.jsxs)(n.p,{children:["The connection used for the query (",(0,r.jsx)(n.code,{children:"execute"}),") can be obtained through the ",(0,r.jsx)(n.code,{children:"createConnection"}),", ",(0,r.jsx)(n.code,{children:"createPool"})," or ",(0,r.jsx)(n.code,{children:"createPoolCluster"})," methods."]})}),"\n",(0,r.jsx)(n.hr,{}),"\n",(0,r.jsx)(n.h2,{id:"glossary",children:"Glossary"}),"\n",(0,r.jsx)(n.h3,{id:"queryoptions",children:"QueryOptions"}),"\n",(0,r.jsx)(o.Z,{title:"QueryOptions Specification",children:(0,r.jsx)(c.I,{language:"ts",url:"https://raw.githubusercontent.com/sidorares/node-mysql2/master/typings/mysql/lib/protocol/sequences/Query.d.ts",extractMethod:"QueryOptions",methodType:"interface"})})]})}function m(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(x,{...e})}):x(e)}},5162:(e,n,s)=>{s.d(n,{Z:()=>a});s(7294);var r=s(512);const t={tabItem:"tabItem_Ymn6"};var l=s(5893);function a(e){let{children:n,hidden:s,className:a}=e;return(0,l.jsx)("div",{role:"tabpanel",className:(0,r.Z)(t.tabItem,a),hidden:s,children:n})}},4866:(e,n,s)=>{s.d(n,{Z:()=>q});var r=s(7294),t=s(512),l=s(2466),a=s(6550),o=s(469),c=s(1980),i=s(7392),u=s(12);function d(e){return r.Children.toArray(e).filter((e=>"\n"!==e)).map((e=>{if(!e||(0,r.isValidElement)(e)&&function(e){const{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw new Error(`Docusaurus error: Bad child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the component should be , and every should have a unique "value" prop.`)}))?.filter(Boolean)??[]}function h(e){const{values:n,children:s}=e;return(0,r.useMemo)((()=>{const e=n??function(e){return d(e).map((e=>{let{props:{value:n,label:s,attributes:r,default:t}}=e;return{value:n,label:s,attributes:r,default:t}}))}(s);return function(e){const n=(0,i.l)(e,((e,n)=>e.value===n.value));if(n.length>0)throw new Error(`Docusaurus error: Duplicate values "${n.map((e=>e.value)).join(", ")}" found in . Every value needs to be unique.`)}(e),e}),[n,s])}function p(e){let{value:n,tabValues:s}=e;return s.some((e=>e.value===n))}function x(e){let{queryString:n=!1,groupId:s}=e;const t=(0,a.k6)(),l=function(e){let{queryString:n=!1,groupId:s}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!s)throw new Error('Docusaurus error: The