Added details on query builder access

This commit is contained in:
Umar Adilov 2026-02-13 18:38:07 +05:00
parent f6c614016d
commit 71df6a350d
2 changed files with 27 additions and 48 deletions

View File

@ -54,19 +54,15 @@ Document your design decisions briefly before implementing.
#### Step 1: Set Up Server-Side Data Layer #### 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 ```typescript
import { createQueryBuilder } from "@taylordb/query-builder"; publicProcedure.input({}).query(({ input }) => {
import type { TaylorDatabase } from "./types.js"; const queryBuilder = ctx.queryBuilder;
export const queryBuilder = createQueryBuilder<TaylorDatabase>({
baseUrl: process.env.TAYLORDB_BASE_URL!,
baseId: process.env.TAYLORDB_SERVER_ID!,
apiKey: "",
}); });
```
// ============================================================================ // ============================================================================
// READ Operations // READ Operations

View File

@ -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<TaylorDatabase>({
baseUrl: process.env.TAYLORDB_BASE_URL!,
baseId: process.env.TAYLORDB_SERVER_ID!,
apiKey: "",
});
```
The type parameter `<TaylorDatabase>` provides full type safety based on your generated schema.
---
## Basic Queries ## Basic Queries
### Get All Records ### Get All Records
@ -167,6 +148,7 @@ const adminUsers = await getUsersByTags(["admin", "moderator"]);
### Select Field Filtering ### Select Field Filtering
#### Single Select #### Single Select
For single-select fields, the query builder now returns a single string value. For single-select fields, the query builder now returns a single string value.
```typescript ```typescript
@ -179,6 +161,7 @@ export async function getUsersByRole(role: string) {
``` ```
#### Multi Select #### Multi Select
For multi-select fields, the query builder returns and accepts multiple values. For multi-select fields, the query builder returns and accepts multiple values.
```typescript ```typescript
@ -550,16 +533,16 @@ export async function getPaginatedUsers(page: number, pageSize: number) {
### Field Type Reference ### Field Type Reference
| TaylorDB Field Type | TypeScript Type | Insert Value | Query Value | | TaylorDB Field Type | TypeScript Type | Insert Value | Query Value |
| ------------------- | -------------------- | ---------------------- | ---------------------------- | | ------------------- | ----------------------- | --------------------- | ---------------------------- |
| **Text** | `string` | `"Hello"` | `"Hello"` | | **Text** | `string` | `"Hello"` | `"Hello"` |
| **Number** | `number` | `42` | `42` | | **Number** | `number` | `42` | `42` |
| **Date** | `string` (ISO) | `"2024-01-15"` | `["exactDay", "2024-01-15"]` | | **Date** | `string` (ISO) | `"2024-01-15"` | `["exactDay", "2024-01-15"]` |
| **Checkbox** | `boolean` | `true` | `true` | | **Checkbox** | `boolean` | `true` | `true` |
| **Single Select** | `string` | `"option"` | `"option"` | | **Single Select** | `string` | `"option"` | `"option"` |
| **Multi Select** | `string[]` | `["opt1", "opt2"]` | `["opt1", "opt2"]` | | **Multi Select** | `string[]` | `["opt1", "opt2"]` | `["opt1", "opt2"]` |
| **Attachment** | `string[]` (File Paths) | `uploadAttachments()` | `"file-path"` | | **Attachment** | `string[]` (File Paths) | `uploadAttachments()` | `"file-path"` |
| **Email** | `string` | `"user@example.com"` | `"user@example.com"` | | **Email** | `string` | `"user@example.com"` | `"user@example.com"` |
### Handling Nullable Fields ### Handling Nullable Fields
@ -706,8 +689,8 @@ Attachments are no longer treated as relations. They are now standard columns an
```typescript ```typescript
// New Standard: Use regular .select() like any other field. // New Standard: Use regular .select() like any other field.
const expenses = await qb const expenses = await qb
.selectFrom('expenses') .selectFrom("expenses")
.select(['id', 'amount', 'receipt']) .select(["id", "amount", "receipt"])
.execute(); .execute();
``` ```
@ -717,12 +700,12 @@ Use `qb.uploadAttachments` to upload files before inserting.
```typescript ```typescript
await qb await qb
.insertInto('customers') .insertInto("customers")
.values({ .values({
firstName: 'Jane', firstName: "Jane",
lastName: 'Doe', lastName: "Doe",
avatar: await qb.uploadAttachments([ avatar: await qb.uploadAttachments([
{ file: new Blob(['']), name: 'test.png' }, { file: new Blob([""]), name: "test.png" },
]), ]),
}) })
.execute(); .execute();
@ -732,14 +715,14 @@ await qb
```typescript ```typescript
await qb await qb
.update('customers') .update("customers")
.set({ .set({
lastName: 'Smith', lastName: "Smith",
avatar: await qb.uploadAttachments([ avatar: await qb.uploadAttachments([
{ file: new Blob(['']), name: 'test.png' }, { file: new Blob([""]), name: "test.png" },
]), ]),
}) })
.where('id', '=', 1) .where("id", "=", 1)
.execute(); .execute();
``` ```