Class UtiliaDB

The UtiliaDB class represents a simple key-value database. It provides methods for inserting, finding, updating, deleting, and filtering data. The data is stored in a JSON file specified by the filePath parameter. The logger parameter is used for logging database operations.

Constructors

  • Constructs a new UtiliaDB instance.

    Parameters

    • filePath: string

      The path to the JSON file where the data will be stored.

    Returns UtiliaDB

Properties

data: Record<string, any>
filePath: string
logger: Logger = ...

Methods

  • Creates a backup of the database by saving the data to a JSON file.

    Parameters

    • backupFilePath: string

      The path to the backup file.

    Returns void

  • Deletes the key-value pair associated with the specified key from the database.

    Parameters

    • key: string

      The key to delete.

    Returns void

    Throws

    Error if the key does not exist in the database.

  • Filters the data in the database based on a predicate function.

    Parameters

    • predicate: ((value, key) => boolean)

      A function that takes a value and a key and returns a boolean indicating whether the value should be included in the result.

        • (value, key): boolean
        • Parameters

          • value: any
          • key: string

          Returns boolean

    Returns any[]

    An array of values that satisfy the predicate.

  • Finds the value associated with the specified key in the database.

    Parameters

    • key: string

      The key to search for.

    Returns any

    The value associated with the key, or undefined if the key does not exist.

  • Inserts a key-value pair into the database.

    Parameters

    • key: string

      The key of the data.

    • value: any

      The value of the data.

    Returns void

  • Removes the database file.

    Returns void

  • Saves the data to the JSON file. This is a private helper method and should not be called directly.

    Returns void

  • Updates the value associated with the specified key in the database.

    Parameters

    • key: string

      The key to update.

    • value: any

      The new value.

    Returns void

    Throws

    Error if the key does not exist in the database.

Generated using TypeDoc