Skip to main content
Puri maximizes TypeScript’s type system to catch SQL query errors at compile time.

Type Safety Overview

Automatic Type Inference

Query result types auto-inferred Compile-time validation

Column Autocomplete

IDE autocomplete support Prevent typos

JOIN Type Inference

Auto-expanded types after join LEFT JOIN nullable

Raw Function Types

Raw SQL is also type-safe Explicit return types

Basic Type Inference

SELECT Type Inference

WHERE Type Validation

JOIN Type Extension

INNER JOIN

LEFT JOIN - nullable Types

LEFT JOIN type safety:
  • INNER JOIN: Value always exists → T
  • LEFT JOIN: Value may not exist → T | null
TypeScript automatically enforces null checks.

Column Autocomplete

IDE Autocomplete

Prevent Invalid Columns

Raw Function Type Safety

Explicit Type Specification

Aggregate Function Types

first() Types

first() returns a single result or undefined.

pluck() Types

Type-safe Parameters

Params Type Definition

Using in API Methods

Subquery Types

Practical Examples

Type-safe Search Filter

Using Generics

Type Guards

Narrowing Result Types

Next Steps

Advanced Patterns

Learn advanced patterns

Basic Queries

Back to basic queries

Joins

Type safety in joins

Model

Using Puri in Models