From 71df6a350dd78456be373d41bd029bf6a60e862e Mon Sep 17 00:00:00 2001 From: Umar Adilov <99314948+adilovcode@users.noreply.github.com> Date: Fri, 13 Feb 2026 18:38:07 +0500 Subject: [PATCH] Added details on query builder access --- AGENTS.md | 14 +++----- docs/TAYLORDB_QUERY_REFERENCE.md | 61 ++++++++++++-------------------- 2 files changed, 27 insertions(+), 48 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 47f4706..640b0b7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -54,19 +54,15 @@ Document your design decisions briefly before implementing. #### Step 1: Set Up Server-Side Data Layer -**File: `apps/server/taylordb/query-builder.ts`** +Use querybuilder which is in **File: `apps/server/taylordb/query-builder.ts`** -This file contains all database operations. Create type-safe CRUD functions for each table: +You can access the query builder from ```typescript -import { createQueryBuilder } from "@taylordb/query-builder"; -import type { TaylorDatabase } from "./types.js"; - -export const queryBuilder = createQueryBuilder({ - baseUrl: process.env.TAYLORDB_BASE_URL!, - baseId: process.env.TAYLORDB_SERVER_ID!, - apiKey: "", +publicProcedure.input({}).query(({ input }) => { + const queryBuilder = ctx.queryBuilder; }); +``` // ============================================================================ // READ Operations diff --git a/docs/TAYLORDB_QUERY_REFERENCE.md b/docs/TAYLORDB_QUERY_REFERENCE.md index b54c834..36b04f0 100644 --- a/docs/TAYLORDB_QUERY_REFERENCE.md +++ b/docs/TAYLORDB_QUERY_REFERENCE.md @@ -19,25 +19,6 @@ This document provides comprehensive examples of how to use the TaylorDB query b --- -## Setup & Configuration - -### Initialize Query Builder - -```typescript -import { createQueryBuilder } from "@taylordb/query-builder"; -import type { TaylorDatabase } from "./types.js"; - -export const queryBuilder = createQueryBuilder({ - baseUrl: process.env.TAYLORDB_BASE_URL!, - baseId: process.env.TAYLORDB_SERVER_ID!, - apiKey: "", -}); -``` - -The type parameter `` provides full type safety based on your generated schema. - ---- - ## Basic Queries ### Get All Records @@ -167,6 +148,7 @@ const adminUsers = await getUsersByTags(["admin", "moderator"]); ### Select Field Filtering #### Single Select + For single-select fields, the query builder now returns a single string value. ```typescript @@ -179,6 +161,7 @@ export async function getUsersByRole(role: string) { ``` #### Multi Select + For multi-select fields, the query builder returns and accepts multiple values. ```typescript @@ -550,16 +533,16 @@ export async function getPaginatedUsers(page: number, pageSize: number) { ### Field Type Reference -| TaylorDB Field Type | TypeScript Type | Insert Value | Query Value | -| ------------------- | -------------------- | ---------------------- | ---------------------------- | -| **Text** | `string` | `"Hello"` | `"Hello"` | -| **Number** | `number` | `42` | `42` | -| **Date** | `string` (ISO) | `"2024-01-15"` | `["exactDay", "2024-01-15"]` | -| **Checkbox** | `boolean` | `true` | `true` | -| **Single Select** | `string` | `"option"` | `"option"` | -| **Multi Select** | `string[]` | `["opt1", "opt2"]` | `["opt1", "opt2"]` | -| **Attachment** | `string[]` (File Paths) | `uploadAttachments()` | `"file-path"` | -| **Email** | `string` | `"user@example.com"` | `"user@example.com"` | +| TaylorDB Field Type | TypeScript Type | Insert Value | Query Value | +| ------------------- | ----------------------- | --------------------- | ---------------------------- | +| **Text** | `string` | `"Hello"` | `"Hello"` | +| **Number** | `number` | `42` | `42` | +| **Date** | `string` (ISO) | `"2024-01-15"` | `["exactDay", "2024-01-15"]` | +| **Checkbox** | `boolean` | `true` | `true` | +| **Single Select** | `string` | `"option"` | `"option"` | +| **Multi Select** | `string[]` | `["opt1", "opt2"]` | `["opt1", "opt2"]` | +| **Attachment** | `string[]` (File Paths) | `uploadAttachments()` | `"file-path"` | +| **Email** | `string` | `"user@example.com"` | `"user@example.com"` | ### Handling Nullable Fields @@ -706,8 +689,8 @@ Attachments are no longer treated as relations. They are now standard columns an ```typescript // New Standard: Use regular .select() like any other field. const expenses = await qb - .selectFrom('expenses') - .select(['id', 'amount', 'receipt']) + .selectFrom("expenses") + .select(["id", "amount", "receipt"]) .execute(); ``` @@ -717,12 +700,12 @@ Use `qb.uploadAttachments` to upload files before inserting. ```typescript await qb - .insertInto('customers') + .insertInto("customers") .values({ - firstName: 'Jane', - lastName: 'Doe', + firstName: "Jane", + lastName: "Doe", avatar: await qb.uploadAttachments([ - { file: new Blob(['']), name: 'test.png' }, + { file: new Blob([""]), name: "test.png" }, ]), }) .execute(); @@ -732,14 +715,14 @@ await qb ```typescript await qb - .update('customers') + .update("customers") .set({ - lastName: 'Smith', + lastName: "Smith", avatar: await qb.uploadAttachments([ - { file: new Blob(['']), name: 'test.png' }, + { file: new Blob([""]), name: "test.png" }, ]), }) - .where('id', '=', 1) + .where("id", "=", 1) .execute(); ```