pip_services3_data.persistence.JsonFilePersister module

pip_services3_data.persistence.JsonFilePersister

JSON file persister implementation

copyright

Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.

license

MIT, see LICENSE for more details.

class pip_services3_data.persistence.JsonFilePersister.JsonFilePersister(path: str = None)

Bases: pip_services3_data.ILoader.ILoader, pip_services3_data.ISaver.ISaver, pip_services3_commons.config.IConfigurable.IConfigurable

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:

persister = JsonFilePersister("./data/data.json")

persister.save("123", ["A", "B", "C"])
...

persister.load("123", items)
print items
configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)

Configures component by passing configuration parameters.

Parameters

config – configuration parameters to be set.

load(correlation_id: Optional[str]) → List[T]

Loads data items from external JSON file.

Parameters

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

Returns

loaded items

property path

Gets the file path where data is stored.

Returns

the file path where data is stored.

save(correlation_id: Optional[str], items: List[T])

Saves given data items to external JSON file.

Parameters
  • correlation_id – (optional) transaction id to trace execution through call chain.

  • items – list if data items to save