Module jesse_database

Schema definitions cache handling.

Description

Schema definitions cache handling.

All the schema definitions are stored in an ETS table for quick access during validation. This module provides an interface for: 1) updating of schema definitions in runtime; 2) getting of a schema definition by a key. When an update is ordered, the update function checks a schema definition file timestamp and compares it to a timestamp for the same schema in the cache, so, it will never update a schema in the database if the definition file was not updated.

Data Types

error()

error() = {error, error_reason()}

error_reason()

error_reason() = {database_error, Key::string(), schema_not_found | unknown_uri_scheme}

reason()

reason() = term()

store_fail()

store_fail() = {file:filename(), file:date_time(), reason()}

store_result()

store_result() = ok | [store_fail()]

Function Index

add/3Adds a schema definition Schema to the internal storage associated with the key Key.
add_path/3Add schema definitions from all the files from directory Dir, each being validated by ValidationFun, and stored in the internal storage.
add_uri/1Add a schema definition to the internal storage identified by a URI Key.
delete/1Deletes a schema definition from the internal storage associated with, or sourced with the key Key.
load/1Loads a schema definition associated with, or sourced with the key Key from the internal storage.
load_all/0Loads all schemas in the internal storage.
load_uri/1Loads a schema definition associated with, or sourced with the key Key from the internal storage.

Function Details

add/3

add(Key::string(), Schema::jesse:json_term(), ValidationFun::fun((any()) -> boolean())) -> store_result()

Adds a schema definition Schema to the internal storage associated with the key Key. It will overwrite an existing schema with the same key if there is any.

add_path/3

add_path(Path::string(), ParseFun::fun((binary()) -> jesse:json_term()), ValidationFun::fun((any()) -> boolean())) -> store_result()

Add schema definitions from all the files from directory Dir, each being validated by ValidationFun, and stored in the internal storage.

The file modification time will also be stored, to skip unnecessary updates.

Schema definitions are stored in the format that ParseFun returns.

NOTE: it's impossible to automatically update schema definitions added by add/2. The only way to update those is to use add/2 again with the new definition.

add_uri/1

add_uri(Key::string()) -> store_result()

Add a schema definition to the internal storage identified by a URI Key. Supported URI schemes are file:, http: and https:. If this fails, an exception will be thrown.

delete/1

delete(Key::string()) -> ok

Deletes a schema definition from the internal storage associated with, or sourced with the key Key.

load/1

load(Key::string()) -> jesse:json_term() | no_return()

Loads a schema definition associated with, or sourced with the key Key from the internal storage. If there is no such key in the storage, an exception will be thrown.

load_all/0

load_all() -> [tuple()]

Loads all schemas in the internal storage.

load_uri/1

load_uri(Key::string()) -> jesse:json_term() | no_return()

Loads a schema definition associated with, or sourced with the key Key from the internal storage. If there is no such key in the storage, it will try to fetch and add one to the internal storage if the Key uses the file:, http: or https: URI scheme. If this fails as well, an exception will be thrown.


Generated by EDoc