EntitySchema <Entity, Base, Class>
Hierarchy
- EntitySchema
Index
Constructors
constructor
Parameters
meta: EntitySchemaMetadata<Entity, Base, Class>
Returns EntitySchema<Entity, Base, Class>
Properties
staticREGISTRY
When schema links the entity class via class option, this registry allows the lookup from opposite side,
so we can use the class in entities option just like the EntitySchema instance.
Accessors
class
Returns Class
meta
Returns the underlying EntityMetadata.
Returns EntityMetadata<Entity, Class>
name
Returns the entity class name.
Returns string | EntityName<Entity>
properties
Returns Record<string, any>
tableName
Returns the database table name.
Returns string
Methods
addEmbedded
Adds an embedded property to the entity schema.
Parameters
name: EntityKey<Entity>
options: EmbeddedOptions<Entity, Target>
Returns void
addEnum
Adds an enum property to the entity schema.
Parameters
name: EntityKey<Entity>
optionaltype: TypeType
options: EnumOptions<Entity> = {}
Returns void
addHook
Adds a lifecycle hook handler to the entity schema. This method allows registering hooks after the entity is defined, which can be useful for avoiding circular type references.
Parameters
event: EventType | onInit | onLoad | beforeCreate | afterCreate | beforeUpdate | afterUpdate | beforeUpsert | afterUpsert | beforeDelete | afterDelete | beforeFlush | onFlush | afterFlush | beforeTransactionStart | afterTransactionStart | beforeTransactionCommit | afterTransactionCommit | beforeTransactionRollback | afterTransactionRollback
handler: (args) => void | Promise<void>
Returns this
addIndex
Adds an index definition to the entity schema.
Parameters
options: IndexOptions<Entity, Key>
Returns void
addManyToMany
Adds a many-to-many relation to the entity schema.
Parameters
name: EntityKey<Entity>
type: TypeType
options: ManyToManyOptions<Entity, Target>
Returns void
addManyToOne
Adds a many-to-one relation to the entity schema.
Parameters
name: EntityKey<Entity>
type: TypeType
options: ManyToOneOptions<Entity, Target>
Returns void
addOneToMany
Adds a one-to-many relation to the entity schema.
Parameters
name: EntityKey<Entity>
type: TypeType
options: OneToManyOptions<Entity, Target>
Returns void
addOneToOne
Adds a one-to-one relation to the entity schema.
Parameters
name: EntityKey<Entity>
type: TypeType
options: OneToOneOptions<Entity, Target>
Returns void
addPrimaryKey
Adds a primary key property to the entity schema.
Parameters
name: EntityKey<Entity>
type: TypeType
options: PrimaryKeyOptions<Entity> = {}
Returns void
addProperty
Adds a scalar property to the entity schema.
Parameters
name: EntityKey<Entity>
optionaltype: TypeType
options: PropertyOptions<Entity> | EntityProperty<Entity, any> = {}
Returns void
addSerializedPrimaryKey
Adds a serialized primary key property (e.g. for MongoDB ObjectId).
Parameters
name: EntityKey<Entity>
type: TypeType
options: SerializedPrimaryKeyOptions<Entity> = {}
Returns void
addUnique
Adds a unique constraint definition to the entity schema.
Parameters
options: UniqueOptions<Entity, Key>
Returns void
addVersion
Adds a version property for optimistic locking.
Parameters
name: EntityKey<Entity>
type: TypeType
options: PropertyOptions<Entity> = {}
Returns void
new
Parameters
rest...params: ConstructorParameters<Class>
Returns Entity
setClass
Sets or replaces the entity class associated with this schema.
Parameters
cls: Class
Returns void
setCustomRepository
Sets a custom repository class for this entity.
Parameters
repository: () => Constructor
Returns void
setExtends
Sets the base entity that this schema extends.
Parameters
base: EntityName
Returns void
staticfromMetadata
Creates an EntitySchema from existing EntityMetadata (used internally).
Parameters
meta: EntityMetadata<T, EntityCtor<T>> | DeepPartial<EntityMetadata<T, EntityCtor<T>>>
Returns EntitySchema<T, U, EntityCtor<T>>
staticis
Checks if the given value is an EntitySchema instance, using duck-typing as a fallback when
instanceoffails due to CJS/ESM dual-package hazard (e.g. when usingtsxor@swc-node/registerwith"type": "commonjs"projects).Parameters
item: unknown
Returns item is EntitySchema<any, never, EntityCtor<any>>
Class-less entity definition that provides a programmatic API for defining entities without decorators.