Enums and constants
Read this page in the documentation
Enums and constants Where an option's value must be one of a handful of words, there is an enum for it. An enum autocompletes, survives a rename, and cannot be 'FORIEGN KEY' — a typo a string union catches only if you spelled the type correctly too. Note: this page is about the TypeScript vocabulary — the values you pass to the ORM. For the SQL statements that change session behaviour — PRAGMA, sqlmode, searchpath, isolation level as a statement — see SQL constants. Note: every field still accepts the plain string. The enums are string-valued and the option types were widened rather than replaced, so { type: 'UNIQUE' } and { type: ConstraintType.Unique } are the same value. Existing code needs no change, and the two spellings mix freely. Schema ConstraintType Member | SQL | Means | --- | --- | --- | PrimaryKey | PRIMARY KEY | The row's identity. One per table, never null. | Unique | UNIQUE | No two rows share these values. Nulls are exempt on most engines. | ForeignKey | FOREIGN KEY | The value must exist in another table. | Check | CHECK | A predicate every row must satisfy. | Exclude | EXCLUDE | No two rows overlap on the given operators — the general form of UNIQUE. | Exclude is PostgreSQL-only. Fields on engines that cannot emit it take TableConstraintTypeLike, the same enum without that member, so asking MySQL for an exclusion constraint is a type error rather than SQL the driver rejects. Note: this enum reconciles two definitions that disagreed — models/constraints.ts included EXCLUDE and models/indexes.ts did not, so which members were legal depended on which module you imported the type from. ReferentialAction What happens to referencing rows when the row they point at changes. Member | Means | --- | --- | Cascade | Apply the same change — delete the referencing rows, or follow the new key. The convenient one, and the one that silently removes data. | Restrict | Refuse immediately, before other constraints are considered. | SetNull | Null the referencing column. It must allow null. | NoAction | Refuse, but only at end of statement — so a deferred constraint can still be satisfied by a later row. The SQL default. | SetDefault | Set the referencing column to its column default. | Restrict and NoAction differ only in when the check runs. That matters exactly once: with a deferred constraint, NoAction lets a transaction fix itself before committing and Restrict does not. Deferrable When a constraint is checked. Member | Means | --- | --- | InitiallyDeferred | At the end of the transaction. Lets you insert rows that reference each other. | InitiallyImmediate | Per statement, but can be deferred within a transaction. | NotDeferrable | Per statement, always. | IndexMethod Member | Good for | Where | --- | --- | --- | BTree | Equality, ranges, sorting, prefixes | Everywhere; the default | Hash | Equality only, smaller than a B-tree for it | PostgreSQL, MySQL (MEMORY) | Gin | Arrays, JSONB, full-text | PostgreSQL | Gist | Geometric and range types | PostgreSQL | SpGist | Data dividing into non-overlapping regions — points, text prefixes | PostgreSQL | Brin | Very large, naturally ordered tables; tiny indexes | PostgreSQL | PartitionKind Member | Divides by | --- | --- | Range | A contiguous span of values. The usual choice for dates. | List | An explicit set of values per partition. | Hash | A hash of the key — even distribution rather than meaning. | Queries SortDirection ASC and DESC. Worth knowing: null placement differs by engine — nulls sort first on PostgreSQL and last on MySQL under ASC, and the placement inverts with the direction. Use NullsOrder when it matters. JoinType Member | Keeps | --- | --- | Inner | Only rows matching on both sides. The default. | Left | Every row from the left, nulls where the right has no match. | Right | Every row from the right. A Left join with the sides swapped. | Full | Every row from both. Not supported by MySQL. | Cross | Every combination — left × right rows. Rarely intended. | AssociationType Member | Foreign key lives on | --- | --- | HasOne | the other table | HasMany | the other table | BelongsTo | this table | BelongsToMany | a join table | If you are unsure which to use, the question is only ever "which table holds the column?" — that table is the one that BelongsTo. Transactions IsolationLevel Member | Guarantees | --- | --- | ReadUncommitted | Nothing; reads can see uncommitted changes. PostgreSQL accepts it and silently gives you ReadCommitted. | ReadCommitted | Each statement sees committed data — but two statements in one transaction can see different data. PostgreSQL's default. | RepeatableRead | Every read sees one snapshot. MySQL's default. Does not rule out phantoms on every engine. | Serializable | As if transactions ran one at a time. The only level that rules out write skew. | Warning: Serializable makes serialisation failures a normal outcome, not an error condition. Code using it must retry the transaction rather than surface the failure. LockLevel Member | Blocks | --- | --- | KeyShare | Only changes to the key itself — rows referencing this one can still be inserted. | Share | Writers. Other readers are fine. | NoKeyUpdate | Other writers, but not KeyShare readers. | Update | Everything else. | Listed weakest to strongest. A foreign key check takes KeyShare implicitly, which is why SELECT … FOR UPDATE on a parent row can block inserts into a child table. Schema objects TriggerTiming, TriggerEvent, TriggerForEach Covered with the rest of the trigger API in Schema objects. TriggerEvent.Truncate is PostgreSQL-only and statement-level by definition. ParamMode, Volatility, RoutineLanguage For procedures and functions. Volatility names two families that are not interchangeable: PostgreSQL takes Immutable / Stable / Volatile, MySQL takes Deterministic / NotDeterministic. Naming them in one enum makes picking the wrong one visible at the call site. SqlCommand ALL, SELECT, INSERT, UPDATE, DELETE — for grants and row-level security policies. On a policy, Insert is checked with withCheck rather than using, because there is no existing row to test. Diagrams DiagramType names all fifteen generators, so a diagram can be chosen from a CLI flag or a config file. See From your models to a diagram. Importing them All of them come from the package root: Each also has a …Like type — ConstraintTypeLike, ReferentialActionLike and so on — which is the enum plus its string values. Option types use those, which is what keeps the plain strings working. Related reading Schema objects — where most of these are used Query operators — the where vocabulary Transactions — isolation levels in practice Indexes & constraints SQL constants — the session statements, which these are not