Loading data from source files

The Loader Handler Class

import { ZooDbDataLoaderHandler } from '@phfaist/zoodb';
class ZooDbDataLoaderHandler(db_data_loader, options)

This class takes care of loading raw database data using a dbdataloader (e.g. YamlDbDataLoader()) into a ZooDb() instance. It can take care of performing reloads, etc.

You can install a ZooDbDataLoaderHandler in a ZooDb() instance by calling ZooDb.install_data_loader_handler().

The reason for splitting off the logic of the loader handler is to avoid bloating the ZooDb class definition, especially in case a user would like to create a barebones ZooDb, e.g. with hard-coded JSON data, without reloading features, in which case neither a loader nor a loader handler are not necessary.

This class will do a few more things other than directly calling the dbdataloader’s load method and setting the data on the zoodb instance:

  • Checks if a loading operation is already currently in progress, and if so, declines to reload the data with an error message in the console.

  • Calls the zoodb instance’s validate() function, to ensure that the loaded data conforms to any validation checks.

  • Provides a load() function that can be called repeatedly — the method performs an initial zoo load the first time it is called and then performs reload operations on subsequent calls.

Constructor arguments:

  • db_data_loaders - one or more dbdataloader instance to use for loading the database data. You might include, for instance, a YamlDbDataLoader() instance. Specify either an array of loader instances or a single loader instance.

  • options - [optional] an object with the following properties.

Options:

  • throw_reload_errors - if set to true, then reload operation failures will cause an error to be thrown (regardless of whether they are initiated with a second call to load() or with a call to reload()). If set to false, only an error message is printed to the console while the function returns normally. Setting this option to false can be useful in development mode in eleventy, for instance, where you don’t want to stop the development server by throwing an exception when reloading a database after a file modification is detected.

ZooDbDataLoaderHandler.ZooDbDataLoaderHandler
ZooDbDataLoaderHandler.initialize(zoodb)

Initializes the loader handler, giving it the zoodb instance.

Normally, you don’t need to call this method! This function is automatically called by the ZooDb() instance when you call ZooDb.install_data_loader_handler().

ZooDbDataLoaderHandler.load()

Load the data into the zoo, using the dbdataloader. See the class documentation for details.

After the initial call to load(), any subsequent calls to load() will automatically reload the zoo in the same was as directly calling reload().

ZooDbDataLoaderHandler.reload()

Reload data into the zoo using the dbdataloader. You must have called load() at least once before, and that call must have completed.

Usually you don’t need to call reload() directly and simply call load() instead. After the initial call to load(), any subsequent calls to load() will automatically reload the zoo in the same was as directly calling reload().

Importing YAML Files

import { YamlDbDataLoader } from '@phfaist/zoodb/dbdataloader/yamldb';
class YamlDbDataLoader()

Load object data from a collection of YAML (or JSON) source files.

Includes validation of the input object data against the provided schemas.

Doc……..

Configuration options ………….

See also makeStandardZooDbYamlDataLoader() for a simplified loading.

YamlDbDataLoader.YamlDbDataLoader

Importing FLM Files

import { FlmFilesDbDataLoader } from '@phfaist/zoodb/dbdataloader/flmfilesdb';
class FlmFilesDbDataLoader()

Load object data from a collection of FLM source files with optional YAML front matter.

Includes validation of the input object data against the provided schemas.

Doc……..

Configuration options ………….

See also makeStandardZooDbYamlDataLoader() for a simplified loading.

FlmFilesDbDataLoader.FlmFilesDbDataLoader