The db object is used to query the database. It is designed as a tenant-aware connection pool.
When nile.tenantId is set, the db object will use the correct tenant’s virtual database.
All tenants and users have access to any shared tables - tables without a tenant id column.
const db = nile.db;await db.query( 'CREATE TABLE IF NOT EXISTS shared_table (id INTEGER, name TEXT)',);await db.query('INSERT INTO shared_table (id, name) VALUES (1, "John Doe")');const result = await db.query('SELECT * FROM shared_table');console.log(result);
Tenant-aware tables have a tenant id column.
If you query without setting nile.tenantId, this will be a cross-tenant query.
If you set nile.withContext({ tenantId }), the query will run against the tenant’s virtual database.When inserting data into a tenant-aware table, you need to provide the tenant id - and it has to belong to an existing tenant.
If you set nile.withContext({ tenantId }), the tenant id must match the tenant id in the table.In the example below, we also use parameter substitution to prevent SQL injection.
nile.db is a context-less way to query the database. nile.query uses
context when querying the database, if the context is set
const { db } = nile; // using DB means it will be a cross-tenant query.const some_name = 'John Doe';const some_tenant_id = '0195f45d-c3ca-7b29-8a9c-717a99d993a1';await db.query( 'CREATE TABLE IF NOT EXISTS tenant_table (id INTEGER, name TEXT, tenant_id UUID)',);await db.query( 'INSERT INTO tenant_table (id, name, tenant_id) VALUES (1, $1, $2)', [some_name, some_tenant_id],);const result = await db.query('SELECT * FROM tenant_table'); // this will return all rows from all tenantsconsole.log(result);
const context = { tenantId: '0195f45d-c3ca-7b29-8a9c-717a99d993a1'; // may be omitted if already set}const { query } = await nile.withContext(context);const some_name = 'John Doe';await query('CREATE TABLE IF NOT EXISTS tenant_table (id INTEGER, name TEXT, tenant_id UUID)');await query('INSERT INTO tenant_table (id, name, tenant_id) VALUES (1, $1, $2)', [some_name , context.tenantId]);const result = await query('SELECT * FROM tenant_table'); // this will only return rows where tenant_id matches the current tenantconsole.log(result);
The client method is used to get a client from the database connection pool. This can be useful if you want to run several queries on the same connection.
The client is not automatically released back to the pool after the query is
executed. You need to call client.release() to release it back to the pool.
The example below uses client to run a transaction - a group of queries that are executed as a single unit.
If any of the queries fail, the transaction is rolled back.
If all queries succeed, the transaction is committed.
The client object guarantees that all queries are executed on the same connection.
It is then released back to the pool after the transaction is committed or rolled back.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Nile Documentation","colors":{"primary":"#fdb768","light":"#fdb768","dark":"#fdb768"},"logo":{"light":"https://mintcdn.com/nile/SZ6JYQiPYP1_QgSP/images/nilemintlogo.svg?fit=max\u0026auto=format\u0026n=SZ6JYQiPYP1_QgSP\u0026q=85\u0026s=3303eacc9118937fc5b967ee98a24024","dark":"https://mintcdn.com/nile/SZ6JYQiPYP1_QgSP/images/nilemintlogo.svg?fit=max\u0026auto=format\u0026n=SZ6JYQiPYP1_QgSP\u0026q=85\u0026s=3303eacc9118937fc5b967ee98a24024","href":"https://www.thenile.dev"},"favicon":"https://mintcdn.com/nile/CzaL00MoWjPpKNw_/images/favicon.svg?fit=max\u0026auto=format\u0026n=CzaL00MoWjPpKNw_\u0026q=85\u0026s=5c01c6ff6f635b2a4799d56abab1a71a","appearance":{"default":"dark","strict":true},"navbar":{"links":[{"href":"https://discord.com/invite/8UuBB84tTy","label":"Community"}],"primary":{"type":"button","label":"Get Started","href":"https://console.thenile.dev"}},"footer":{"socials":{"x":"https://x.com/niledatabase","github":"https://github.com/niledatabase/niledatabase","linkedin":"https://www.linkedin.com/company/niledatabase","discord":"https://discord.com/invite/8UuBB84tTy"},"links":[{"header":"Resources","items":[{"label":"Blog","href":"https://www.thenile.dev/blog"},{"label":"Pricing","href":"https://www.thenile.dev/pricing"},{"label":"Templates","href":"https://www.thenile.dev/templates"},{"label":"Community","href":"https://www.thenile.dev/community"}]},{"header":"Company","items":[{"label":"Careers","href":"https://www.thenile.dev/about-us"},{"label":"About","href":"https://www.thenile.dev/about-us"}]},{"header":"Support","items":[{"label":"Contact Sales","href":"https://www.thenile.dev/contact-us"},{"label":"Get Help","href":"https://www.thenile.dev/contact-us"},{"label":"FAQ","href":"https://www.thenile.dev/pricing"}]}]},"seo":{"metatags":{"og:image":"https://www.thenile.dev/opengraph/docs.jpg"},"indexing":"navigable"},"integrations":{"ga4":{"measurementId":"G-KE7812B4ZF"}},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"nile","hasAudioNarration":false,"actualSubdomain":"nile","customDomains":["thenile.dev"],"gitSource":{"type":"github","owner":"niledatabase","repo":"niledatabase","deployBranch":"main","contentDirectory":"www/app/docs","isPrivate":true,"mountPath":"","label":""},"chroma":{"liveDeploymentHistoryId":"6a9cbf6e7168debd2fad7286","collectionId":"92cf1a7a-4366-49ff-a155-84808e6665bd","schemaVersion":"v3","latestBuiltDeploymentHistoryId":"6a9cbf6e7168debd2fad7286"},"feedback":{"thumbs":true,"issues":false},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6a9cbf6e7168debd2fad7286","clientVersion":"0.0.4054","searchFilterCounts":[{"language":"default","tag":"Postgres","count":93},{"language":"default","tag":"Auth","count":68},{"language":"default","tag":"Nile Auth","count":61},{"language":"default","tag":"ManagementAPI","count":40},{"language":"default","tag":"Extensions","count":37},{"language":"default","tag":"Get Started","count":37},{"language":"default","tag":"Auth API","count":33},{"language":"default","tag":"Platform","count":24},{"language":"default","tag":"databases","count":20},{"language":"default","tag":"Usecases","count":18}]},"assistantConfig":{},"basePath":"/docs","hasChatPermissions":true,"hasWebMcpPermissions":true,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-updated-9-15","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"auth/sdk-reference/javascript/server/db","slug":"/auth/sdk-reference/javascript/server/db","pageMetadata":{"title":"DB","description":"Using the Nile-JS SDK DB client","href":"/auth/sdk-reference/javascript/server/db"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Using the Nile-JS SDK DB client\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,CodeGroup,Heading,Note,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!CodeGroup)_missingMdxReference(`CodeGroup`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Note)_missingMdxReference(`Note`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`db`}),` object is used to query the database. It is designed as a tenant-aware connection pool.\nWhen `,_jsx(_components.code,{children:`nile.tenantId`}),` is set, the `,_jsx(_components.code,{children:`db`}),` object will use the correct tenant’s virtual database.`]}),`\n`,_jsx(Heading,{level:`2`,id:`query`,children:`query`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`query`}),` method is used to query the database. This is the main method exposed by the `,_jsx(_components.code,{children:`db`}),` object.`]}),`\n`,_jsx(Heading,{level:`3`,id:`parameters`,children:`Parameters`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`sql`}),`: The SQL query to execute.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`params`}),`: The parameters to use in the query.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`3`,id:`querying-a-shared-table`,children:`Querying a shared table`}),`\n`,_jsxs(_components.p,{children:[`All tenants and users have access to any `,_jsx(_components.a,{href:`/tenant-virtualization/tenant-sharing`,children:`shared tables`}),` - tables without a tenant id column.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` db`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` nile`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'CREATE TABLE IF NOT EXISTS shared_table (id INTEGER, name TEXT)'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'INSERT INTO shared_table (id, name) VALUES (1, \"John Doe\")'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` result`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'SELECT * FROM shared_table'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`result`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`querying-a-tenant-aware-table`,children:`Querying a tenant-aware table`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.a,{href:`/tenant-virtualization/tenant-isolation`,children:`Tenant-aware tables`}),` have a tenant id column.\nIf you query without setting `,_jsx(_components.code,{children:`nile.tenantId`}),`, this will be a cross-tenant query.\nIf you set `,_jsx(_components.code,{children:`nile.withContext({ tenantId })`}),`, the query will run against the tenant’s virtual database.`]}),`\n`,_jsxs(_components.p,{children:[`When inserting data into a tenant-aware table, you need to provide the tenant id - and it has to belong to an existing tenant.\nIf you set `,_jsx(_components.code,{children:`nile.withContext({ tenantId })`}),`, the tenant id must match the tenant id in the table.`]}),`\n`,_jsx(_components.p,{children:`In the example below, we also use parameter substitution to prevent SQL injection.`}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`nile.db`}),` is a context-less way to query the database. `,_jsx(_components.code,{children:`nile.query`}),` uses\ncontext when querying the database, if the context is set`]})}),`\n`,_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`cross-tenant query`,numberOfLines:`12`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`12`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` nile`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`; `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// using DB means it will be a cross-tenant query.`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` some_name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'John Doe'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` some_tenant_id`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '0195f45d-c3ca-7b29-8a9c-717a99d993a1'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'CREATE TABLE IF NOT EXISTS tenant_table (id INTEGER, name TEXT, tenant_id UUID)'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'INSERT INTO tenant_table (id, name, tenant_id) VALUES (1, $1, $2)'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`some_name`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`some_tenant_id`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` result`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'SELECT * FROM tenant_table'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// this will return all rows from all tenants`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`result`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`]})})}),_jsx(CodeBlock,{filename:`tenant-aware query`,numberOfLines:`9`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`9`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` context`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` tenantId:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '0195f45d-c3ca-7b29-8a9c-717a99d993a1'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`; `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// may be omitted if already set`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` nile`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`withContext`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`context`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` some_name`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'John Doe'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'CREATE TABLE IF NOT EXISTS tenant_table (id INTEGER, name TEXT, tenant_id UUID)'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'INSERT INTO tenant_table (id, name, tenant_id) VALUES (1, $1, $2)'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, [`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`some_name`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` , `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`context`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`tenantId`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`]);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` result`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'SELECT * FROM tenant_table'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`); `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// this will only return rows where tenant_id matches the current tenant`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`result`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`]})})})]}),`\n`,_jsx(Heading,{level:`2`,id:`client`,children:`client`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.code,{children:`client`}),` method is used to get a client from the database connection pool. This can be useful if you want to run several queries on the same connection.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`The client is not automatically released back to the pool after the query is\nexecuted. You need to call `,_jsx(_components.code,{children:`client.release()`}),` to release it back to the pool.`]})}),`\n`,_jsx(Heading,{level:`3`,id:`example`,children:`Example`}),`\n`,_jsxs(_components.p,{children:[`The example below uses `,_jsx(_components.code,{children:`client`}),` to run a transaction - a group of queries that are executed as a single unit.\nIf any of the queries fail, the transaction is rolled back.\nIf all queries succeed, the transaction is committed.\nThe `,_jsx(_components.code,{children:`client`}),` object guarantees that all queries are executed on the same connection.\nIt is then released back to the pool after the transaction is committed or rolled back.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`13`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`13`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:`db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` } `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` nile`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` client`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`client`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`try`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` client`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'BEGIN'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'INSERT INTO shared_table (id, name) VALUES (1, \"John Doe\")'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` db`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'INSERT INTO shared_table (id, name) VALUES (2, \"Jane Doe\")'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` client`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'COMMIT'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`} `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`catch`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` client`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`query`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'ROLLBACK'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` throw`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` error`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`} `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`finally`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` client`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`release`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"DB","description":"Using the Nile-JS SDK DB client","href":"/auth/sdk-reference/javascript/server/db"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"query","slug":"query","depth":2,"children":[{"title":"Parameters","slug":"parameters","depth":3,"children":[]},{"title":"Querying a shared table","slug":"querying-a-shared-table","depth":3,"children":[]},{"title":"Querying a tenant-aware table","slug":"querying-a-tenant-aware-table","depth":3,"children":[]}]},{"title":"client","slug":"client","depth":2,"children":[{"title":"Example","slug":"example","depth":3,"children":[]}]}],"codeExamples":{}},"jsLinks":[],"subdomain":"nile","siteName":"Nile Documentation","title":"DB - Nile Documentation","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2025-12-08T20:52:59.597Z","originalFileLocation":"auth/sdk-reference/javascript/server/db.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=\"dark\";if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"dark\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Using the Nile-JS SDK DB client\">\u003cmeta data-mint-head name=\"application-name\" content=\"Nile Documentation\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/nile/GO7FOq6RcmxStYK0/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/docs/mintlify-assets/_mintlify/favicons/nile/GO7FOq6RcmxStYK0/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/nile/GO7FOq6RcmxStYK0/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/nile/GO7FOq6RcmxStYK0/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/nile/GO7FOq6RcmxStYK0/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/nile/GO7FOq6RcmxStYK0/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/nile/GO7FOq6RcmxStYK0/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/nile/GO7FOq6RcmxStYK0/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/nile/GO7FOq6RcmxStYK0/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"DB - Nile Documentation\">\u003cmeta data-mint-head property=\"og:description\" content=\"Using the Nile-JS SDK DB client\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Nile Documentation\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://thenile.dev/docs/auth/sdk-reference/javascript/server/db\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://www.thenile.dev/opengraph/docs.jpg\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"DB - Nile Documentation\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Using the Nile-JS SDK DB client\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://www.thenile.dev/opengraph/docs.jpg\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/docs/mintlify-assets/_mintlify/favicons/nile/GO7FOq6RcmxStYK0/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Nile Documentation\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#fdb768\">\u003clink data-mint-head rel=\"canonical\" href=\"https://thenile.dev/docs/auth/sdk-reference/javascript/server/db\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/docs/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/docs/auth/sdk-reference/javascript/server/db.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://thenile.dev/#organization\",\"name\":\"Nile Documentation\",\"url\":\"https://thenile.dev\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/nile/SZ6JYQiPYP1_QgSP/images/nilemintlogo.svg?fit=max\u0026auto=format\u0026n=SZ6JYQiPYP1_QgSP\u0026q=85\u0026s=3303eacc9118937fc5b967ee98a24024\"}},{\"@type\":\"WebSite\",\"@id\":\"https://thenile.dev/docs#website\",\"name\":\"Nile Documentation\",\"url\":\"https://thenile.dev/docs\",\"publisher\":{\"@id\":\"https://thenile.dev/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://thenile.dev/docs/auth/sdk-reference/javascript/server/db#webpage\",\"url\":\"https://thenile.dev/docs/auth/sdk-reference/javascript/server/db\",\"name\":\"DB\",\"description\":\"Using the Nile-JS SDK DB client\",\"dateModified\":\"2025-12-08T20:52:59.597Z\",\"isPartOf\":{\"@id\":\"https://thenile.dev/docs#website\"},\"breadcrumb\":{\"@id\":\"https://thenile.dev/docs/auth/sdk-reference/javascript/server/db#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://thenile.dev/docs/auth/sdk-reference/javascript/server/db#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Nile Auth\",\"item\":\"https://thenile.dev/docs/auth/introduction\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SDK Reference\",\"item\":\"https://thenile.dev/docs/auth/sdk-reference/javascript/overview\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript (server)\",\"item\":\"https://thenile.dev/docs/auth/sdk-reference/javascript/overview\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"DB\",\"item\":\"https://thenile.dev/docs/auth/sdk-reference/javascript/server/db\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://thenile.dev/docs/auth/sdk-reference/javascript/server/db#article\",\"headline\":\"DB\",\"name\":\"DB\",\"description\":\"Using the Nile-JS SDK DB client\",\"url\":\"https://thenile.dev/docs/auth/sdk-reference/javascript/server/db\",\"mainEntityOfPage\":{\"@id\":\"https://thenile.dev/docs/auth/sdk-reference/javascript/server/db#webpage\"},\"image\":\"https://www.thenile.dev/opengraph/docs.jpg\",\"dateModified\":\"2025-12-08T20:52:59.597Z\",\"publisher\":{\"@id\":\"https://thenile.dev/#organization\"},\"isPartOf\":{\"@id\":\"https://thenile.dev/docs#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Nile Documentation\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Nile Documentation","nav":{"global":null,"tabs":[{"tab":"Postgres","pages":[{"title":"Postgres","href":"/getting-started/getting-started"}]},{"tab":"Auth","pages":[{"group":"Nile Auth","pages":[{"title":"Introduction","icon":"user","href":"/auth/introduction"},{"title":"Comparison","icon":"code-compare","href":"/auth/comparison"},{"title":"Installation","icon":"play","href":"/auth/getting-started/installation"},{"group":"Quickstart","icon":"rocket","pages":[{"title":"NextJs","icon":"square-arrow-up-right","href":"/auth/quickstarts/nextjs"},{"title":"Remix","icon":"shuffle","href":"/auth/quickstarts/remix"},{"title":"Express.js","icon":"server","href":"/auth/quickstarts/express"}]},{"title":"Self Host Nile Auth","icon":"server","href":"/auth/selfhosting"},{"title":"Examples","icon":"lightbulb","href":"/auth/examples"},{"group":"Concepts","icon":"folder","pages":[{"title":"Tenants","href":"/auth/concepts/tenants"},{"title":"Users","href":"/auth/concepts/users"},{"title":"Sessions","href":"/auth/concepts/sessions"},{"title":"JWTs","href":"/auth/concepts/jwt"},{"title":"Cookies","href":"/auth/concepts/cookies"},{"title":"OAuth","href":"/auth/concepts/oauth"},{"title":"Built-in Tables","href":"/auth/concepts/builtintables"},{"title":"Per-Tenant Overrides","href":"/auth/concepts/per-tenantoverrides"},{"title":"Account Linking","href":"/auth/concepts/acclinking"},{"title":"Extensions","href":"/auth/concepts/extensions"},{"title":"Multi-factor Authentication (MFA) Concepts","href":"/auth/concepts/multifactor"}]},{"group":"Email","icon":"envelope","pages":[{"title":"Passwords","href":"/auth/email/password"},{"title":"Templates","href":"/auth/email/templates"},{"title":null,"href":"/auth/email/verification"},{"title":"Custom SMTP","href":"/auth/email/customsmtp"},{"title":null,"href":"/auth/email/invites"}]},{"group":"Single Sign On","icon":"right-to-bracket","pages":[{"title":"Google","icon":"google","href":"/auth/singlesignon/google"},{"title":"GitHub","icon":"github","href":"/auth/singlesignon/github"},{"title":"Discord","icon":"discord","href":"/auth/singlesignon/discord"},{"title":"LinkedIn","icon":"linkedin","href":"/auth/singlesignon/linkedin"},{"title":"Microsoft Azure","icon":"microsoft","href":"/auth/singlesignon/microsoft"},{"title":"HubSpot","icon":"hubspot","href":"/auth/singlesignon/hubspot"},{"title":"X (Twitter)","icon":"x-twitter","href":"/auth/singlesignon/x"},{"title":"Slack","icon":"slack","href":"/auth/singlesignon/slack"}]},{"title":"Magic Link","icon":"wand-magic-sparkles","href":"/auth/magiclink"},{"group":"Components","icon":"browser","pages":[{"title":"Sign In","href":"/auth/components/signin"},{"title":"Sign Up","href":"/auth/components/signup"},{"title":"Sign Out","href":"/auth/components/signout"},{"title":"Users","href":"/auth/components/user"},{"title":"Organization","href":"/auth/components/organization"},{"title":"Customize","href":"/auth/components/customization"},{"title":"Multi-factor","href":"/auth/components/multifactor"}]},{"group":"Dashboard","icon":"table-columns","pages":[{"title":"Managing Tenants","href":"/auth/dashboard/managing-tenants"},{"title":"Managing Users","href":"/auth/dashboard/managing-users"},{"title":"Configurations","href":"/auth/dashboard/configurations"}]},{"group":"Migration","icon":"truck-moving","pages":[{"title":"From NextAuth.js","href":"/auth/migration/fromnextauth"},{"title":"From Firebase","href":"/auth/migration/fromfirebase"},{"title":"From Auth0","href":"/auth/migration/fromauth0"}]},{"group":"SDK Reference","icon":"code","pages":[{"group":"JavaScript (server)","icon":"js","pages":[{"title":"Overview","href":"/auth/sdk-reference/javascript/overview"},{"title":"Auth","href":"/auth/sdk-reference/javascript/server/auth"},{"title":"Users","href":"/auth/sdk-reference/javascript/server/users"},{"title":"Tenants","description":"Managing tenants for the current user","href":"/auth/sdk-reference/javascript/server/tenants"},{"title":"DB","href":"/auth/sdk-reference/javascript/server/db"},{"title":"Routes","description":"Routes in the Nile-JS SDK","href":"/auth/sdk-reference/javascript/server/routes"},{"title":"Configuration","href":"/auth/sdk-reference/javascript/server/configuration"}]},{"title":"JavaScript (client)","icon":"js","href":"/auth/sdk-reference/javascript/client/authorizer"}]},{"group":"Help","icon":"question","pages":[{"title":"Errors","href":"/auth/help/errors"},{"title":"FAQ","href":"/auth/help/faq"},{"title":"Community","href":"/auth/help/community"}]},{"group":"Contributing","icon":"hand-holding-hand","pages":[{"title":"Development","href":"/auth/contributing/develop"},{"title":"Testing","href":"/auth/contributing/testing"},{"title":"Issues","href":"/auth/contributing/report"}]},{"title":"Roadmap","icon":"road","url":"https://github.com/orgs/niledatabase/discussions?discussions_q=label%3Aauth","href":"/auth/roadmap"}]},{"group":"Frameworks","icon":"puzzle-piece","pages":[{"title":"Express","icon":"server","href":"/auth/frameworks/express"},{"title":"Next.js","icon":"n","href":"/auth/frameworks/nextjs"},{"title":"Nitro","icon":"bolt-lightning","href":"/auth/frameworks/nitro"},{"title":"Nuxt","icon":"mountain","href":"/auth/frameworks/nuxt"},{"title":"React","icon":"atom","href":"/auth/frameworks/react"},{"title":"Remix","icon":"route","href":"/auth/frameworks/remix"},{"title":"Elysia","icon":"firefox-browser","href":"/auth/frameworks/elysia"}]}]},{"tab":"AI","pages":[{"title":"AI","href":"/ai-embeddings/introduction"}]},{"tab":"Platform","pages":[{"title":"Platform","href":"/cli/introduction"}]},{"tab":"ManagementAPI","pages":[{"title":"ManagementAPI","href":"/api-reference/databases/list-dedicated-compute-instances-for-a-database"}]},{"tab":"Auth API","pages":[{"title":"Auth API","href":"/auth/api-reference/auth/sign-in-to-the-application"}]},{"tab":"Pricing","href":"https://www.thenile.dev/pricing"},{"tab":"Templates","href":"https://www.thenile.dev/templates"},{"tab":"Discord","href":"https://discord.com/invite/8UuBB84tTy"}]},"basePath":"","title":"DB - Nile Documentation","buildId":"dpl_GWQzn6k13MqphA3qck3hQKoQXDzM","deploymentId":"dpl_GWQzn6k13MqphA3qck3hQKoQXDzM","dynamics":[],"chunks":[]}