Skip to main content
Version: Next

EntitySchemaWithMeta <TName, TTableName, TEntity, TBase, TProperties, TClass>

Extended EntitySchema interface that carries additional type-level metadata (entity name, properties, table name). Returned by defineEntity() to provide strong type inference without explicit generics.

Hierarchy

Index

Properties

readonlyname

name: TName

Returns the entity class name.

readonlyproperties

properties: TProperties

readonlytableName

tableName: TTableName

Returns the database table name.

Accessors

inheritedclass

  • get class(): Class
  • Returns Class

inheritedmeta

  • Returns the underlying EntityMetadata.


    Returns EntityMetadata<Entity, Class>

Methods

inheritedaddEmbedded

  • addEmbedded<Target>(name, options): void
  • Adds an embedded property to the entity schema.


    Parameters

    Returns void

inheritedaddEnum

  • addEnum(name, type, options): void
  • Adds an enum property to the entity schema.


    Parameters

    Returns void

inheritedaddHook

  • addHook<T>(event, handler): this
  • 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.

    @example
    export const Article = defineEntity({
    name: 'Article',
    properties: { ... },
    });

    Article.addHook('beforeCreate', async args => {
    args.entity.slug = args.entity.title.toLowerCase();
    });

    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

    inheritedaddIndex

    • addIndex<Key>(options): void
    • Adds an index definition to the entity schema.


      Parameters

      Returns void

    inheritedaddManyToMany

    • addManyToMany<Target>(name, type, options): void
    • Adds a many-to-many relation to the entity schema.


      Parameters

      Returns void

    inheritedaddManyToOne

    • addManyToOne<Target>(name, type, options): void
    • Adds a many-to-one relation to the entity schema.


      Parameters

      Returns void

    inheritedaddOneToMany

    • addOneToMany<Target>(name, type, options): void
    • Adds a one-to-many relation to the entity schema.


      Parameters

      Returns void

    inheritedaddOneToOne

    • addOneToOne<Target>(name, type, options): void
    • Adds a one-to-one relation to the entity schema.


      Parameters

      Returns void

    inheritedaddPrimaryKey

    • addPrimaryKey(name, type, options): void
    • Adds a primary key property to the entity schema.


      Parameters

      Returns void

    inheritedaddProperty

    • addProperty(name, type, options): void
    • Adds a scalar property to the entity schema.


      Parameters

      Returns void

    inheritedaddSerializedPrimaryKey

    • addSerializedPrimaryKey(name, type, options): void
    • Adds a serialized primary key property (e.g. for MongoDB ObjectId).


      Parameters

      Returns void

    inheritedaddUnique

    • addUnique<Key>(options): void
    • Adds a unique constraint definition to the entity schema.


      Parameters

      Returns void

    inheritedaddVersion

    • addVersion(name, type, options): void
    • Adds a version property for optimistic locking.


      Parameters

      Returns void

    inheritednew

    • new(...params): TEntity
    • Parameters

      • rest...params: ConstructorParameters<TClass>

      Returns TEntity

    inheritedsetClass

    • setClass(cls): void
    • Sets or replaces the entity class associated with this schema.


      Parameters

      • cls: TClass

      Returns void

    inheritedsetCustomRepository

    • setCustomRepository(repository): void
    • Sets a custom repository class for this entity.


      Parameters

      Returns void

    inheritedsetExtends

    • setExtends(base): void
    • Sets the base entity that this schema extends.


      Parameters

      Returns void