Skip to content

ForeignKeyBuilder ​

Parameters ​

NameDescription
columnLocal column name for the foreign key.
foreignKeysArray to collect ForeignKeyDefinition entries.

Example ​

typescript
const foreignKeys: ForeignKeyDefinition[] = [];
new ForeignKeyBuilder("user_id", foreignKeys)
  .references("id")
  .on("users")
  .onDelete("cascade")
  .onUpdate("restrict");
// foreignKeys now contains:
// [{ column: "user_id", references: { table: "users", column: "id" }, onDelete: "cascade", onUpdate: "restrict" }]

ForeignKeyBuilder ​

Fluent builder for constructing foreign key constraints in migrations. Chain methods to define column references and actions.

references ​

Specify the referenced column in the related table.

Parameters ​

NameDescription
columnColumn name in the foreign table.

returns — The builder instance for chaining.

on ​

Specify the referenced table for the foreign key.

Parameters ​

NameDescription
tableTable name to reference.

returns — The builder instance for chaining.

onDelete ​

Define the ON DELETE action for the foreign key.

Parameters ​

NameDescription
actionOne of 'cascade', 'set null', or 'restrict'.

returns — The builder instance for chaining.

onUpdate ​

Define the ON UPDATE action for the foreign key.

Parameters ​

NameDescription
actionOne of 'cascade', 'set null', or 'restrict'.

returns — The builder instance for chaining.

Released under the MIT License.