Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tailor-platform/sdk/llms.txt

Use this file to discover all available pages before exploring further.

TailorDB provides a comprehensive set of field types for defining your data schema. All fields are type-safe and automatically validated.

Basic Field Types

db.string()
db.string({ optional: true })
db.string({ array: true })
String field mapped to TypeScript string.

Date and Time Fields

db.date()
db.date({ optional: true })
Date-only field (no time component).Format: "yyyy-MM-dd" (e.g., "2024-03-15")TypeScript Type: string

Special Field Types

UUID

db.uuid()
db.uuid({ optional: true })
Universally unique identifier field. Commonly used for foreign keys. Format: Standard UUID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" TypeScript Type: string

Enum

Enum fields restrict values to a predefined set of strings:
// Simple enum
db.enum(["red", "green", "blue"])

// With descriptions
db.enum([
  { value: "active", description: "Active status" },
  { value: "inactive", description: "Inactive status" },
])

// Optional enum
db.enum(["MANAGER", "STAFF"], { optional: true })
Example from source:
export const user = db.type("User", {
  role: db.enum(["MANAGER", "STAFF"]),
  status: db.string({ optional: true }),
});

export const supplier = db.type("Supplier", {
  state: db.enum(["Alabama", "Alaska"]),
});

Object (Nested Fields)

Define structured nested objects with typed fields:
db.object({
  street: db.string(),
  city: db.string(),
  country: db.string(),
})

// Optional object
db.object({
  name: db.string(),
  age: db.int({ optional: true }),
}, { optional: true })

// Array of objects
db.object({
  id: db.uuid(),
  name: db.string(),
}, { array: true })
Example from source:
export const attachedFiles = db.object(
  {
    id: db.uuid(),
    name: db.string(),
    size: db.int().validate(({ value }) => value > 0),
    type: db.enum(["text", "image"]),
  },
  { array: true },
);

export const nestedProfile = db.type("NestedProfile", {
  userInfo: db
    .object({
      name: db.string().description("User's full name"),
      age: db.int({ optional: true }).description("User's age"),
      bio: db.string({ optional: true }).description("User's biography"),
      email: db.string().description("User's email address"),
      phone: db.string({ optional: true }).description("User's phone number"),
    })
    .description("User information"),
  metadata: db
    .object({
      created: db.datetime().description("Creation timestamp"),
      lastUpdated: db.datetime({ optional: true }).description("Last update timestamp"),
      version: db.int().description("Version number"),
    })
    .description("Profile metadata"),
});

Decimal

High-precision decimal numbers stored as strings:
db.decimal()
db.decimal({ scale: 2 }) // 2 decimal places
db.decimal({ scale: 4, optional: true }) // 4 decimal places, optional
Parameters:
  • scale: Integer between 0 and 12 specifying decimal places
TypeScript Type: string

Field Options

All field types accept these options:
optional
boolean
default:false
If true, the field can be null or undefined.
array
boolean
default:false
If true, the field accepts an array of values.
db.string({ optional: true })
db.string({ array: true })
db.string({ optional: true, array: true }) // Optional array of strings
db.int({ optional: true })
db.uuid({ array: true })

Field Modifiers

Field modifiers are chained methods that add additional behavior to fields.

Description

Add documentation to a field:
db.string().description("User's full name")
db.int().description("Age in years")

Index

Create a database index on the field for faster queries:
db.string().index()
db.enum(["MANAGER", "STAFF"]).index()
Note: Cannot be used on array fields.

Unique

Enforce uniqueness constraint (automatically adds an index):
db.string().unique()
db.int().unique()
Example:
export const user = db.type("User", {
  name: db.string(),
  email: db.string().unique(), // Email must be unique
});
Enable vector search on string fields:
db.string().vector()
Note: Only available on non-array string fields.

Serial / Auto-increment

Generate auto-incrementing values:
// Integer serial
db.int().serial({
  start: 1,
  maxValue: 999999,
})

// String serial with format
db.string().serial({
  start: 1000,
  format: "INV-%05d", // Generates INV-01000, INV-01001, etc.
})
Example from source:
export const invoice = db.type("Invoice", {
  invoiceNumber: db.string().serial({
    start: 1000,
    format: "INV-%05d",
  }),
  sequentialId: db.int().serial({
    start: 1,
    maxValue: 999999,
  }),
});

Common Field Patterns

Timestamps

Use db.fields.timestamps() to add standard createdAt and updatedAt fields:
export const user = db.type("User", {
  name: db.string(),
  email: db.string(),
  ...db.fields.timestamps(),
});
This expands to:
{
  createdAt: db.datetime()
    .hooks({ create: () => new Date() })
    .description("Record creation timestamp"),
  updatedAt: db.datetime({ optional: true })
    .hooks({ update: () => new Date() })
    .description("Record last update timestamp"),
}

Validation

Add validation rules to fields:
// Single validator (function form)
db.int().validate(({ value }) => value >= 0)

// Multiple validators with error messages (recommended)
db.string().validate(
  ({ value }) => value.includes("@"),
  [({ value }) => value.length >= 5, "Email must be at least 5 characters"],
)

// Nested field validation
db.object({
  size: db.int().validate(({ value }) => value > 0),
})
Example from source:
export const customer = db.type("Customer", {
  city: db.string({ optional: true }).validate(
    ({ value }) => (value ? value.length > 1 : true),
    ({ value }) => (value ? value.length < 100 : true),
  ),
});

Hooks

Execute functions during create or update operations:
// Field-level hooks
db.string().hooks({
  create: ({ user }) => user.id,
  update: ({ value }) => value,
})

db.datetime().hooks({
  create: () => new Date(),
  update: () => new Date(),
})
Hook arguments:
  • value: User input if provided, otherwise existing value (update) or null (create)
  • data: Entire record data (for accessing other fields)
  • user: User performing the operation
Note: For type-safe access to other fields, use type-level hooks instead (see db.type()).

Field Type Reference

MethodTailorDB TypeTypeScript TypeNotes
db.string()Stringstring
db.int()IntegernumberWhole numbers only
db.float()FloatnumberDecimal numbers
db.bool()Booleanboolean
db.date()DatestringFormat: yyyy-MM-dd
db.datetime()DateTimestring | DateISO 8601 format
db.time()TimestringFormat: HH:mm
db.uuid()UUIDstringStandard UUID format
db.decimal()DecimalstringHigh-precision decimals
db.enum()EnumstringRestricted values
db.object()NestedobjectStructured data

See Also

Build docs developers (and LLMs) love