Updated docs adopted single&multiple select & attachments

This commit is contained in:
Umar Adilov 2026-02-13 18:03:54 +05:00
parent 0050023af0
commit f6c614016d

View File

@ -14,7 +14,8 @@ This document provides comprehensive examples of how to use the TaylorDB query b
6. [Deleting Data](#deleting-data) 6. [Deleting Data](#deleting-data)
7. [Advanced Patterns](#advanced-patterns) 7. [Advanced Patterns](#advanced-patterns)
8. [Field Type Handling](#field-type-handling) 8. [Field Type Handling](#field-type-handling)
9. [Common Pitfalls](#common-pitfalls) 9. [Attachments](#attachments)
10. [Common Pitfalls](#common-pitfalls)
--- ---
@ -163,10 +164,12 @@ export async function getUsersByTags(tags: string[]) {
const adminUsers = await getUsersByTags(["admin", "moderator"]); const adminUsers = await getUsersByTags(["admin", "moderator"]);
``` ```
### Single Select Filtering ### Select Field Filtering
#### Single Select
For single-select fields, the query builder now returns a single string value.
```typescript ```typescript
// For single-select fields (stored as arrays in TaylorDB)
export async function getUsersByRole(role: string) { export async function getUsersByRole(role: string) {
return await queryBuilder return await queryBuilder
.selectFrom("users") .selectFrom("users")
@ -175,6 +178,18 @@ export async function getUsersByRole(role: string) {
} }
``` ```
#### Multi Select
For multi-select fields, the query builder returns and accepts multiple values.
```typescript
export async function getUsersByInterests(interests: string[]) {
return await queryBuilder
.selectFrom("users")
.where("interests", "hasAnyOf", interests)
.execute();
}
```
### Text Search (Contains) ### Text Search (Contains)
```typescript ```typescript
@ -214,6 +229,8 @@ export async function createUser(data: {
### Insert with Single-Select Field ### Insert with Single-Select Field
Single-select fields now accept a single string value directly.
```typescript ```typescript
export async function createTask(data: { export async function createTask(data: {
title: string; title: string;
@ -223,7 +240,7 @@ export async function createTask(data: {
.insertInto("tasks") .insertInto("tasks")
.values({ .values({
title: data.title, title: data.title,
priority: [data.priority], // Wrap in array for single-select priority: data.priority,
}) })
.executeTakeFirst(); .executeTakeFirst();
} }
@ -328,7 +345,7 @@ export async function updateTaskPriority(
) { ) {
return await queryBuilder return await queryBuilder
.update("tasks") .update("tasks")
.set({ priority: [priority] }) // Wrap in array .set({ priority })
.where("id", "=", id) .where("id", "=", id)
.execute(); .execute();
} }
@ -533,15 +550,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"]` | `tags: ["opt1", "opt2"]` | | **Multi Select** | `string[]` | `["opt1", "opt2"]` | `["opt1", "opt2"]` |
| **Email** | `string` | `"user@example.com"` | `"user@example.com"` | | **Attachment** | `string[]` (File Paths) | `uploadAttachments()` | `"file-path"` |
| **Email** | `string` | `"user@example.com"` | `"user@example.com"` |
### Handling Nullable Fields ### Handling Nullable Fields
@ -576,7 +594,7 @@ export async function createTask(data: {
.insertInto("tasks") .insertInto("tasks")
.values({ .values({
title: data.title, title: data.title,
status: [data.status], // Single select as array status: data.status,
}) })
.executeTakeFirst(); .executeTakeFirst();
} }
@ -595,16 +613,6 @@ export async function getTasksByStatus(
## Common Pitfalls ## Common Pitfalls
### ❌ Pitfall 1: Not Wrapping Single-Select in Array
```typescript
// ❌ WRONG
.values({ priority: "high" })
// ✅ CORRECT
.values({ priority: ["high"] })
```
### ❌ Pitfall 2: Not Using exactDay for Dates ### ❌ Pitfall 2: Not Using exactDay for Dates
```typescript ```typescript
@ -689,6 +697,54 @@ const avg = ages.reduce((a, b) => a + b, 0) / ages.length;
--- ---
## Attachments
Attachments are no longer treated as relations. They are now standard columns and can be selected directly.
### Select Attachments
```typescript
// New Standard: Use regular .select() like any other field.
const expenses = await qb
.selectFrom('expenses')
.select(['id', 'amount', 'receipt'])
.execute();
```
### Create with Attachments
Use `qb.uploadAttachments` to upload files before inserting.
```typescript
await qb
.insertInto('customers')
.values({
firstName: 'Jane',
lastName: 'Doe',
avatar: await qb.uploadAttachments([
{ file: new Blob(['']), name: 'test.png' },
]),
})
.execute();
```
### Update with Attachments
```typescript
await qb
.update('customers')
.set({
lastName: 'Smith',
avatar: await qb.uploadAttachments([
{ file: new Blob(['']), name: 'test.png' },
]),
})
.where('id', '=', 1)
.execute();
```
---
## Additional Resources ## Additional Resources
- **Generated Types**: Check `apps/server/taylordb/types.ts` for your schema - **Generated Types**: Check `apps/server/taylordb/types.ts` for your schema