PageSourceSearch

https://spacetimedb.com/docs/assets/js/a4c0f82f.24e4a28e.js

js spacetimedb.com collected 2026-09-25 14:15:30 UTC 143,989 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[955],{43244:(s,l,e)=>{e.d(l,{A:()=>o});e(7378);var n=e(23372);const c={tabItem:"tabItem_w6aI"};var r=e(86106);function o({children:s,hidden:l,className:e}){return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(c.tabItem,e),hidden:l,children:s})}},51471:(s,l,e)=>{e.d(l,{A:()=>g});var n=e(7378),c=e(23372),r=e(23418),o=e(46585),a=e(30505),i=e(99202),F=e(81922),t=e(46923),d=e(73126);function h(s){return n.Children.toArray(s).filter(s=>"\n"!==s).map(s=>{if(!s||(0,n.isValidElement)(s)&&function(s){const{props:l}=s;return!!l&&"object"==typeof l&&"value"in l}(s))return s;throw new Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof s.type?s.type:s.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)})?.filter(Boolean)??[]}function x(s){const{values:l,children:e}=s;return(0,n.useMemo)(()=>{const s=l??function(s){return h(s).map(({props:{value:s,label:l,attributes:e,default:n}})=>({value:s,label:l,attributes:e,default:n}))}(e);return function(s){const l=(0,t.XI)(s,(s,l)=>s.value===l.value);if(l.length>0)throw new Error(`Docusaurus error: Duplicate values "${l.map(s=>s.value).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(s),s},[l,e])}function p({value:s,tabValues:l}){return l.some(l=>l.value===s)}function j({queryString:s=!1,groupId:l}){const e=(0,a.W6)(),c=function({queryString:s=!1,groupId:l}){if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!l)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return l??null}({queryString:s,groupId:l});return[(0,F.aZ)(c),(0,n.useCallback)(s=>{if(!c)return;const l=new URLSearchParams(e.location.search);l.set(c,s),e.replace({...e.location,search:l.toString()})},[c,e])]}function y(s){const{defaultValue:l,queryString:e=!1,groupId:c}=s,r=x(s),[o,a]=(0,n.useState)(()=>function({defaultValue:s,tabValues:l}){if(0===l.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(s){if(!p({value:s,tabValues:l}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${l.map(s=>s.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const e=l.find(s=>s.default)??l[0];if(!e)throw new Error("Unexpected error: 0 tabValues");return e.value}({defaultValue:l,tabValues:r})),[F,t]=j({queryString:e,groupId:c}),[h,y]=function({groupId:s}){const l=function(s){return s?`docusaurus.tab.${s}`:null}(s),[e,c]=(0,d.Dv)(l);return[e,(0,n.useCallback)(s=>{l&&c.set(s)},[l,c])]}({groupId:c}),u=(()=>{const s=F??h;return p({value:s,tabValues:r})?s:null})();(0,i.A)(()=>{u&&a(u)},[u]);return{selectedValue:o,selectValue:(0,n.useCallback)(s=>{if(!p({value:s,tabValues:r}))throw new Error(`Can't select invalid tab value=${s}`);a(s),t(s),y(s)},[t,y,r]),tabValues:r}}var u=e(52538);const m={tabList:"tabList_duiv",tabItem:"tabItem_a1H9"};var C=e(86106);function b({className:s,block:l,selectedValue:e,selectValue:n,tabValues:r}){const a=[],{blockElementScrollPositionUntilNextRender:i}=(0,o.a_)(),F=s=>{const l=s.currentTarget,c=a.indexOf(l),o=r[c].value;o!==e&&(i(l),n(o))},t=s=>{let l=null;switch(s.key){case"Enter":F(s);break;case"ArrowRight":{const e=a.indexOf(s.currentTarget)+1;l=a[e]??a[0];break}case"ArrowLeft":{const e=a.indexOf(s.currentTarget)-1;l=a[e]??a[a.length-1];break}}l?.focus()};return(0,C.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,c.A)("tabs",{"tabs--block":l},s),children:r.map(({value:s,label:l,attributes:n})=>(0,C.jsx)("li",{role:"tab",tabIndex:e===s?0:-1,"aria-selected":e===s,ref:s=>{a.push(s)},onKeyDown:t,onClick:F,...n,className:(0,c.A)("tabs__item",m.tabItem,n?.className,{"tabs__item--active":e===s}),children:l??s},s))})}function N({lazy:s,children:l,selectedValue:e}
1){const r=(Array.isArray(l)?l:[l]).filter(Boolean);if(s){const s=r.find(s=>s.props.value===e);return s?(0,n.cloneElement)(s,{className:(0,c.A)("margin-top--md",s.props.className)}):null}return(0,C.jsx)("div",{className:"margin-top--md",children:r.map((s,l)=>(0,n.cloneElement)(s,{key:l,hidden:s.props.value!==e}))})}function A(s){const l=y(s);return(0,C.jsxs)("div",{className:(0,c.A)(r.G.tabs.container,"tabs-container",m.tabList),children:[(0,C.jsx)(b,{...l,...s}),(0,C.jsx)(N,{...l,...s})]})}function g(s){const l=(0,u.A)();return(0,C.jsx)(A,{...s,children:h(s.children)},String(l))}},53502:(s,l,e)=>{e.r(l),e.d(l,{assets:()=>d,contentTitle:()=>t,default:()=>p,frontMatter:()=>F,metadata:()=>n,toc:()=>h});const n=JSON.parse('{"id":"core-concepts/functions/reducers/reducers","title":"Overview","description":"Reducers are functions that modify database state in response to client requests or system events. They are the only way to mutate tables in SpacetimeDB - all database changes must go through reducers.","source":"@site/docs/00200-core-concepts/00200-functions/00300-reducers/00300-reducers.md","sourceDirName":"00200-core-concepts/00200-functions/00300-reducers","slug":"/functions/reducers","permalink":"/docs/functions/reducers","draft":false,"unlisted":false,"editUrl":"https://github.com/clockworklabs/SpacetimeDB/edit/master/docs/docs/00200-core-concepts/00200-functions/00300-reducers/00300-reducers.md","tags":[],"version":"current","sidebarPosition":300,"frontMatter":{"title":"Overview","slug":"/functions/reducers"},"sidebar":"sidebar","previous":{"title":"Functions","permalink":"/docs/functions"},"next":{"title":"Reducer Context","permalink":"/docs/functions/reducers/reducer-context"}}');var c=e(86106),r=e(56225),o=e(51471),a=e(43244),i=e(67834);const F={title:"Overview",slug:"/functions/reducers"},t=void 0,d={},h=[{value:"Defining Reducers",id:"defining-reducers",level:2},{value:"Transactional Execution",id:"transactional-execution",level:2},{value:"Accessing Tables",id:"accessing-tables",level:2},{value:"Inserting Rows",id:"inserting-rows",level:3},{value:"Finding Rows by Unique Column",id:"finding-rows-by-unique-column",level:3},{value:"Filtering Rows by Indexed Column",id:"filtering-rows-by-indexed-column",level:3},{value:"Updating Rows",id:"updating-rows",level:3},{value:"Deleting Rows",id:"deleting-rows",level:3},{value:"Iterating All Rows",id:"iterating-all-rows",level:3},{value:"Counting Rows",id:"counting-rows",level:3},{value:"Reducer Isolation",id:"reducer-isolation",level:2},{value:"Scheduling Procedures",id:"scheduling-procedures",level:2},{value:"Next Steps",id:"next-steps",level:2}];function x(s){const l={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",li:"li",ol:"ol",p:"p",pre:"pre",span:"span",strong:"strong",ul:"ul",...(0,r.R)(),...s.components};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(l.p,{children:["Reducers are functions that modify database state in response to client requests or system events. They are the ",(0,c.jsx)(l.strong,{children:"only"})," way to mutate tables in SpacetimeDB - all database changes must go through reducers."]}),"\n",(0,c.jsx)(l.h2,{id:"defining-reducers",children:"Defining Reducers"}),"\n",(0,c.jsx)(l.p,{children:"Reducers are defined in your module code and automatically exposed as callable functions to connected clients."}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsxs)(a.A,{value:"typescript",label:"TypeScript",children:[(0,c.jsxs)(l.p,{children:["Use the ",(0,c.jsx)(l.code,{children:"spacetimedb.reducer"})," function:"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"import"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { schema, table, t } "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"from"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"spacetimedb/server"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  { name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" true"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"u64"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"primaryKey"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"autoInc"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"index"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"btree"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    email"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"unique"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" schema"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({ user });"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"export"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" default"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb;"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"export"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" create_user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"reducer"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({ name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(), email"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"() }, ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"name"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"email"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"  // Validate input"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"  if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"==="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" ''"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    throw"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6",fontWeight:"bold"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" Error"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Name cannot be empty"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  "})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"  // Modify tables"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  ctx.db.user."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"n"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:",  "}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// auto-increment will assign"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    name,"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    email"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})}),(0,c.jsxs)(l.p,{children:["The exported const name becomes the reducer name. Pass an argument type object followed by a handler function taking ",(0,c.jsx)(l.code,{children:"(ctx, args)"}),". For reducers with no arguments, pass only the handler function."]})]}),(0,c.jsxs)(a.A,{value:"csharp",label:"C#",children:[(0,c.jsxs)(l.p,{children:["Use the ",(0,c.jsx)(l.code,{children:"[SpacetimeDB.Reducer]"})," attribute on a static method:"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" class"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:" Module"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Reducer"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" void"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" CreateUser"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" name"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" email"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    {"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"        // Validate input"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"        if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"IsNullOrEmpty"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(name))"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"            throw"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" ArgumentException"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Name cannot be empty"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        "})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"        // Modify tables"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        ctx.Db.User."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" User"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"            Id "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:",  "}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// auto-increment will assign"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"            Name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" name,"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"            Email "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" email"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})}),(0,c.jsxs)(l.p,{children:["Reducers must be static methods with ",(0,c.jsx)(l.code,{children:"ReducerContext"})," as the first parameter. Additional parameters may be built-in SpacetimeDB types, primitive types, or custom types marked with ",(0,c.jsx)(l.code,{children:"[SpacetimeDB.Type]"}),". Reducers should return ",(0,c.jsx)(l.code,{children:"void"}),"."]})]}),(0,c.jsxs)(a.A,{value:"rust",label:"Rust",children:[(0,c.jsxs)(l.p,{children:["Use the ",(0,c.jsx)(l.code,{children:"#[spacetimedb::reducer]"})," macro on a function:"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"use"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{reducer, "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"};"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[reducer]"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"pub"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" create_user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", email"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"->"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Result"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"<(), "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"> {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"    // Validate input"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"is_empty"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"() {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"        return"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Err"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Name cannot be empty"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"());"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"    // Modify tables"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"User"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// auto-increment will assign"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        name,"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        email,"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    });"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"    Ok"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(())"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})}),(0,c.jsxs)(l.p,{children:["Reducers must take ",(0,c.jsx)(l.code,{children:"&ReducerContext"})," as their first parameter. Additional parameters must be serializable types. Reducers can return ",(0,c.jsx)(l.code,{children:"()"}),", ",(0,c.jsx)(l.code,{children:"Result<(), String>"}),", or ",(0,c.jsx)(l.code,{children:"Result<(), E>"})," where ",(0,c.jsx)(l.code,{children:"E: Display"}),"."]}),(0,c.jsxs)(l.admonition,{title:"Rust: Importing the Table Trait",type:"note",children:[(0,c.jsxs)(l.p,{children:["Table operations like ",(0,c.jsx)(l.code,{children:"insert"}),", ",(0,c.jsx)(l.code,{children:"try_insert"}),", ",(0,c.jsx)(l.code,{children:"iter"}),", and ",(0,c.jsx)(l.code,{children:"count"})," are provided by the ",(0,c.jsx)(l.code,{children:"Table"})," trait. You must import this trait for these methods to be available:"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsx)(l.code,{children:(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"use"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]})})})}),(0,c.jsxs)(l.p,{children:['If you see errors like "no method n
1amed ',(0,c.jsx)(l.code,{children:"try_insert"}),' found", add this import.']})]})]}),(0,c.jsxs)(a.A,{value:"cpp",label:"C++",children:[(0,c.jsx)(i._,{}),(0,c.jsxs)(l.p,{children:["Use the ",(0,c.jsx)(l.code,{children:"SPACETIMEDB_REDUCER"})," macro on a function:"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#include"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" <"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"spacetimedb.h"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:">"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" namespace"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" SpacetimeDB;"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"SPACETIMEDB_REDUCER"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(create_user, ReducerContext ctx, std"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"string name, std"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"string email) {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"    // Validate input"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (name."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"empty"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"        return"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" Err"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Name cannot be empty"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"    // Modify tables"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    User new_user{"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", name, email};"}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"  // 0 for id - auto-increment will assign"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ctx.db[user]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(new_user);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    return"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" Ok"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})}),(0,c.jsxs)(l.p,{children:["Reducers must take ",(0,c.jsx)(l.code,{children:"ReducerContext ctx"})," as their first parameter. Additional parameters can be any registered types. Reducers return ",(0,c.jsx)(l.code,{children:"ReducerResult"})," (which is ",(0,c.jsx)(l.code,{children:"Outcome<void>"}),"): use ",(0,c.jsx)(l.code,{children:"Ok()"})," on success or ",(0,c.jsx)(l.code,{children:"Err(message)"})," on error for convenience."]})]})]}),"\n",(0,c.jsx)(l.h2,{id:"transactional-execution",children:"Transactional Execution"}),"\n",(0,c.jsx)(l.p,{children:"Every reducer runs inside a database transaction. This provides important guarantees:"}),"\n",(0,c.jsxs)(l.ul,{children:["\n",(0,c.jsxs)(l.li,{children:[(0,c.jsx)(l.strong,{children:"Isolation"}),": Reducers don't see changes from other concurrent reducers"]}),"\n",(0,c.jsxs)(l.li,{children:[(0,c.jsx)(l.strong,{children:"Atomicity"}),": Either all changes succeed or all are rolled back"]}),"\n",(0,c.jsxs)(l.li,{children:[(0,c.jsx)(l.strong,{children:"Consistency"}),": Failed reducers leave the database unchanged"]}),"\n"]}),"\n",(0,c.jsx)(l.p,{children:"If a reducer throws an exception or returns an error, all of its changes are automatically rolled back."}),"\n",(0,c.jsx)(l.h2,{id:"accessing-tables",children:"Accessing Tables"}),"\n",(0,c.jsxs)(l.p,{children:["Reducers have full read-write access to all tables (both public and private) through the ",(0,c.jsx)(l.code,{children:"ReducerContext"}),". The examples below assume a ",(0,c.jsx)(l.code,{children:"user"})," table with ",(0,c.jsx)(l.code,{children:"id"})," (primary key), ",(0,c.jsx)(l.code,{children:"name"})," (indexed), and ",(0,c.jsx)(l.code,{children:"email"})," (unique) columns."]}),"\n",(0,c.jsx)(l.h3,{id:"inserting-rows",children:"Inserting Rows"}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsx)(a.A,{value:"typescript",label:"TypeScript",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx.db.user."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"n"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:",  "}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// auto-increment will assign"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Alice"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  email"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"[email protected]"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})})}),(0,c.jsx)(a.A,{value:"csharp",label:"C#",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx.Db.User."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" User"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    Id "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:",  "}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// auto-increment will assign"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    Name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Alice"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    Email "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"[email protected]"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})})}),(0,c.jsx)(a.A,{value:"rust",label:"Rust",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"User"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:",  "}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// auto-increment will assign"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:' "Alice"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    email"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:' "[email protected]"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})})}),(0,c.jsx)(a.A,{value:"cpp",label:"C++",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx.db[user]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(User{"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"    0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"  // auto-increment will assign"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'    "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Alice"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'    "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"[email protected]"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})})})]}),"\n",(0,c.jsx)(l.h3,{id:"finding-rows-by-unique-column",children:"Finding Rows by Unique Column"}),"\n",(0,c.jsxs)(l.p,{children:["Use ",(0,c.jsx)(l.code,{children:"find"})," on a unique or primary key column to retrieve a single row:"]}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsx)(a.A,{value:"typescript",label:"TypeScript",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.db.user.id."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (user) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`Found: "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"user.name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" byEmail "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.db.user.email."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"[email protected]"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]})]})})})}),(0,c.jsx)(a.A,{value:"csharp",label:"C#",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Db.User.Id."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"is"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" not"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" null"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Info"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Found: "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" byEmail "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Db.User.Email."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"[email protected]"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]})]})})})}),(0,c.jsx)(a.A,{value:"rust",label:"Rust",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"if"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Some"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(user) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"id"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    log"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"info!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Found: {}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"name);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" by_email "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"email"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"[email protected]"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]})]})})})}),(0,c.jsx)(a.A,{value:"cpp",label:"C++",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"auto"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.db[user_id]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"    LOG_INFO"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Found: "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" +"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"->"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"name);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"auto"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" by_email "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.db[user_email]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"[email protected]"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]})]})})})})]}),"\n",(0,c.jsx)(l.h3,{id:"filtering-rows-by-indexed-column",children:"Filtering Rows by Indexed Column"}),"\n",(0,c.jsxs)(l.p,{children:["Use ",(0,c.jsx)(l.code,{children:"filter"})," on an indexed column to retrieve multiple matching rows:"]}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsx)(a.A,{value:"typescript",label:"TypeScript",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"for"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"of"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.db.user.name."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"filter"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Alice"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`User "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"user.id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:": "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"user.email"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"csharp",label:"C#",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"foreach"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"in"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Db.User.Name."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Filter"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Alice"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"))"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Info"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"User "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:": "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Email"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"rust",label:"Rust",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"for"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"in"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"name"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"filter"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Alice"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    log"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"info!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"User {}: {}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"id, user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"email);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"cpp",label:"C++",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"for"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" auto&"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user : ctx.db[user_name]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"filter"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Alice"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"    LOG_INFO"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"User "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" +"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" std"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(user.id) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"+"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:": "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" +"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user.email);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})})]}),"\n",(0,c.jsx)(l.h3,{id:"updating-rows",children:"Updating Rows"}),"\n",(0,c.jsxs)(l.p,{children:["Find a row, modify it, then call ",(0,c.jsx)(l.code,{children:"update"})," on the same unique column:"]}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsx)(a.A,{value:"typescript",label:"TypeScript",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.db.user.id."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (user) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  user.name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Bob"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  ctx.db.user.id."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"update"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(user);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"csharp",label:"C#",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Db.User.Id."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"is"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" not"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" null"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    user.Name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Bob"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ctx.Db.User.Id."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Update"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(user);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"rust",label:"Rust",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"if"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Some"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"mut"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"id"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:' "Bob"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"id"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"update"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(user);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"cpp",label:"C++",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"auto"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.db[user_id]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"->"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Bob"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ctx.db[user_id]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"update"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"*"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"user);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})})]}),"\n",(0,c.jsx)(l.h3,{id:"deleting-rows",children:"Deleting Rows"}),"\n",(0,c.jsx)(l.p,{children:"Delete by unique column value or by indexed column value:"}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsx)(a.A,{value:"typescript",label:"TypeScript",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Delete by primary key"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx.db.user.id."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"delete"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Delete all matching an indexed column"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" deleted "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.db.user.name."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"delete"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Alice"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`Deleted "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"deleted"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:" row(s)`"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]})]})})})}),(0,c.jsx)(a.A,{value:"csharp",label:"C#",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Delete by primary key"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx.Db.User.Id."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Delete"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Delete all matching an indexed column"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" deleted "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Db.User.Name."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Delete"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Alice"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Info"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Deleted "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"deleted"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:" row(s)"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]})]})})})}),(0,c.jsx)(a.A,{value:"rust",label:"Rust",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Delete by primary key"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"id"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"delete"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Delete all matching an indexed column"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" deleted "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"name"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"delete"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Alice"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"info!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Deleted {} row(s)"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", deleted);"})]})]})})})}),(0,c.jsx)(a.A,{value:"cpp",label:"C++",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Delete by primary key"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx.db[user_id]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"delete_by_key"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"123"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Delete all matching an indexed column"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"uint32_t"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" deleted "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"for"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" auto&"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user : ctx.db[user_name]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"filter"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Alice"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ctx.db[user_id]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"delete_by_key"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(user.id);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    deleted"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"++"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"LOG_INFO"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Deleted "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" +"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" std"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(deleted) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"+"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:" row(s)"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]})]})})})})]}),"\n",(0,c.jsx)(l.h3,{id:"iterating-all-rows",children:"Iterating All Rows"}),"\n",(0,c.jsxs)(l.p,{children:["Use ",(0,c.jsx)(l.code,{children:"iter"})," to iterate over all rows in a table:"]}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsx)(a.A,{value:"typescript",label:"TypeScript",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"for"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"of"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.db.user."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"iter"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"user.id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:": "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"user.name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"csharp",label:"C#",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"foreach"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"in"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Db.User."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Iter"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"())"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Info"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:": "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"rust",label:"Rust",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"for"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"in"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"iter"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"() {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    log"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"info!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"{}: {}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"id, user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"name);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"cpp",label:"C++",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"for"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" auto&"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user : ctx.db[user]) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"    LOG_INFO"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(std"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(user.id) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"+"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:": "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" +"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user.name);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})})]}),"\n",(0,c.jsx)(l.h3,{id:"counting-rows",children:"Counting Rows"}),"\n",(0,c.jsxs)(l.p,{children:["Use ",(0,c.jsx)(l.code,{children:"count"})," to get the number of rows in a table:"]}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsx)(a.A,{value:"typescript",label:"TypeScript",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" total "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.db.user."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"count"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`Total users: "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"total"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]})]})})})}),(0,c.jsx)(a.A,{value:"csharp",label:"C#",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" total "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Db.User.Count;"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Info"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Total users: "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"total"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]})]})})})}),(0,c.jsx)(a.A,{value:"rust",label:"Rust",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" total "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"count"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"info!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Total users: {}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", total);"})]})]})})})}),(0,c.jsx)(a.A,{value:"cpp",label:"C++",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"auto"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" total "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.db[user]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"count"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"LOG_INFO"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Total users: "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" +"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" std"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(total));"})]})]})})})})]}),"\n",(0,c.jsxs)(l.p,{children:["For more details on querying with indexes, including range queries and multi-column indexes, see ",(0,c.jsx)(l.a,{href:"/docs/tables/indexes",children:"Indexes"}),"."]}),"\n",(0,c.jsx)(l.h2,{id:"reducer-isolation",children:"Reducer Isolation"}),"\n",(0,c.jsxs)(l.p,{children:["Reducers run in an isolated environment and ",(0,c.jsx)(l.strong,{children:"cannot"})," interact with the outside world:"]}),"\n",(0,c.jsxs)(l.ul,{children:["\n",(0,c.jsx)(l.li,{children:"\u274c No network requests"}),"\n",(0,c.jsx)(l.li,{children:"\u274c No file system access"}),"\n",(0,c.jsx)(l.li,{children:"\u274c No system calls"}),"\n",(0,c.jsx)(l.li,{children:"\u2705 Only database operations"}),"\n"]}),"\n",(0,c.jsxs)(l.p,{children:["If you need to interact with external systems, use ",(0,c.jsx)(l.a,{href:"/docs/functions/procedures",children:"Procedures"})," instead. Procedures can make network calls and perform other side effects, but they have different execution semantics and limitations."]}),"\n",(0,c.jsxs)(l.admonition,{title:"Global and Static Variables Are Undef
1ined Behavior",type:"warning",children:[(0,c.jsxs)(l.p,{children:["Relying on global variables, static variables, or module-level state to persist across reducer calls is ",(0,c.jsx)(l.strong,{children:"undefined behavior"}),". SpacetimeDB does not guarantee that values stored in these locations will be available in subsequent reducer invocations."]}),(0,c.jsx)(l.p,{children:"This is undefined for several reasons:"}),(0,c.jsxs)(l.ol,{children:["\n",(0,c.jsxs)(l.li,{children:[(0,c.jsx)(l.strong,{children:"Fresh execution environments."})," SpacetimeDB may run each reducer in a fresh WASM or JS instance."]}),"\n",(0,c.jsxs)(l.li,{children:[(0,c.jsx)(l.strong,{children:"Module updates."})," Publishing a new module creates a fresh execution environment. This is necessary for hot-swapping modules while transactions are in flight."]}),"\n",(0,c.jsxs)(l.li,{children:[(0,c.jsx)(l.strong,{children:"Concurrent execution."})," SpacetimeDB reserves the right to execute multiple reducers concurrently in separate execution environments (e.g., with MVCC)."]}),"\n",(0,c.jsxs)(l.li,{children:[(0,c.jsx)(l.strong,{children:"Crash recovery."})," Instance memory is not persisted across restarts."]}),"\n",(0,c.jsxs)(l.li,{children:[(0,c.jsx)(l.strong,{children:"Non-transactional updates."})," If you modify global state and then roll back the transaction, the modified value may remain for subsequent transactions."]}),"\n",(0,c.jsxs)(l.li,{children:[(0,c.jsx)(l.strong,{children:"Replay safety."})," If a serializability anomaly is detected, SpacetimeDB may re-execute your reducer with the same arguments, causing modifications to global state to occur multiple times."]}),"\n"]}),(0,c.jsx)(l.p,{children:"Reducers are designed to be free of side effects. They should only modify tables. Always store state in tables to ensure correctness and durability."}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// \u274c Undefined behavior: may or may not persist or correctly update across reducer calls"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" mut"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" COUNTER"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u64"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// \u2705 Store state in a table instead"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"table(accessor "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" counter)]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"pub"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" struct"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Counter"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    #[primary_key]"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    value"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u64"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})]}),"\n",(0,c.jsx)(l.h2,{id:"scheduling-procedures",children:"Scheduling Procedures"}),"\n",(0,c.jsxs)(l.p,{children:["Reducers cannot call procedures directly (procedures may have side effects incompatible with transactional execution). Instead, schedule a procedure to run by inserting into a ",(0,c.jsx)(l.a,{href:"/docs/tables/schedule-tables",children:"schedule table"}),":"]}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsx)(a.A,{value:"typescript",label:"TypeScript",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"import"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { ScheduleAt } "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"from"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"import"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { schema, t, table } "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"from"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"spacetimedb/server"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Define a schedule table for the procedure"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" fetchSchedule "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  { name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"fetch_schedule"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    scheduledId"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"u64"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"primaryKey"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"autoInc"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    scheduledAt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"scheduleAt"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    url"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" schema"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({ fetchSchedule });"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"export"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" default"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb;"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// The procedure to be scheduled, bound to the schedule table with `onSchedule`."})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// A scheduled procedure must return `t.unit()`."})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"export"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" fetchExternalData "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  { onSchedule"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" fetchSchedule },"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  { arg"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" fetchSchedule.rowType },"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"unit"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"arg"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.http."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"fetch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(arg.url);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"    // Process response..."})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {};"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// From a reducer, schedule the procedure by inserting into the schedule table"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"export"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" queueFetch "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"reducer"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({ url"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"() }, ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"url"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  ctx.db.fetchSchedule."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    scheduledId"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"n"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    scheduledAt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ScheduleAt."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"interval"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"0"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"n"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"), "}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Run immediately"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    url,"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"  });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})})}),(0,c.jsx)(a.A,{value:"csharp",label:"C#",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#pragma"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" warning"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" disable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" STDB_UNSTABLE"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" class"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:" Module"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(Accessor "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"FetchSchedule"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", Scheduled "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"FetchExternalData"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", ScheduledAt "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"ScheduledAt"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" struct"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" FetchSchedule"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"PrimaryKey"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"AutoInc"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"        public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ulong"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ScheduledId;"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"        public"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" ScheduleAt"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ScheduledAt;"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"        public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Url;"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" void"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" FetchExternalData"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"FetchSchedule"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" schedule"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"        var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" result "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Http."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Get"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(schedule.Url);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"        if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (result "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"is"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Result"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpResponse"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpError"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:">."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"OkR"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response))"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        {"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"            // Process response..."})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"    // From a reducer, schedule the procedure"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Reducer"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" void"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" QueueFetch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" url"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        ctx.Db.FetchSchedule."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" FetchSchedule"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"            ScheduledId "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"            ScheduledAt "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" ScheduleAt"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Interval"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(TimeSpan.Zero),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"            Url "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" url,"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"rust",label:"Rust",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"use"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ScheduleAt"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"};"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"use"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" std"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"time"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Duration"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"table(accessor "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" fetch_schedule, scheduled(fetch_external_data))]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"pub"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" struct"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" FetchSchedule"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    #[primary_key]"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    #[auto_inc]"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    scheduled_id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u64"}),(0,c.jsx)(l.span,{style
1:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    scheduled_at"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" ScheduleAt"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    url"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedure]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" fetch_external_data"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &mut"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", schedule"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" FetchSchedule"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    if"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Ok"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(response) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"http"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"get"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"&"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"schedule"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"url) {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"        // Process response..."})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// From a reducer, schedule the procedure"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"reducer]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" queue_fetch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", url"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"fetch_schedule"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"FetchSchedule"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        scheduled_id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        scheduled_at"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ScheduleAt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Interval"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(Duration"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"ZERO"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"into"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        url,"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"cpp",label:"C++",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#define"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" SPACETIMEDB_UNSTABLE_FEATURES"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#include"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" <"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"spacetimedb.h"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:">"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" namespace"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" SpacetimeDB;"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Define a table to store scheduled tasks"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"struct"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" FetchSchedule"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    uint64_t"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" scheduled_id;"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ScheduleAt scheduled_at;"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    std"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"string url;"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"};"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"SPACETIMEDB_STRUCT"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(FetchSchedule, scheduled_id, scheduled_at, url);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"SPACETIMEDB_TABLE"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(FetchSchedule, fetch_schedule, Private);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"FIELD_PrimaryKeyAutoInc"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(fetch_schedule, scheduled_id);"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Register the table for scheduling (column 1 = scheduled_at field, 0-based index)"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"SPACETIMEDB_SCHEDULE"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(fetch_schedule, "}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"1"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", fetch_external_data);"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// The procedure to be scheduled - called automatically when the time arrives"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"SPACETIMEDB_PROCEDURE"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"uint32_t"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", fetch_external_data, ProcedureContext ctx, FetchSchedule schedule) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"    LOG_INFO"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Fetching data from: "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" +"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" schedule.url);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"    // Process response..."})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    return"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"  // Success"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// From a reducer, schedule the procedure by inserting into the schedule table"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"SPACETIMEDB_REDUCER"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(queue_fetch, ReducerContext ctx, std"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"string url) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    auto"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" scheduled_at "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" ScheduleAt"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(TimeDuration"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"from_seconds"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"));"}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"  // Run immediately"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    FetchSchedule fetch_task{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"        0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"                // scheduled_id - auto-increment will assign"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        scheduled_at,"}),(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"     // When to execute"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"        url"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    };"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"    ctx.db[fetch_schedule]."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(fetch_task);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"    LOG_INFO"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Fetch scheduled for URL: "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" +"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" url);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"    return"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" Ok"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"();"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})})]}),"\n",(0,c.jsxs)(l.p,{children:["See ",(0,c.jsx)(l.a,{href:"/docs/tables/schedule-tables",children:"Schedule Tables"})," for more scheduling options."]}),"\n",(0,c.jsx)(l.h2,{id:"next-steps",children:"Next Steps"}),"\n",(0,c.jsxs)(l.ul,{children:["\n",(0,c.jsxs)(l.li,{children:["Learn about ",(0,c.jsx)(l.a,{href:"/docs/tables",children:"Tables"})," to understand data storage"]}),"\n",(0,c.jsxs)(l.li,{children:["Explore ",(0,c.jsx)(l.a,{href:"/docs/functions/procedures",children:"Procedures"})," for side effects beyond the database"]}),"\n",(0,c.jsxs)(l.li,{children:["Review ",(0,c.jsx)(l.a,{href:"/docs/clients/subscriptions",children:"Subscriptions"})," for real-time client updates"]}),"\n"]})]})}function p(s={}){const{wrapper:l}={...(0,r.R)(),...s.components};return l?(0,c.jsx)(l,{...s,children:(0,c.jsx)(x,{...s})}):x(s)}},56225:(s,l,e)=>{e.d(l,{R:()=>o,x:()=>a});var n=e(7378);const c={},r=n.createContext(c);function o(s){const l=n.useContext(r);return n.useMemo(function(){return"function"==typeof s?s(l):{...l,...s}},[l,s])}function a(s){let l;return l=s.disableParentContext?"function"==typeof s.components?s.components(c):s.components||c:o(s.components),n.createElement(r.Provider,{value:l},s.children)}},67834:(s,l,e)=>{e.d(l,{_:()=>c});e(7378);var n=e(86106);function c(){return(0,n.jsx)(n.Fragment,{})}}}]);

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.