Skip to main content

EntityMetadata

EntityMetadata is the runtime record @sqb/connect builds for every class touched by @Entity, @Column, @Embedded or any other ORM decorator. It's what Entity.getMetadata() returns, and what every other Entity.* static helper reads from under the hood — see the Defining Models guide for the full list of helpers built on top of it.

interface EntityMetadata {
readonly ctor: Type;
readonly name: string;
tableName?: string;
schema?: string;
comment?: string;
fields: Record<string, AnyFieldMetadata>;
indexes: IndexMetadata[];
foreignKeys: Association[];
eventListeners: Record<string, Function[]>;
}

type AnyFieldMetadata =
| ColumnFieldMetadata
| EmbeddedFieldMetadata
| AssociationFieldMetadata;
FieldTypeDescription
ctorTypeThe decorated class itself.
namestringThe class name (ctor.name) — always mirrors the constructor, regardless of any name passed to EntityOptions (which @Entity never reads).
tableNamestringSet by @Entity — defaults to ctor.name when not given explicitly.
schemastringSet by @Entity({ schema }).
commentstringSet by @Entity({ comment }).
fieldsRecord<string, AnyFieldMetadata>Every @Column/@Embedded/@Link field, keyed by the lower-cased property name.
indexesIndexMetadata[]Every index registered via @Index or @PrimaryKey — at most one entry has primary: true.
foreignKeysAssociation[]Every foreign key registered via @ForeignKey.
eventListenersRecord<string, Function[]>Methods registered via the lifecycle decorators, keyed by event name ('before-insert', 'after-insert', 'before-update', 'after-update', 'before-destroy', 'after-destroy').

AnyFieldMetadata is a union of the three field-kind shapes: ColumnFieldMetadata (a @Column field — see ColumnFieldOptions for its options-only form), EmbeddedFieldMetadata (an @Embedded field), and AssociationFieldMetadata (a @Link field — see AssociationFieldOptions). Every field shape shares a common base carrying kind, entity, name, plus the hidden/exclusive flags described on the options pages above.

note

EntityMetadata is also a namespace of internal helper functions (define, get, mixin, defineColumnField, ...) used by the decorators themselves to build and merge these objects. Application code doesn't normally call them directly — reach for the public Entity.* static helpers instead, which wrap the same data with friendlier, type-checked signatures.