Class JsonDB

Hierarchy

  • JsonDB

Constructors

Properties

config: JsonDBConfig
data: KeyValue = {}
loaded: boolean = false

Methods

  • Returns the number of element which constitutes the array

    Parameters

    • dataPath: string

    Returns Promise<number>

    Throws

  • Delete the data

    Parameters

    • dataPath: string

      path leading to the data

    Returns Promise<void>

  • Check for existing datapath

    Parameters

    • dataPath: string

    Returns Promise<boolean>

  • Find all specific entry in an array/object

    Type Parameters

    • T

    Parameters

    • rootPath: string

      base dataPath from where to start searching

    • callback: FindCallback

      method to filter the result and find the wanted entry. Receive the entry and it's index.

    Returns Promise<undefined | T[]>

    Throws

  • Find a specific entry in an array/object

    Type Parameters

    • T

    Parameters

    • rootPath: string

      base dataPath from where to start searching

    • callback: FindCallback

      method to filter the result and find the wanted entry. Receive the entry and it's index.

    Returns Promise<undefined | T>

    Throws

  • Convert a router style path to a normal path By default propertyName to search is "id"

    Parameters

    • path: string

      router based path to a correct base path

    • propertyName: string = 'id'

      name of the property to look for searchValue

    Returns Promise<string>

  • Parameters

    • dataPath: string

    Returns Promise<any>

  • Get the wanted data

    Parameters

    • dataPath: string

      path of the data to retrieve

    Returns Promise<any>

  • Returns the index of the object that meets the criteria submitted. Returns -1, if no match is found.

    Parameters

    • dataPath: string

      base dataPath from where to start searching

    • searchValue: string | number

      value to look for in the dataPath

    • propertyName: string = 'id'

      name of the property to look for searchValue

    Returns Promise<number>

  • Return the index of the value inside the array. Returns -1, if no match is found.

    Parameters

    • dataPath: string

      base dataPath from where to start searching

    • searchValue: string | number

      value to look for in the dataPath

    Returns Promise<number>

  • Same as getData only here it's directly typed to your object

    Type Parameters

    • T

    Parameters

    • dataPath: string

      path of the data to retrieve

    Returns Promise<T>

  • Same as getData but with your own object type and a possible default value when we can't find the data path

    Type Parameters

    • T

    Parameters

    • dataPath: string

      path of the data to retrieve

    • Optional defaultValue: T

      value to use when the dataPath doesn't lead to data

    Returns Promise<T>

    Throws

  • Manually load the database It is automatically called when the first getData is done

    Returns Promise<void>

    Throws

  • Process datapath into different parts

    Parameters

    • dataPath: string

    Returns DataPath

  • Pushing data into the database

    Parameters

    • dataPath: string

      path leading to the data

    • data: any

      data to push

    • override: boolean = true

      overriding or not the data, if not, it will merge them

    Returns Promise<void>

    Throws

  • Reload the database from the file

    Returns Promise<void>

  • Only use this if you know what you're doing. It reset the full data of the database.

    Parameters

    • data: any

    Returns void

  • Parameters

    • dataPath: DataPath
    • create: boolean = false

    Returns Promise<any>

  • Manually save the database By default you can't save the database if it's not loaded

    Parameters

    • Optional force: boolean

      force the save of the database

    Returns Promise<void>

    Throws

Generated using TypeDoc