Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JsonFilePersister<T>

Persistence component that loads and saves data from/to flat file.

It is used by FilePersistence, but can be useful on its own.

Configuration parameters

  • path: path to the file where data is stored

Example

let persister = new JsonFilePersister("./data/data.json");

persister.save("123", ["A", "B", "C"], (err) => {
    ...
    persister.load("123", (err, items) => {
        console.log(items);                      // Result: ["A", "B", "C"]
    });
});

Type parameters

  • T

Hierarchy

  • JsonFilePersister

Implements

Index

Constructors

Accessors

Methods

Constructors

constructor

Accessors

path

  • get path(): string
  • set path(value: string): void

Methods

configure

  • configure(config: ConfigParams): void
  • Configures component by passing configuration parameters.

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

load

  • load(correlation_id: string, callback: function): void
  • Loads data items from external JSON file.

    Parameters

    • correlation_id: string

      (optional) transaction id to trace execution through call chain.

    • callback: function

      callback function that receives loaded items or error.

        • (err: any, data: T[]): void
        • Parameters

          • err: any
          • data: T[]

          Returns void

    Returns void

save

  • save(correlation_id: string, items: T[], callback?: function): void
  • Saves given data items to external JSON file.

    Parameters

    • correlation_id: string

      (optional) transaction id to trace execution through call chain.

    • items: T[]

      list if data items to save

    • Optional callback: function

      callback function that error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

Generated using TypeDoc