Options
All
  • Public
  • Public/Protected
  • All
Menu

Simple abstraction for MongoDB.

Hierarchy

  • Database

Index

Constructors

constructor

  • Parameters

    • connection: Connection
    • Default value defaultDatabaseName: string = "app"

    Returns Database

Properties

connection

connection: Connection

Protected defaultDatabaseName

defaultDatabaseName: string

Protected rootSession

rootSession: DatabaseSession = new DatabaseSession(this.connection, true)

Methods

add

  • add<T>(item: T): Promise<boolean>
  • Low level: add one item to the database.

    • Populates primary key if necessary.
    • DOES NOT add references automatically. You have to call on each new reference add() in order to save it.
    • DOES NOT update back references.
    • No repository events are triggered.

    You should usually work with DatabaseSession (createSession()) instead, except if you know what you are doing.

    Type parameters

    • T

    Parameters

    • item: T

    Returns Promise<boolean>

close

  • close(force?: undefined | false | true): Promise<void>
  • Parameters

    • Optional force: undefined | false | true

    Returns Promise<void>

createSession

  • Creates a new database session. This is the preferred way of working with the database and enjoy all ORM features. Call DatabaseSession.persist(item) to persist changes.

    All entity instances creating during this session are cached and tracked.

    Returns DatabaseSession

query

  • Creates a new DatabaseQuery instance which can be used to query data.

    • Entity instances ARE NOT cached or tracked.
    • No repository events are triggered.

    Use a DatabaseSession (createSession()) with query() in your workflow to enable instance pooling.

    Type parameters

    • T

    Parameters

    • classType: ClassType<T>

    Returns DatabaseQuery<T>

remove

  • remove<T>(item: T): Promise<boolean>
  • Low level: removes one item from the database that has the given id.

    • DOES NOT remove referenced items. You have to call on each reference delete() in order to remove it.
    • DOES NOT update back references.
    • No repository events are triggered.

    You should usually work with DatabaseSession (createSession()) instead, except if you know what you are doing.

    Type parameters

    • T

    Parameters

    • item: T

    Returns Promise<boolean>

update

  • update<T>(item: T): Promise<boolean>
  • Low level: updates one item in the database.

    • DOES NOT update referenced items. You have to call on each changed reference update() in order to save it.
    • DOES NOT update back references.
    • No repository events are triggered.

    You should usually work with DatabaseSession (createSession()) instead, except if you know what you are doing.

    Type parameters

    • T

    Parameters

    • item: T

    Returns Promise<boolean>

Generated using TypeDoc