Class JsonDB

Represents a simple JSON file database.

Hierarchy

  • JsonDB

Constructors

  • Creates a new instance of the JsonDB class.

    Parameters

    • filepath: string

      The filepath where the data file is stored or to be stored.

    • indents: number = 0

    Returns JsonDB

Properties

The data stored in the JSON database.

filepath: string

The filepath where the data file is stored or to be stored.

indents: number = 0

Methods

  • Deletes a value from the JSON database.

    Parameters

    • Optional prefix: string

      Object path prefix as dot-separated keys.

    • save: boolean = true

      Whether to save the data to the JSON file.

    Returns void

  • Gets a value from the JSON database.

    Type Parameters

    Parameters

    • Optional prefix: string

      Object path prefix as dot-separated keys.

    Returns T

    The value associated with the key.

    Throws

    An error if no entry is found at the specified key.

  • Gets a value from the JSON database safely.

    Type Parameters

    Parameters

    • Optional prefix: string

      Object path prefix as dot-separated keys.

    Returns undefined | T

    The value associated with the key, or undefined if no entry is found.

  • Checks if a key exists in the JSON database.

    Parameters

    • Optional prefix: string

      Object path prefix as dot-separated keys.

    Returns boolean

    True if the key exists, false otherwise.

  • Sets a value in the JSON database.

    Parameters

    • Optional prefix: string

      Object path prefix as dot-separated keys.

    • value: JsonValue = {}

      The value to set.

    • save: boolean = true

      Whether to save the data to the JSON file.

    Returns void

  • Sets the filepath of the JSON file.

    Parameters

    • filepath: string

      The new filepath.

    • save: boolean = true

    Returns void

Generated using TypeDoc