Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DBDoc

Class for creating structured documents

Hierarchy

  • DBDoc

Index

Constructors

constructor

  • new DBDoc(data: {}, collection: DBCollection, id?: string, isCloned?: boolean): DBDoc
  • Construct a new Document with the collections schema and any provided data

    Parameters

    • data: {}

      Data to be assigned to the document schema

      • [key: string]: any
    • collection: DBCollection

      Reference to the parent collection

    • id: string = ...
    • isCloned: boolean = false

    Returns DBDoc

Properties

_createdAt

_createdAt: number = ...

_pluginData

_pluginData: {} = {}

Object for any plugin related data

Type declaration

  • [key: string]: any

_updatedAt

_updatedAt: number = ...

Readonly collection

collection: DBCollection

Reference to the parent collection

Readonly doc_

doc_: Debugger

Debugger variable

id

id: string

Document id

indexed

indexed: {} = {}

Reference to indexed data for repeated deep data matching

Type declaration

  • [key: string]: any | any[]

Private isCloned

isCloned: boolean = false

pluginData

pluginData: { delete: (plugin: string) => void; get: (plugin: string) => any; set: (plugin: string, data: any) => void } = ...

Object with functions for handling plugin data

Type declaration

  • delete: (plugin: string) => void
      • (plugin: string): void
      • Delete the data object of a specific plugin

        Parameters

        • plugin: string

          Plugin name to delete data of

        Returns void

  • get: (plugin: string) => any
      • (plugin: string): any
      • Get the data object from a specific plugin

        Parameters

        • plugin: string

          Plugin name to get data of

        Returns any

        Data from the plugin

  • set: (plugin: string, data: any) => void
      • (plugin: string, data: any): void
      • Set/replace the data object for a plugin

        Parameters

        • plugin: string

          Plugin name to set data to

        • data: any

          Data to replace the plugin data with

        Returns void

Private updateIndexes

updateIndexes: (...args: [path: string]) => void = ...

Type declaration

    • (...args: [path: string]): void
    • Parameters

      • Rest ...args: [path: string]

      Returns void

Accessors

data

  • get data(): any
  • The data of the document as provided by the storage provider

    Returns any

Methods

clone

  • Duplicate this document, making mutations to it not affect the original

    Returns DBDoc

customPopulate

  • customPopulate(opts: DocumentCustomPopulateOpts): DBDoc
  • Populate the document with another document that matches the query. This will return a copy of the document and not a reference to the original.

    It's recommended you use the provided populate (doc.populate(...)) function instead.

    Parameters

    • opts: DocumentCustomPopulateOpts

      Options for the populate. Things like the target field and query don't have to be set

    Returns DBDoc

delete

  • delete(): void
  • Delete this document from the db

    Returns void

emitEvent

  • emitEvent(event: MemsDBEvent): void
  • Emit an event to the attached database

    Parameters

    • event: MemsDBEvent

      Event to emit

    Returns void

populate

  • populate(populateQuery: string, filter?: boolean): DBDoc
  • Populate down a tree of documents based on the provided MemsPL populateQuery

    Parameters

    • populateQuery: string

      MemsPL population query

    • filter: boolean = false

      Filter unspecified keys from the populated documents

    Returns DBDoc

    Cloned version of this document

set

  • set(key: string, data: any): void
  • Set the value of a key in the doc to a specified value.

    This should only be done on shallow key values, lest you want keys like 'key1.key2.key3' as object keys in your data

    Parameters

    • key: string

      Key to set the value of

    • data: any

      Data to set to the afformentioned key

    Returns void

    Returns nothing

setData

  • setData(data: any): void
  • Set the root of the data object.

    This will completely replace the data object

    Parameters

    • data: any

      Data to set

    Returns void

toJSON

  • toJSON(): any
  • Returns a simplified view

    Returns any

tree

  • tree(opts?: DocumentTreeOpts): DBDoc
  • Populate a tree of documents. It's recommended you use the provided populate (doc.populate(...)) function instead.

    Parameters

    • opts: DocumentTreeOpts = {}

      Options for making a tree from the provided document

    Returns DBDoc

    A cloned version of this doc that has the data field formatted into a tree

Generated using TypeDoc