Overview

table() stores the columns. The key comes first, then each data type, then the options.

table()Anatomy
export const notes = table(
"notes",name
{
id: t.identity(),key
title: t.text(),type
published: t.boolean().default(false),after the type
},
{ … },options
);

Name

An empty name is refused.

Columns

The key comes first. Each other field is a data type. Defaults, names, and checks come after the type.

Options

Keys, indexes, checks, and the pages below. schema() builds the catalog.

One builder

t is every builder. Import one builder when a file uses only that type.

The declaration

The list is how often you reach for each part while building. Columns, keys, and the calls come first.

notes.ts
import { index, table, t } from "okmodel/pg";

export const notes = table(
  "notes",
  {
    id: t.identity(), 
    title: t.text(),
    published: t.boolean().default(false),
  },
  { indexes: (columns) => [index(columns.title)] }, 
);
OrderPageYou use it for
1ColumnsThe builder for each value.
2KeysThe primary key, and a unique.
3DefaultsWhat fills a column you omit.
4ReferencesA foreign key.
5RelationsThe edge you query.
6QueriesThe calls on the table.
7TraitsShared columns, including timestamps and archive.
8IndexesAn extra index.
9ValidationThe rule that rejects a bad value.
10ShapeAn array, a picklist, or an enum.
11FiltersWhat a caller may send.
12PresetsA named where.
13TenancyThe schema key, global, or a path.
14NamesThe SQL name, a previous name, and a comment.
15VisibilityHidden, sensitive, and guarded.
16ChecksSQL the row must pass.
17Required rowsRows the application expects, inserted when the key is missing.

On this page