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
**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<TaylorDatabase>({
baseUrl: process.env.TAYLORDB_BASE_URL!,
baseId: process.env.TAYLORDB_SERVER_ID!,
apiKey: "",
publicProcedure.input({}).query(({ input }) => {
const queryBuilder = ctx.queryBuilder;
});
```
// ============================================================================
// 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
### 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();
```