Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Model<T>

Model is essentialy a set of fields and functions that is used in Datastore.

It contains .meta field, that contains the identifier of an object, etc.

Usage

export class Human extends Model<Human> {
  name: string;

  constructor(name: string) {
    super()
    this.name = name
  }
}

Type parameters

  • T: Model<T>

    The object that extends the model.

Hierarchy

  • Model

Index

Constructors

constructor

  • new Model(data?: object): Model
  • Creates an instance of Model.

    memberof

    Model

    Parameters

    • Optional data: object

      Optional data to pass.

      • Optional id?: string
      • Optional store?: Datastore<T>

    Returns Model

Properties

meta

Meta contains the 'metadata' fields of an object. This includes the identifier, creation time and last updated time.

Private store

store: Datastore<any>

Datastore object that handles this model.

Methods

delete

  • delete(): void
  • Deletes the object via Datastore. You have to make sure that this.store is not null.

    Returns void

save

  • save(): Promise<void>
  • Saves the object via Datastore. You have to make sure that this.store is not null.

    If the object already has this.meta.id set, it will update the object in the database under this.meta.id. Otherwise, if the identifier not set, it will create a new object in the database and set the this.meta field.

    Returns Promise<void>

setCreatedTime

  • setCreatedTime(time: number): void
  • Sets the creation time of an object.

    Parameters

    • time: number

      UNIX timestamp of the time.

    Returns void

setData

  • setData(data: object): void
  • Sets the fields that are required by Datastore.

    Parameters

    • data: object

      Identifier of an object and the Datastore object.

    Returns void

setDb

setUpdatedTime

  • setUpdatedTime(time: number): void
  • Sets the last updated time of an object.

    Parameters

    • time: number

      UNIX timestamp of the time.

    Returns void

Generated using TypeDoc