1"use strict";(globalThis.webpackChunkkysely_site=globalThis.webpackChunkkysely_site||[]).push([[9064],{7816(e,t,s){s.r(t),s.d(t,{assets:()=>l,contentTitle:()=>h,default:()=>u,frontMatter:()=>a,metadata:()=>r,toc:()=>c});const r=JSON.parse('{"id":"examples/merge/source-row-existence","title":"Source row existence","description":"Update a target column based on the existence of a source row:","source":"@site/docs/examples/merge/0010-source-row-existence.mdx","sourceDirName":"examples/merge","slug":"/examples/merge/source-row-existence","permalink":"/docs/examples/merge/source-row-existence","draft":false,"unlisted":false,"editUrl":"https://github.com/kysely-org/kysely/tree/master/site/docs/examples/merge/0010-source-row-existence.mdx","tags":[],"version":"current","sidebarPosition":10,"frontMatter":{"title":"Source row existence"},"sidebar":"tutorialSidebar","previous":{"title":"MERGE","permalink":"/docs/category/merge"},"next":{"title":"Temporary changes table","permalink":"/docs/examples/merge/temporary-changes-table"}}');var n=s(1058),o=s(4801),i=s(2360);const a={title:"Source row existence"},h="Source row existence",l={},c=[];function d(e){const t={a:"a",admonition:"admonition",h1:"h1",header:"header",li:"li",p:"p",ul:"ul",...(0,o.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.header,{children:(0,n.jsx)(t.h1,{id:"source-row-existence",children:"Source row existence"})}),"\n",(0,n.jsx)(t.p,{children:"Update a target column based on the existence of a source row:"}),"\n","\n","\n",(0,n.jsx)("div",{style:{marginBottom:"1em"},children:(0,n.jsx)(i.Q,{code:"const result = await db\n .mergeInto('person as target')\n .using('pet as source', 'source.owner_id', 'target.id')\n .whenMatchedAnd('target.has_pets', '!=', 'Y')\n .thenUpdateSet({ has_pets: 'Y' })\n .whenNotMatchedBySourceAnd('target.has_pets', '=', 'Y')\n .thenUpdateSet({ has_pets: 'N' })\n .executeTakeFirstOrThrow()\n\nconsole.log(result.numChangedRows)"})}),"\n",(0,n.jsxs)(t.admonition,{title:"More examples",type:"info",children:[(0,n.jsxs)(t.p,{children:["The API documentation is packed with examples. The API docs are hosted ",(0,n.jsx)(t.a,{href:"https://kysely-org.github.io/kysely-apidoc/",children:"here"}),",\nbut you can access the same documentation by hovering over functions/methods/classes in your IDE. The examples are always\njust one hover away!"]}),(0,n.jsx)(t.p,{children:"For example, check out these sections:"}),(0,n.jsxs)(t.ul,{children:["\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/Kysely.html#mergeInto",children:"mergeInto method"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/MergeQueryBuilder.html#using",children:"using method"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/WheneableMergeQueryBuilder.html#whenMatched",children:"whenMatched method"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/MatchedThenableMergeQueryBuilder.html#thenUpdateSet",children:"thenUpdateSet method"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/MatchedThenableMergeQueryBuilder.html#thenDelete",children:"thenDelete method"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/MatchedThenableMergeQueryBuilder.html#thenDoNothing",children:"thenDoNothing method"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/WheneableMergeQueryBuilder.html#whenNotMatched",children:"whenNotMatched method"})}),"\n",(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/NotMatchedThenableMergeQueryBuilder.html#thenInsertValues",children:"thenInsertValues method"})}),"\n"]})]})]})}function u(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,n.jsx)(t,{...e,children:(0,n.jsx)(d,{...e})}):d(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.