Skip to main content

Type Signature

Overview

Insertable<T> is a utility type that extracts the insert type from all columns in a table interface. It resolves the InsertType from any ColumnType definitions and creates a type representing what you can insert into the table.

Type Parameters

R
interface
required
A table interface with column definitions.

Behavior

  • Extracts the second type parameter (InsertType) from each ColumnType<SelectType, InsertType, UpdateType>
  • For regular types without ColumnType, uses the type as-is
  • Fields with nullable insert types (can be undefined or null) become optional
  • Fields with non-nullable insert types remain required
  • Excludes columns where InsertType is never

Examples

Basic Usage

Notice:
  • id is optional (because Generated<number> allows undefined for inserts)
  • created_at is a string (not Date) for inserts
  • first_name and last_name are required strings

Using with Insert Queries

With GeneratedAlways Columns

Optional vs Required Fields

Different Types for Insert

Common Patterns

Function Parameters

Bulk Inserts

Combining with Selectable

Partial Insertable with Pick

Source

View source on GitHub