Skip to main content
Version: Next

EntitySchema <Entity, Base, Class>

Hierarchy

Index

Constructors

constructor

  • new EntitySchema<Entity, Base, Class>(meta): EntitySchema<Entity, Base, Class>

Properties

staticREGISTRY

REGISTRY: Map<Partial<any>, EntitySchema<any, never, EntityCtor<any>>> = ...

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

  • get class(): Class
  • Returns Class

meta

name

properties

  • get properties(): Record<string, any>
  • Returns Record<string, any>

tableName

  • get tableName(): string
  • Returns string

Methods

addEmbedded

  • addEmbedded<Target>(name, options): void

addEnum

  • addEnum(name, type, options): void
  • Parameters

    Returns void

addHook

  • addHook<Event>(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

    Returns this

addIndex

  • addIndex<Key>(options): void

addManyToMany

  • addManyToMany<Target>(name, type, options): void

addManyToOne

  • addManyToOne<Target>(name, type, options): void

addOneToMany

  • addOneToMany<Target>(name, type, options): void

addOneToOne

  • addOneToOne<Target>(name, type, options): void

addPrimaryKey

  • addPrimaryKey(name, type, options): void

addProperty

  • addProperty(name, type, options): void

addSerializedPrimaryKey

  • addSerializedPrimaryKey(name, type, options): void

addUnique

  • addUnique<Key>(options): void

addVersion

  • addVersion(name, type, options): void

new

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

    • rest...params: ConstructorParameters<Class>

    Returns Entity

setClass

  • setClass(cls): void
  • Parameters

    • cls: Class

    Returns void

setCustomRepository

  • setCustomRepository(repository): void

setExtends

  • setExtends(base): void

staticfromMetadata