"use strict";(self.webpackChunkdocusaurus=self.webpackChunkdocusaurus||[]).push([[53],{2761:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>c,contentTitle:()=>l,default:()=>a,frontMatter:()=>i,metadata:()=>r,toc:()=>h});const r=JSON.parse('{"id":"classes/delete","title":"Delete","description":"Performs a query to delete rows from a table.","source":"@site/docs/classes/delete.md","sourceDirName":"classes","slug":"/classes/delete","permalink":"/awSQL/classes/delete","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":5,"frontMatter":{"sidebar_position":5},"sidebar":"defaultSidebar","previous":{"title":"Insert","permalink":"/awSQL/classes/insert"},"next":{"title":"Update","permalink":"/awSQL/classes/update"}}');var t=n(4848),d=n(8453);const i={sidebar_position:5},l="Delete",c={},h=[{value:"Methods",id:"methods",level:2},{value:"selectDatabase()",id:"selectdatabase",level:3},{value:"where()",id:"where",level:3},{value:"force()",id:"force",level:3},{value:"execute()",id:"execute",level:3}];function o(e){const s={a:"a",admonition:"admonition",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",hr:"hr",li:"li",p:"p",pre:"pre",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:"delete",children:"Delete"})}),"\n",(0,t.jsx)(s.p,{children:"Performs a query to delete rows from a table."}),"\n",(0,t.jsxs)(s.admonition,{title:"Possible crash",type:"warning",children:[(0,t.jsxs)(s.p,{children:["To ",(0,t.jsx)(s.strong,{children:"prevent accidental deletion of all rows"}),", an error will be thrown on ",(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 ",(0,t.jsx)(s.strong,{children:"explicitly allow deletion of 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:"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:"Sets the database for this 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 database name to select."})]})})]}),"\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:["Addsa ",(0,t.jsx)(s.code,{children:"WHERE"})," clause to the delete query."]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsxs)(s.strong,{children:["Use placeholders (",(0,t.jsx)(s.code,{children:"?"}),")"]})," in the condition string and provide values in the ",(0,t.jsx)(s.code,{children:"values"})," array ",(0,t.jsx)(s.strong,{children:"to prevent SQL injection"}),"."]}),"\n",(0,t.jsxs)(s.li,{children:["If using ",(0,t.jsx)(s.strong,{children:"joins"}),", specify the table and column together: ",(0,t.jsx)(s.code,{children:'"table.column"'}),"."]}),"\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:["SQL ",(0,t.jsx)(s.code,{children:"WHERE"})," condition 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:["Values replacing ",(0,t.jsx)(s.code,{children:"?"}),", in left-to-right order."]})]})]})]}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Example Usage"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",metastring:"showLineNumbers",children:'.delete().where("id = ?", [5])\n'})}),"\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:[(0,t.jsx)(s.strong,{children:"Enables deletion of all rows"}),", overriding the safeguard in ",(0,t.jsx)(s.a,{href:"#execute",children:"execute()"}),"."]}),"\n",(0,t.jsx)(s.admonition,{title:"Use with Caution",type:"danger",children:(0,t.jsxs)(s.p,{children:["Calling ",(0,t.jsx)(s.a,{href:"#execute",children:"execute()"})," after ",(0,t.jsx)(s.a,{href:"#force",children:"force()"})," will delete ",(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:"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.jsxs)(s.p,{children:["Executes the prepared ",(0,t.jsx)(s.code,{children:"DELETE"})," 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 a(e={}){const{wrapper:s}={...(0,d.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(o,{...e})}):o(e)}},8453:(e,s,n)=>{n.d(s,{R:()=>i,x:()=>l});var r=n(6540);const t={},d=r.createContext(t);function i(e){const s=r.useContext(d);return r.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:i(e.components),r.createElement(d.Provider,{value:s},e.children)}}}]);