Skip to main content

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​

ParameterType
metadataEntityMetadata

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​

ParameterTypeDescription
tableNamestringName of the database table.
schema?stringOptional 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​

ParameterTypeDescription
keySelectorPropertySelector<T, unknown> | keyof TProperty 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​

ParameterTypeDescription
propSelectorkeyof T | PropertySelector<T, R>Property accessor lambda or property name.
configure?(builder) => voidOptional 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​

ParameterTypeDescription
propSelectorPropertySelector<T, unknown> | keyof TProperty 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​

ParameterTypeDefault valueDescription
columnNamestring'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.


hasQueryFilter()​

hasQueryFilter(filter): this

Defined in: src/model/EntityTypeBuilder.ts:114

Attaches a global query filter to this entity type (e.g. multi-tenant isolation).

Parameters​

ParameterTypeDescription
filter(clause) => void | WhereClause<T>Function receiving a WhereClause builder.

Returns​

this

this builder instance for chaining.

Usecase​

Multi-tenant data filtering or automatic status filtering across all queries on this entity.

Example​

b.hasQueryFilter(w => w.eq('isArchived', false));