Type Parameters

  • T

Hierarchy

  • EventEmitter
    • default

Constructors

Properties

Document: any
Query: any
_database: default
_mutex: default = ...
data: Record<PropertyKey, T> = {}
each: ((iterator, options?) => void)

Type declaration

    • (iterator, options?): void
    • Iterates over all documents.

      Parameters

      • iterator: ((value, index) => void)
          • (value, index): void
          • Parameters

            • value: any
            • index: number

            Returns void

      • Optional options: Options

        See Model#findById.

      Returns void

get: ((id, options_?) => T | default<T>)

Type declaration

    • (id, options_?): T | default<T>
    • Finds a document by its identifier.

      Parameters

      • id: PropertyKey
      • Optional options_: Options

      Returns T | default<T>

length: number = 0
name: string

Model name

random: (() => default<T>)

Type declaration

schema: default
size: (() => number)

Type declaration

    • (): number
    • Returns the number of elements.

      Returns number

Methods

  • Private

    Acquires write lock.

    Returns Disposer<void>

  • Private

    Exports data.

    Returns string

  • Private

    Imports data.

    Parameters

    • arr: any[]

    Returns void

  • Private

    Inserts a document.

    Parameters

    Returns Bluebird<any>

  • Private

    Returns a getter function for normal population.

    Parameters

    • data: string | number
    • model: default<T>
    • options: unknown

    Returns (() => default<T> | Record<PropertyKey, any>)

      • (): default<T> | Record<PropertyKey, any>
      • Returns default<T> | Record<PropertyKey, any>

  • Private

    Finds a document by its identifier and remove it.

    Parameters

    • id: string | number

    Returns Bluebird<any>

  • Private

    Finds a document by its identifier and replace it.

    Parameters

    Returns Bluebird<any>

  • Private

    Updates a document with a compiled stack.

    Parameters

    • id: string | number
    • stack: ((data) => void)[]

    Returns Bluebird<any>

  • Returns the number of elements.

    Returns number

  • Deletes a model.

    Returns void

  • Returns the document at the specified index. num can be a positive or negative number.

    Parameters

    • i_: number
    • Optional options: Options

      See Model#findById.

    Returns default<T> | Record<PropertyKey, any>

  • Tests whether all documents pass the test implemented by the provided function.

    Parameters

    • iterator: ((value, index) => any)
        • (value, index): any
        • Parameters

          • value: any
          • index: number

          Returns any

    Returns boolean

  • Creates a new array with all documents that pass the test implemented by the provided function.

    Parameters

    • iterator: ((value, index) => any)
        • (value, index): any
        • Parameters

          • value: any
          • index: number

          Returns any

    • Optional options: Options

    Returns default<T>

  • Returns the first document.

    Parameters

    • Optional options: Options

      See Model#findById.

    Returns default<T> | Record<PropertyKey, any>

  • Iterates over all documents.

    Parameters

    • iterator: ((value, index) => void)
        • (value, index): void
        • Parameters

          • value: any
          • index: number

          Returns void

    • Optional options: Options

      See Model#findById.

    Returns void

  • Checks if the model contains a document with the specified id.

    Parameters

    • id: PropertyKey

    Returns boolean

  • Returns the last document.

    Parameters

    • Optional options: Options

      See Model#findById.

    Returns default<T> | Record<PropertyKey, any>

  • Creates an array of values by iterating each element in the collection.

    Type Parameters

    • T

    Parameters

    • iterator: ((value, index) => T)
        • (value, index): T
        • Parameters

          • value: any
          • index: number

          Returns T

    • Optional options: Options

    Returns T[]

  • Populates document references.

    Parameters

    • path: string | any[] | {
          model?: any;
          path?: string;
          [key: PropertyKey]: any;
      }

    Returns default<T>

  • Reduces a collection to a value which is the accumulated result of iterating each element in the collection.

    Type Parameters

    • T

    Parameters

    • iterator: ((pre, cur, index) => T)
        • (pre, cur, index): T
        • Parameters

          • pre: any
          • cur: any
          • index: number

          Returns T

    • Optional initial: T

      By default, the initial value is the first document.

    Returns T

  • Reduces a collection to a value which is the accumulated result of iterating each element in the collection from right to left.

    Type Parameters

    • T

    Parameters

    • iterator: ((pre, cur, index) => T)
        • (pre, cur, index): T
        • Parameters

          • pre: any
          • cur: any
          • index: number

          Returns T

    • Optional initial: T

      By default, the initial value is the last document.

    Returns T

  • Removes matching documents.

    Parameters

    Returns Bluebird<any>

  • Finds a document by its identifier and remove it.

    Parameters

    Returns Bluebird<any>

  • Replaces matching documents.

    Parameters

    Returns Bluebird<any>

  • Finds a document by its identifier and replace it.

    Parameters

    Returns Bluebird<any>

  • Inserts the document if it does not exist; otherwise updates it.

    Parameters

    Returns Bluebird<any>

  • Returns the specified range of documents.

    Parameters

    • Optional start_: number
    • Optional end_: number

    Returns default<T>

  • Tests whether some documents pass the test implemented by the provided function.

    Parameters

    • iterator: ((value, index) => any)
        • (value, index): any
        • Parameters

          • value: any
          • index: number

          Returns any

    Returns boolean

  • Returns an array containing all documents.

    Parameters

    • Optional options: Options

      See Model#findById.

    Returns any[]

  • Updates matching documents.

    Parameters

    Returns Bluebird<any>

  • Finds a document by its identifier and update it.

    Parameters

    Returns Bluebird<any>