Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FilePersistence<T>

Abstract persistence component that stores data in flat files and caches them in memory.

This is the most basic persistence component that is only able to store data items of any type. Specific CRUD operations over the data items must be implemented in child classes by accessing this._items property and calling save method.

see

MemoryPersistence

see

JsonFilePersister

Configuration parameters

  • path: path to the file where data is stored

References

  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages

Example

class MyJsonFilePersistence extends FilePersistence<MyData> {
    public constructor(path?: string) {
        super(new JsonPersister(path));
    }

    public getByName(correlationId: string, name: string, callback: (err, item) => void): void {
        let item = _.find(this._items, (d) => d.name == name);
        callback(null, item);
    });

    public set(correlatonId: string, item: MyData, callback: (err) => void): void {
        this._items = _.filter(this._items, (d) => d.name != name);
        this._items.push(item);
        this.save(correlationId, callback);
    }

}

Type parameters

  • T

Hierarchy

Implements

  • IReferenceable
  • IOpenable
  • ICleanable
  • IConfigurable

Index

Constructors

constructor

Properties

Protected _items

_items: T[] = []

Protected _loader

_loader: ILoader<T>

Protected _logger

_logger: CompositeLogger = new CompositeLogger()

Protected _opened

_opened: boolean = false

Protected _persister

_persister: JsonFilePersister<T>

Protected _saver

_saver: ISaver<T>

Methods

clear

  • clear(correlationId: string, callback?: function): void
  • Clears component state.

    Parameters

    • correlationId: string

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

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err?: any): void
        • Parameters

          • Optional err: any

          Returns void

    Returns void

close

  • close(correlationId: string, callback?: function): void
  • Closes component and frees used resources.

    Parameters

    • correlationId: string

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

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

configure

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

    Parameters

    • config: ConfigParams

      configuration parameters to be set.

    Returns void

isOpen

  • isOpen(): boolean

open

  • open(correlationId: string, callback?: function): void
  • Opens the component.

    Parameters

    • correlationId: string

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

    • Optional callback: function

      callback function that receives error or null no errors occured.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

save

  • save(correlationId: string, callback?: function): void
  • Saves items to external data source using configured saver component.

    Parameters

    • correlationId: string

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

    • Optional callback: function

      (optional) callback function that receives error or null for success.

        • (err: any): void
        • Parameters

          • err: any

          Returns void

    Returns void

setReferences

  • setReferences(references: IReferences): void

Generated using TypeDoc