Module mentat::vocabulary [] [src]

This module exposes an interface for programmatic management of vocabularies.

A vocabulary is defined by a name, a version number, and a collection of attribute definitions.

Operations on vocabularies can include migrations between versions. These are defined programmatically as a pair of functions, pre and post, that are invoked prior to an upgrade.

A Mentat store exposes, via the HasSchema trait, operations to read vocabularies by name or in bulk.

An in-progress transaction (InProgress) further exposes a trait, VersionedStore, which allows for a vocabulary definition to be checked for existence in the store, and transacted if needed.

Typical use is the following:

#[macro_use(kw)]
extern crate mentat;

use mentat::{
    Store,
    ValueType,
};

use mentat::vocabulary;
use mentat::vocabulary::{
    Definition,
    HasVocabularies,
    VersionedStore,
    VocabularyOutcome,
};

fn main() {
    let mut store = Store::open("").expect("connected");

    {
        // Read the list of installed vocabularies.
        let reader = store.begin_read().expect("began read");
        let vocabularies = reader.read_vocabularies().expect("read");
        for (name, vocabulary) in vocabularies.iter() {
            println!("Vocab {} is at version {}.", name, vocabulary.version);
            for &(ref name, ref attr) in vocabulary.attributes().iter() {
                println!("  >> {} ({})", name, attr.value_type);
            }
        }
    }

    {
        let mut in_progress = store.begin_transaction().expect("began transaction");

        // Make sure the core vocabulary exists.
        in_progress.verify_core_schema().expect("verified");

        // Make sure our vocabulary is installed, and install if necessary.
        in_progress.ensure_vocabulary(&Definition {
            name: kw!(:example/links),
            version: 1,
            attributes: vec![
                (kw!(:link/title),
                 vocabulary::AttributeBuilder::helpful()
                   .value_type(ValueType::String)
                   .multival(false)
                   .fulltext(true)
                   .build()),
            ],
            pre: Definition::no_op,
            post: Definition::no_op,
        }).expect("ensured");

        // Now we can do stuff.
        in_progress.transact("[{:link/title \"Title\"}]").expect("transacts");
        in_progress.commit().expect("commits");
    }
}

A similar approach is taken using the VocabularyProvider trait to handle migrations across multiple vocabularies.

Modules

attribute

Structs

AttributeBuilder
Definition

A definition of an attribute that is independent of a particular store.

SimpleVocabularySource

A convenience struct to package simple pre and post functions with a collection of vocabulary Definitions.

Vocabularies

A collection of named Vocabulary instances, as retrieved from the store.

Vocabulary

A definition of a vocabulary as retrieved from a particular store.

Enums

VocabularyCheck

This enum captures the various relationships between a particular vocabulary pair — one Definition and one Vocabulary, if present.

VocabularyOutcome

This enum captures the outcome of attempting to ensure that a vocabulary definition is present and up-to-date in the store.

Traits

HasVocabularies

This trait captures the ability to retrieve and describe stored vocabularies.

VersionedStore

This trait captures the ability of a store to check and install/upgrade vocabularies.

VocabularySource

Implement VocabularySource to have full programmatic control over how a set of Definitions are checked against and transacted into a store.

VocabularyStatus

VocabularyStatus is passed to pre function when attempting to add or upgrade vocabularies via ensure_vocabularies. This is how you can find the status and versions of existing vocabularies — you can retrieve the requested definition and the resulting VocabularyCheck by name.

Type Definitions

Datom
Version