Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BaseModel

Exports [[#BaseModel]] class

memberof

cormo

Hierarchy

  • BaseModel

Index

Constructors

Properties

_attributes?: any
_intermediates?: any
_is_persisted?: any
_prev_attributes?: any
id?: any
_adapter: AdapterBase

Indicates the adapter associated to this model

_associations: {}

Type declaration

  • [column: string]: any
_callbacks_map: { create: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]; destroy: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]; find: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]; initialize: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]; save: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]; update: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]; validate: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[] }

Type declaration

  • create: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]
  • destroy: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]
  • find: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]
  • initialize: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]
  • save: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]
  • update: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]
  • validate: undefined | { method: ModelCallbackMethod; type: ModelCallbackType }[]
_connection: Connection<AdapterBase>

Indicates the connection associated to this model

_initialize_called: boolean = false
_integrities: { child?: typeof BaseModel; column: string; parent?: typeof BaseModel; type: string }[]
_intermediate_paths: any
_name: string
_object_column_classes: { column: string; klass: any }[]
_property_decorators: any[]
_schema: ModelSchemaInternal
_validators: any[]
archive: boolean = false

Archives deleted records in the archive table

description?: string
dirty_tracking: boolean = false

Tracks changes of a record if true

lean_query: boolean = false

Applies the lean option for all queries for this Model

table_name: string

Methods

  • _buildSaveData(): any
  • _create(options: { skip_log?: boolean; transaction?: Transaction }): Promise<{}>
  • _defineProperty(object: any, key: any, path: any, enumerable: any): void
  • _runCallbacks(name: ModelCallbackName, type: ModelCallbackType): void
  • _update(options: { skip_log?: boolean; transaction?: Transaction }): Promise<undefined | {}>
  • destroy(): Promise<void>
  • get(path: any): any
  • getChanged(): string[]
  • getPrevious(path: any): any
  • isDirty(): boolean
  • reset(): void
  • save(options?: { skip_log?: boolean; transaction?: Transaction; validate?: boolean }): Promise<BaseModel>
  • set(path: any, value: any): void
  • validate(): void
  • [custom](depth: number): string
  • _buildSaveDataColumn(data: any, model: any, column: string, property: ColumnPropertyInternal, allow_null?: boolean): void
  • _checkConnection(): void
  • _checkReady(): Promise<void>
  • _collapseNestedNulls(instance: any, selected_columns_raw: any, intermediates: any): void
  • _createBulk(records: any[], options?: { transaction?: Transaction }): Promise<any[]>
  • _getKeyType(target_connection?: Connection<AdapterBase>): any
  • _loadFromCache(key: string, refresh?: boolean): Promise<any>
  • _saveToCache(key: string, ttl: number, data: any): Promise<void>
  • _validateColumn(data: any, column: string, property: ColumnPropertyInternal, for_update?: boolean): void
  • _validateType(column: any, type_class: any, value: any): any
  • addCallback(type: ModelCallbackType, name: ModelCallbackName, method: ModelCallbackMethod): undefined | number
  • addValidator(validator: any): void
  • Adds a validator A validator must return false(boolean) or error message(string), or throw an Error exception if invalid

    Parameters

    • validator: any

    Returns void

  • afterCreate(method: ModelCallbackMethod): void
  • afterDestroy(method: ModelCallbackMethod): void
  • afterFind(method: ModelCallbackMethod): void
  • afterInitialize(method: ModelCallbackMethod): void
  • afterSave(method: ModelCallbackMethod): void
  • afterUpdate(method: ModelCallbackMethod): void
  • afterValidate(method: ModelCallbackMethod): void
  • applyDefaultValues(obj: any): string[]
  • beforeCreate(method: ModelCallbackMethod): void
  • beforeDestroy(method: ModelCallbackMethod): void
  • beforeSave(method: ModelCallbackMethod): void
  • beforeUpdate(method: ModelCallbackMethod): void
  • beforeValidate(method: ModelCallbackMethod): void
  • belongsTo(target_model_or_column: string | typeof BaseModel, options?: AssociationBelongsToOptions): void
  • column(path: string, type_or_property: ColumnType | ColumnType[] | ColumnProperty | ColumnNestedProperty): void
  • connection(connection: Connection<AdapterBase>, name?: string): void
  • Sets a connection of this model

    If this methods was not called explicitly, this model will use Connection.defaultConnection

    Parameters

    • connection: Connection<AdapterBase>
    • Optional name: string

    Returns void

  • count(condition?: object, options?: { transaction?: Transaction }): Promise<number>
  • delete(condition?: object, options?: { transaction?: Transaction }): Promise<number>
  • deleteAll(): Promise<void>
  • drop(): Promise<void>
  • group<M, G, F>(group_by: G | G[], fields?: F, options?: { transaction?: Transaction }): QueryArray<M, { [ field in string | number | symbol]: number } & Pick<M, G>>
  • group<M, F>(group_by: null, fields?: F, options?: { transaction?: Transaction }): QueryArray<M, { [ field in string | number | symbol]: number }>
  • group<M, U>(group_by: null | string, fields?: object, options?: { transaction?: Transaction }): QueryArray<M, U>
  • hasMany(target_model_or_column: string | typeof BaseModel, options?: AssociationHasManyOptions): void
  • hasOne(target_model_or_column: string | typeof BaseModel, options?: AssociationHasOneOptions): void
  • index(columns: {}, options?: { name?: string; unique?: boolean }): void
  • Adds an index to this model

    Parameters

    • columns: {}
      • [column: string]: 1 | -1
    • options: { name?: string; unique?: boolean } = {}
      • Optional name?: string
      • Optional unique?: boolean

    Returns void

  • initialize(): void
  • newModel(connection: Connection<AdapterBase>, name: string, schema: ModelSchema): typeof BaseModel
  • removeCache(key: string): Promise<void>
  • timestamps(): void
  • update(updates: any, condition?: object, options?: { transaction?: Transaction }): Promise<number>

Generated using TypeDoc