1"use strict";(globalThis.webpackChunkkysely_site=globalThis.webpackChunkkysely_site||[]).push([[3511],{1509(e,s,t){t.r(s),t.d(s,{assets:()=>d,contentTitle:()=>i,default:()=>p,frontMatter:()=>o,metadata:()=>r,toc:()=>c});const r=JSON.parse('{"id":"examples/select/nested-array","title":"Nested array","description":"While kysely is not an ORM and it doesn\'t have the concept of relations, we do provide","source":"@site/docs/examples/select/0110-nested-array.mdx","sourceDirName":"examples/select","slug":"/examples/select/nested-array","permalink":"/docs/examples/select/nested-array","draft":false,"unlisted":false,"editUrl":"https://github.com/kysely-org/kysely/tree/master/site/docs/examples/select/0110-nested-array.mdx","tags":[],"version":"current","sidebarPosition":110,"frontMatter":{"title":"Nested array"},"sidebar":"tutorialSidebar","previous":{"title":"All columns of a table","permalink":"/docs/examples/select/all-columns-of-a-table"},"next":{"title":"Nested object","permalink":"/docs/examples/select/nested-object"}}');var n=t(1058),a=t(4801),l=t(2360);const o={title:"Nested array"},i="Nested array",d={},c=[];function h(e){const s={a:"a",admonition:"admonition",code:"code",h1:"h1",header:"header",li:"li",p:"p",ul:"ul",...(0,a.R)(),...e.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(s.header,{children:(0,n.jsx)(s.h1,{id:"nested-array",children:"Nested array"})}),"\n",(0,n.jsxs)(s.p,{children:["While kysely is not an ORM and it doesn't have the concept of relations, we do provide\nhelpers for fetching nested objects and arrays in a single query. In this example we\nuse the ",(0,n.jsx)(s.code,{children:"jsonArrayFrom"})," helper to fetch person's pets along with the person's id."]}),"\n",(0,n.jsxs)(s.p,{children:["Please keep in mind that the helpers under the ",(0,n.jsx)(s.code,{children:"kysely/helpers"})," folder, including\n",(0,n.jsx)(s.code,{children:"jsonArrayFrom"}),", are not guaranteed to work with third party dialects. In order for\nthem to work, the dialect must automatically parse the ",(0,n.jsx)(s.code,{children:"json"})," data type into\nJavaScript JSON values like objects and arrays. Some dialects might simply return\nthe data as a JSON string. In these cases you can use the built in ",(0,n.jsx)(s.code,{children:"ParseJSONResultsPlugin"}),"\nto parse the results."]}),"\n","\n","\n",(0,n.jsx)("div",{style:{marginBottom:"1em"},children:(0,n.jsx)(l.Q,{code:"import { jsonArrayFrom } from 'kysely/helpers/postgres'\n\nconst result = await db\n .selectFrom('person')\n .select((eb) => [\n 'id',\n jsonArrayFrom(\n eb.selectFrom('pet')\n .select(['pet.id as pet_id', 'pet.name'])\n .whereRef('pet.owner_id', '=', 'person.id')\n .orderBy('pet.name')\n ).as('pets')\n ])\n .execute()"})}),"\n",(0,n.jsxs)(s.admonition,{title:"More examples",type:"info",children:[(0,n.jsxs)(s.p,{children:["The API documentation is packed with examples. The API docs are hosted ",(0,n.jsx)(s.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)(s.p,{children:"For example, check out these sections:"}),(0,n.jsxs)(s.ul,{children:["\n",(0,n.jsx)(s.li,{children:(0,n.jsx)(s.a,{href:"https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#select",children:"select method"})}),"\n",(0,n.jsx)(s.li,{children:(0,n.jsx)(s.a,{href:"https://kysely-org.github.io/kysely-apidoc/interfaces/SelectQueryBuilder.html#selectAll",children:"selectAll method"})}),"\n",(0,n.jsx)(s.li,{children:(0,n.jsx)(s.a,{href:"https://kysely-org.github.io/kysely-apidoc/classes/Kysely.html#selectFrom",children:"selectFrom method"})}),"\n"]})]})]})}function p(e={}){const{wrapper:s}={...(0,a.R)(),...e.components};return s?(0,n.jsx)(s,{...e,children:(0,n.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.