Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Database

Implementation of NoSQL DB that uses paths and objects.

See DatabaseInterface for docs on public API

Uses a plain object as a buffer and reads/writes to a plain JSON file. A better implementation could be backed by somethig a little nicer and not hold the buffer in memory

Hierarchy

  • Database

Implements

Index

Constructors

constructor

Properties

Private buff

buff: any

In memory buffer to read/write data

Private changeHandlers

changeHandlers: ChangeHandlers

An array of callback functions that are alerted when the database changes (mostly want to use this for some type of pubsub functionality on-top)

Private ctx

ctx: Context

Methods

flush

  • flush(): Promise<void>

Private hasSpace

  • hasSpace(): boolean

init

  • init(): Promise<void>

read

  • read(path: string): Promise<Object>

remove

  • remove(path: string): Promise<void>

Private resolve

  • resolve(pathParts: string[], isRead?: boolean, level?: number): any
  • Resolve the object located at path.

    If isRead == true, no new nodes will be created, and the function will return null if a null node is encountered on the path. Else, we create each node on the path.

    Level is used to determine how deep to recurse on path. Callers interested in writing may wish to stop higher up the tree.

    Parameters

    • pathParts: string[]
    • Default value isRead: boolean = true
    • Default value level: number = 0

    Returns any

Private runChangeHandlers

  • runChangeHandlers(path: string, change: any): Promise<void>
  • Parameters

    • path: string
    • change: any

    Returns Promise<void>

Private serialize

  • serialize(): Promise<void>
  • Serialize the current buffer into a plain file.

    Change the path by injecting custom Context

    Throws OUT_OF_SPACE

    Returns Promise<void>

subscribe

  • subscribe(path: string, callback: function): function
  • Parameters

    • path: string
    • callback: function
        • (e: any): Promise<any>
        • Parameters

          • e: any

          Returns Promise<any>

    Returns function

      • (): any
      • Returns any

toString

  • toString(): string

Private unsubscribe

  • unsubscribe(key: string): void

write

  • write(path: string, toWrite: any): Promise<void>
  • Parameters

    • path: string
    • toWrite: any

    Returns Promise<void>

Generated using TypeDoc