awSQL/docs/docusaurus/build/assets/js/2ab12074.76390b1f.js
2025-04-13 14:28:04 +02:00

1 line
7.3 KiB
JavaScript

"use strict";(self.webpackChunkdocusaurus=self.webpackChunkdocusaurus||[]).push([[344],{5015:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>l,contentTitle:()=>i,default:()=>o,frontMatter:()=>c,metadata:()=>r,toc:()=>h});const r=JSON.parse('{"id":"classes/update","title":"Update","description":"Executes a query to update data in a table.","source":"@site/docs/classes/update.md","sourceDirName":"classes","slug":"/classes/update","permalink":"/awSQL/classes/update","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":6,"frontMatter":{"sidebar_position":6},"sidebar":"defaultSidebar","previous":{"title":"Delete","permalink":"/awSQL/classes/delete"},"next":{"title":"Structure","permalink":"/awSQL/classes/structure"}}');var t=n(4848),d=n(8453);const c={sidebar_position:6},i="Update",l={},h=[{value:"Methods",id:"methods",level:2},{value:"data()",id:"data",level:3},{value:"selectDatabase()",id:"selectdatabase",level:3},{value:"force()",id:"force",level:3},{value:"where()",id:"where",level:3},{value:"execute()",id:"execute",level:3}];function a(e){const s={a:"a",admonition:"admonition",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",header:"header",hr:"hr",li:"li",p:"p",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,d.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.header,{children:(0,t.jsx)(s.h1,{id:"update",children:"Update"})}),"\n",(0,t.jsx)(s.p,{children:"Executes a query to update data in a table."}),"\n",(0,t.jsxs)(s.admonition,{title:"Possible Crash",type:"warning",children:[(0,t.jsxs)(s.p,{children:["To prevent accidental updates on all rows, this operation will ",(0,t.jsx)(s.strong,{children:"throw an error"})," when calling ",(0,t.jsx)(s.a,{href:"#execute",children:"execute()"})," if no ",(0,t.jsx)(s.a,{href:"#where",children:"where()"})," clause is defined."]}),(0,t.jsxs)(s.p,{children:["To explicitly allow updates on all rows, use ",(0,t.jsx)(s.a,{href:"#force",children:"force()"}),"."]})]}),"\n",(0,t.jsx)(s.hr,{}),"\n",(0,t.jsx)(s.h2,{id:"methods",children:"Methods"}),"\n",(0,t.jsx)(s.hr,{}),"\n",(0,t.jsx)(s.h3,{id:"data",children:"data()"}),"\n",(0,t.jsxs)(s.p,{children:["\u2192 (",(0,t.jsx)(s.code,{children:"object"})," = ",(0,t.jsx)(s.strong,{children:"Object"}),") \u2192 ",(0,t.jsx)(s.code,{children:"this"})]}),"\n",(0,t.jsx)(s.p,{children:"Updates all matching rows with the provided data."}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Parameters"})}),"\n",(0,t.jsxs)(s.table,{children:[(0,t.jsx)(s.thead,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.th,{children:"Parameter"}),(0,t.jsx)(s.th,{children:"Type"}),(0,t.jsx)(s.th,{children:"Description"})]})}),(0,t.jsx)(s.tbody,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"object"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.strong,{children:"Object"})}),(0,t.jsx)(s.td,{children:"An object where keys represent column names and values represent the new data."})]})})]}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Returns"})}),"\n",(0,t.jsxs)(s.p,{children:["\u2192 ",(0,t.jsx)(s.code,{children:"this"})]}),"\n",(0,t.jsx)(s.hr,{}),"\n",(0,t.jsx)(s.h3,{id:"selectdatabase",children:"selectDatabase()"}),"\n",(0,t.jsxs)(s.p,{children:["\u2192 (",(0,t.jsx)(s.code,{children:"database"})," = ",(0,t.jsx)(s.strong,{children:"String"}),") \u2192 ",(0,t.jsx)(s.code,{children:"this"})]}),"\n",(0,t.jsx)(s.p,{children:"Selects a different database for the query."}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Parameters"})}),"\n",(0,t.jsxs)(s.table,{children:[(0,t.jsx)(s.thead,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.th,{children:"Parameter"}),(0,t.jsx)(s.th,{children:"Type"}),(0,t.jsx)(s.th,{children:"Description"})]})}),(0,t.jsx)(s.tbody,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"database"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.strong,{children:"String"})}),(0,t.jsx)(s.td,{children:"The name of the database to use for the update."})]})})]}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Returns"})}),"\n",(0,t.jsxs)(s.p,{children:["\u2192 ",(0,t.jsx)(s.code,{children:"this"})]}),"\n",(0,t.jsx)(s.hr,{}),"\n",(0,t.jsx)(s.h3,{id:"force",children:"force()"}),"\n",(0,t.jsxs)(s.p,{children:["\u2192 () \u2192 ",(0,t.jsx)(s.code,{children:"this"})]}),"\n",(0,t.jsxs)(s.p,{children:["Allows updates on ",(0,t.jsx)(s.strong,{children:"all rows"})," in the table."]}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Returns"})}),"\n",(0,t.jsxs)(s.p,{children:["\u2192 ",(0,t.jsx)(s.code,{children:"this"})]}),"\n",(0,t.jsx)(s.hr,{}),"\n",(0,t.jsx)(s.h3,{id:"where",children:"where()"}),"\n",(0,t.jsxs)(s.p,{children:["\u2192 (",(0,t.jsx)(s.code,{children:"string"})," = ",(0,t.jsx)(s.strong,{children:"String"}),", ",(0,t.jsx)(s.code,{children:"values"})," = ",(0,t.jsx)(s.strong,{children:"Array"}),"<",(0,t.jsx)(s.strong,{children:"any"}),">) \u2192 ",(0,t.jsx)(s.code,{children:"this"})]}),"\n",(0,t.jsxs)(s.p,{children:["Adds a ",(0,t.jsx)(s.code,{children:"WHERE"})," clause to filter the update query."]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:["Use ",(0,t.jsx)(s.code,{children:"?"})," as placeholders in the condition string to prevent SQL injection."]}),"\n"]}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Parameters"})}),"\n",(0,t.jsxs)(s.table,{children:[(0,t.jsx)(s.thead,{children:(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.th,{children:"Parameter"}),(0,t.jsx)(s.th,{children:"Type"}),(0,t.jsx)(s.th,{children:"Description"})]})}),(0,t.jsxs)(s.tbody,{children:[(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"string"})}),(0,t.jsx)(s.td,{children:(0,t.jsx)(s.strong,{children:"String"})}),(0,t.jsxs)(s.td,{children:["The ",(0,t.jsx)(s.code,{children:"WHERE"})," clause with ",(0,t.jsx)(s.code,{children:"?"})," placeholders."]})]}),(0,t.jsxs)(s.tr,{children:[(0,t.jsx)(s.td,{children:(0,t.jsx)(s.code,{children:"values"})}),(0,t.jsxs)(s.td,{children:[(0,t.jsx)(s.strong,{children:"Array"}),"<",(0,t.jsx)(s.strong,{children:"any"}),">"]}),(0,t.jsxs)(s.td,{children:["An arrray of values replacing the placeholders in ",(0,t.jsx)(s.em,{children:"left-to-right"})," order."]})]})]})]}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Returns"})}),"\n",(0,t.jsxs)(s.p,{children:["\u2192 ",(0,t.jsx)(s.code,{children:"this"})]}),"\n",(0,t.jsx)(s.hr,{}),"\n",(0,t.jsx)(s.h3,{id:"execute",children:"execute()"}),"\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"async"})," \u2192 () \u2192 ",(0,t.jsx)(s.a,{href:"../typedefs/okpacket",children:"OkPacket"})]}),"\n",(0,t.jsx)(s.p,{children:"Executes the prepared update query."}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Returns"})}),"\n",(0,t.jsxs)(s.p,{children:["\u2192 ",(0,t.jsx)(s.a,{href:"../typedefs/okpacket",children:"OkPacket"})]}),"\n",(0,t.jsx)(s.hr,{})]})}function o(e={}){const{wrapper:s}={...(0,d.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(a,{...e})}):a(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>c,x:()=>i});var r=n(6540);const t={},d=r.createContext(t);function c(e){const s=r.useContext(d);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function i(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:c(e.components),r.createElement(d.Provider,{value:s},e.children)}}}]);