Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Session

The primary interface used to interact with the database. The Session is a Unit of Work that keeps track of changes until they are synchronized with the database by calling flush or close.

Hierarchy

  • Session

Index

Properties

factory

The [SessionFactory] that created this [Session].

Methods

clear

  • Clears the Session, detaching all managed entities.

    Parameters

    • Optional callback: Callback

      Called after the Session has been cleared.

    Returns void

close

  • Flushes any changes to the database and closes the Session. Calling operations on a closed Session will result in an error.

    Parameters

    • Optional callback: Callback

      Called after the Session has been closed.

    Returns void

contains

  • contains(obj: Object): boolean
  • Checks if an entity is contained in the Session.

    Parameters

    • obj: Object

      The entity to check.

    Returns boolean

detach

  • detach(obj: Object, callback?: Callback): void
  • Detaches an entity from the Session making it unmanaged. Any changes to the entity will not be persisted.

    Parameters

    • obj: Object

      The entity to detach.

    • Optional callback: Callback

      Called after the entity has been detached.

    Returns void

exists

  • Check by identifier if an entity exists.

    Type parameters

    • T

    Parameters

    • ctr: Constructor<T>

      The constructor for the entity to find.

    • id: any

      The identifier for the entity.

    • callback: ResultCallback<boolean>

      Called with a boolean indicating if an entity with exists or not. Note that if an entity is pending removal then the value will be false.

    Returns void

fetch

  • Fetches an entity reference from the database.

    Type parameters

    • T

    Parameters

    • obj: T

      The entity reference to fetch.

    • Optional callback: ResultCallback<T>

      Called with the fetched entity.

    Returns void

  • Fetches entity references at the specified path(s) on the given entity.

    Type parameters

    • T

    Parameters

    • obj: T

      The entity

    • path: string | string[]

      The path(s) to check. Uses the same dot notation that MongoDB uses for queries.

    • Optional callback: ResultCallback<T>

      Called after any entity references have been fetched.

    Returns void

find

  • Finds an entity by identifier.

    Type parameters

    • T

    Parameters

    • ctr: Constructor<T>

      The constructor for the entity to find.

    • id: any

      The identifier for the entity.

    • Optional callback: ResultCallback<T>

      Called with the entity.

    Returns FindOneQuery<T>

flush

  • Synchronizes the Session with the database, writing any changes.

    Parameters

    • Optional callback: Callback

      Called after the changes have been written to the database.

    Returns void

getReference

  • Gets a reference to an entity without making a request to the database.

    Type parameters

    • T

    Parameters

    • ctr: Constructor<T>

      The constructor for the entity.

    • id: any

      The identifier for the entity.

    Returns T

getVersion

  • getVersion(obj: Object): number
  • Gets the version number of an entity. Returns null if the version cannot be determined.

    Parameters

    • obj: Object

      The entity to get the version for.

    Returns number

on

  • on(event: string, listener: Function): EventEmitter
  • Adds an event listener.

    Parameters

    • event: string

      The event to listen for.

    • listener: Function

      The listener function.

    Returns EventEmitter

query

refresh

  • refresh(obj: Object, callback: Callback): void
  • Refreshes an entity state from database. Any changes to the entity are discarded.

    Parameters

    • obj: Object

      The entity to refresh.

    • callback: Callback

      Called after the entity has been refreshed.

    Returns void

remove

  • remove(obj: Object, callback?: Callback): void
  • Removes an entity from the Session. The entity is not actually removed from the database util the Session is flushed.

    Parameters

    • obj: Object

      The entity to remove.

    • Optional callback: Callback

      Called after the entity has been removed from the Session.

    Returns void

save

  • save(obj: Object, callback?: Callback): void
  • Saves an entity to the Session. If the entity is new then it becomes managed. If the entity is already managed then it is flagged for dirty check. The entity is not actually saved to the database until the Session is flushed.

    Parameters

    • obj: Object

      The entity to save.

    • Optional callback: Callback

      Called after the entity has been added to the Session.

    Returns void

toDocument

  • Converts an entity to a document, the same document that is stored in the database. The document is suitable for serialization to JSON.

    Parameters

    • obj: Object

      The entity to convert to a document.

    • Optional callback: ResultCallback<Object>

      Optional callback is called with serialized document. If callback is provided, any errors encountered during writing the document are passed to the callback. If a callback is not provided and errors are encountered during writing the document, null is returned.

    Returns Object

wait

  • Waits for pending operations on the Session to complete.

    Parameters

    • Optional callback: Callback

      Called after all pending operations on the Session have completed.

    Returns void

Generated using TypeDoc