PageSourceSearch

https://kysely.dev/assets/js/eeb514fc.039882f6.js

js kysely.dev collected 2026-10-02 02:57:33 UTC 3,356 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkkysely_site=globalThis.webpackChunkkysely_site||[]).push([[2444],{2741(e,n,t){t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>c,default:()=>p,frontMatter:()=>o,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"examples/transactions/simple-transaction","title":"Simple transaction","description":"This example inserts two rows in a transaction. If an exception is thrown inside","source":"@site/docs/examples/transactions/0010-simple-transaction.mdx","sourceDirName":"examples/transactions","slug":"/examples/transactions/simple-transaction","permalink":"/docs/examples/transactions/simple-transaction","draft":false,"unlisted":false,"editUrl":"https://github.com/kysely-org/kysely/tree/master/site/docs/examples/transactions/0010-simple-transaction.mdx","tags":[],"version":"current","sidebarPosition":10,"frontMatter":{"title":"Simple transaction"},"sidebar":"tutorialSidebar","previous":{"title":"Transactions","permalink":"/docs/category/transactions"},"next":{"title":"Controlled transaction","permalink":"/docs/examples/transactions/controlled-transaction"}}');var i=t(1058),a=t(4801),r=t(2360);const o={title:"Simple transaction"},c="Simple transaction",l={},d=[];function h(e){const n={a:"a",admonition:"admonition",code:"code",h1:"h1",header:"header",li:"li",ol:"ol",p:"p",ul:"ul",...(0,a.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(n.header,{children:(0,i.jsx)(n.h1,{id:"simple-transaction",children:"Simple transaction"})}),"\n",(0,i.jsxs)(n.p,{children:["This example inserts two rows in a transaction. If an exception is thrown inside\nthe callback passed to the ",(0,i.jsx)(n.code,{children:"execute"})," method,"]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsx)(n.li,{children:"the exception is caught,"}),"\n",(0,i.jsx)(n.li,{children:"the transaction is rolled back, and"}),"\n",(0,i.jsx)(n.li,{children:"the exception is thrown again.\nOtherwise the transaction is committed."}),"\n"]}),"\n","\n","\n",(0,i.jsx)("div",{style:{marginBottom:"1em"},children:(0,i.jsx)(r.Q,{code:"const catto = await db.transaction().execute(async (trx) => {\n  const jennifer = await trx.insertInto('person')\n    .values({\n      first_name: 'Jennifer',\n      last_name: 'Aniston',\n      age: 40,\n    })\n    .returning('id')\n    .executeTakeFirstOrThrow()\n\n  return await trx.insertInto('pet')\n    .values({\n      owner_id: jennifer.id,\n      name: 'Catto',\n      species: 'cat',\n      is_favorite: false,\n    })\n    .returningAll()\n    .executeTakeFirst()\n})"})}),"\n",(0,i.jsxs)(n.admonition,{title:"More examples",type:"info",children:[(0,i.jsxs)(n.p,{children:["The API documentation is packed with examples. The API docs are hosted ",(0,i.jsx)(n.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,i.jsx)(n.p,{children:"For example, check out these sections:"}),(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsx)(n.li,{children:(0,i.jsx)(n.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/Kysely.html#transaction",children:"transaction method"})}),"\n"]})]})]})}function p(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(h,{...e})}):h(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.