Class: EntityTypeBuilder<T>
Defined in: src/model/EntityTypeBuilder.ts:10
Fluent builder for configuring metadata, table names, primary keys, and properties of an entity.
Type Parameters
| Type Parameter |
|---|
T extends object |
Constructors
Constructor
new EntityTypeBuilder<
T>(metadata):EntityTypeBuilder<T>
Defined in: src/model/EntityTypeBuilder.ts:11
Parameters
| Parameter | Type |
|---|---|
metadata | EntityMetadata |
Returns
EntityTypeBuilder<T>
Methods
toTable()
toTable(
tableName,schema?):this
Defined in: src/model/EntityTypeBuilder.ts:25
Configures the database table name and schema for this entity.
Parameters
| Parameter | Type | Description |
|---|---|---|
tableName | string | Name of the database table. |
schema? | string | Optional database schema name (e.g. 'public'). |
Returns
this
this builder instance for chaining.
Usecase
Map the entity to a specific database table name.
Example
b.toTable('users', 'public');
hasKey()
hasKey(
keySelector):this
Defined in: src/model/EntityTypeBuilder.ts:42
Designates a property as the primary key of this entity.
Parameters
| Parameter | Type | Description |
|---|---|---|
keySelector | PropertySelector<T, unknown> | keyof T | Property accessor lambda or property name. |
Returns
this
this builder instance for chaining.
Usecase
Define the primary key property for lookups and joins.
Example
b.hasKey(u => u.id);
property()
property<
R>(propSelector,configure?):PropertyBuilder<T,R>
Defined in: src/model/EntityTypeBuilder.ts:64
Configures an individual property of the entity.
Type Parameters
| Type Parameter |
|---|
R |
Parameters
| Parameter | Type | Description |
|---|---|---|
propSelector | keyof T | PropertySelector<T, R> | Property accessor lambda or property name. |
configure? | (builder) => void | Optional callback for setting property options. |
Returns
PropertyBuilder<T, R>
A PropertyBuilder instance.
Usecase
Customize column names, data types, nullability, or max lengths fluently.
Example
b.property(u => u.email, p => p.hasColumnName('email_addr').isNullable(false));
ignore()
ignore(
propSelector):this
Defined in: src/model/EntityTypeBuilder.ts:84
Ignores a property, excluding it from database mapping and queries.
Parameters
| Parameter | Type | Description |
|---|---|---|
propSelector | PropertySelector<T, unknown> | keyof T | Property accessor lambda or property name. |
Returns
this
this builder instance for chaining.
Usecase
Exclude non-persisted helper properties.
hasSoftDelete()
hasSoftDelete(
columnName?):this
Defined in: src/model/EntityTypeBuilder.ts:98
Configures soft deletion for this entity.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
columnName | string | 'deleted_at' | Name of the soft delete column (defaults to 'deleted_at'). |
Returns
this
this builder instance for chaining.
Usecase
Retain records on deletion by populating a timestamp column.