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;
| Field | Type | Description |
|---|---|---|
ctor | Type | The decorated class itself. |
name | string | The class name (ctor.name) — always mirrors the constructor, regardless of any name passed to EntityOptions (which @Entity never reads). |
tableName | string | Set by @Entity — defaults to ctor.name when not given explicitly. |
schema | string | Set by @Entity({ schema }). |
comment | string | Set by @Entity({ comment }). |
fields | Record<string, AnyFieldMetadata> | Every @Column/@Embedded/@Link field, keyed by the lower-cased property name. |
indexes | IndexMetadata[] | Every index registered via @Index or @PrimaryKey — at most one entry has primary: true. |
foreignKeys | Association[] | Every foreign key registered via @ForeignKey. |
eventListeners | Record<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.
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.