[][src]Trait atomic_lib::storelike::Storelike

pub trait Storelike {
    fn add_atoms(&self, atoms: Vec<Atom>) -> AtomicResult<()>;
fn add_resource_string(
        &self,
        subject: String,
        resource: &ResourceString
    ) -> AtomicResult<()>;
fn get_resource_string(&self, subject: &str) -> AtomicResult<ResourceString>;
fn all_resources(&self) -> AtomicResult<ResourceCollection>; fn add_resource(&self, resource: &Resource<'_>) -> AtomicResult<()> { ... }
fn fetch_resource(&self, subject: &str) -> AtomicResult<ResourceString> { ... }
fn get_resource(&self, subject: &str) -> AtomicResult<Resource<'_>>
    where
        Self: Sized
, { ... }
fn get_class(&self, subject: &str) -> AtomicResult<Class> { ... }
fn get_classes_for_subject(&self, subject: &str) -> AtomicResult<Vec<Class>> { ... }
fn get_collection(
        &self,
        tpf: TPFQuery,
        sort_by: String,
        sort_desc: bool,
        _page_nr: u8,
        _page_size: u8
    ) -> AtomicResult<Collection> { ... }
fn get_property(&self, url: &str) -> AtomicResult<Property> { ... }
fn add_atom(&self, atom: Atom) -> AtomicResult<()> { ... }
fn process_delta(&self, delta: Delta) -> AtomicResult<()> { ... }
fn property_shortname_to_url(
        &self,
        shortname: &str,
        resource: &ResourceString
    ) -> AtomicResult<String> { ... }
fn property_url_to_shortname(&self, url: &str) -> AtomicResult<String> { ... }
fn resource_to_ad3(&self, subject: &str) -> AtomicResult<String> { ... }
fn resource_to_json(
        &self,
        resource_url: &str,
        _depth: u8,
        json_ld: bool
    ) -> AtomicResult<String> { ... }
fn tpf(
        &self,
        q_subject: Option<&str>,
        q_property: Option<&str>,
        q_value: Option<&str>
    ) -> AtomicResult<Vec<Atom>> { ... }
fn get_path(
        &self,
        atomic_path: &str,
        mapping: Option<&Mapping>
    ) -> AtomicResult<PathReturn> { ... }
fn validate_store(&self) -> AtomicResult<()> { ... }
fn populate(&self) -> AtomicResult<()> { ... } }

Storelike provides many useful methods for interacting with an Atomic Store. It serves as a basic store Trait, agnostic of how it functions under the hood. This is useful, because we can create methods for Storelike that will work with either in-memory stores, as well as with persistend on-disk stores.

Required methods

fn add_atoms(&self, atoms: Vec<Atom>) -> AtomicResult<()>

Add individual Atoms to the store. Will replace existing Atoms that share Subject / Property combination.

fn add_resource_string(
    &self,
    subject: String,
    resource: &ResourceString
) -> AtomicResult<()>

Replaces existing resource with the contents Accepts a simple nested string only hashmap Adds to hashmap and to the resource store

fn get_resource_string(&self, subject: &str) -> AtomicResult<ResourceString>

Returns a hashmap ResourceString with string Values. Fetches the resource if it is not in the store.

fn all_resources(&self) -> AtomicResult<ResourceCollection>

Returns a collection with all resources in the store. WARNING: This could be very expensive!

Loading content...

Provided methods

fn add_resource(&self, resource: &Resource<'_>) -> AtomicResult<()>

Adds a Resource to the store

fn fetch_resource(&self, subject: &str) -> AtomicResult<ResourceString>

Fetches a resource, makes sure its subject matches. Save to the store. Only adds atoms with matching subjects will be added.

fn get_resource(&self, subject: &str) -> AtomicResult<Resource<'_>> where
    Self: Sized

Returns a full Resource with native Values

fn get_class(&self, subject: &str) -> AtomicResult<Class>

Retrieves a Class from the store by subject URL and converts it into a Class useful for forms

fn get_classes_for_subject(&self, subject: &str) -> AtomicResult<Vec<Class>>

Finds all classes (isA) for any subject. Returns an empty vector if there are none.

fn get_collection(
    &self,
    tpf: TPFQuery,
    sort_by: String,
    sort_desc: bool,
    _page_nr: u8,
    _page_size: u8
) -> AtomicResult<Collection>

Constructs a Collection, which is a paginated list of items with some sorting applied.

fn get_property(&self, url: &str) -> AtomicResult<Property>

Fetches a property by URL, returns a Property instance

fn add_atom(&self, atom: Atom) -> AtomicResult<()>

Adds an atom to the store. Does not do any validations

fn process_delta(&self, delta: Delta) -> AtomicResult<()>

Processes a vector of deltas and updates the store. Panics if the Use this for ALL updates to the store!

fn property_shortname_to_url(
    &self,
    shortname: &str,
    resource: &ResourceString
) -> AtomicResult<String>

Finds the URL of a shortname used in the context of a specific Resource. The Class, Properties and Shortnames of the Resource are used to find this URL

fn property_url_to_shortname(&self, url: &str) -> AtomicResult<String>

Finds

fn resource_to_ad3(&self, subject: &str) -> AtomicResult<String>

fetches a resource, serializes it to .ad3

fn resource_to_json(
    &self,
    resource_url: &str,
    _depth: u8,
    json_ld: bool
) -> AtomicResult<String>

Serializes a single Resource to a JSON object. It uses the Shortnames of properties for Keys. The depth is useful, since atomic data allows for cyclical (infinite-depth) relationships

fn tpf(
    &self,
    q_subject: Option<&str>,
    q_property: Option<&str>,
    q_value: Option<&str>
) -> AtomicResult<Vec<Atom>>

Triple Pattern Fragments interface. Use this for most queries, e.g. finding all items with some property / value combination. Returns an empty array if nothing is found.

Example

For example, if I want to view all Resources that are instances of the class "Property", I'd do:

use atomic_lib::Storelike;
let mut store = atomic_lib::Store::init();
store.populate();
let atoms = store.tpf(
    None,
    Some("https://atomicdata.dev/properties/isA"),
    Some("[\"https://atomicdata.dev/classes/Class\"]")
).unwrap();
assert!(atoms.len() == 3)

fn get_path(
    &self,
    atomic_path: &str,
    mapping: Option<&Mapping>
) -> AtomicResult<PathReturn>

Accepts an Atomic Path string, returns the result value (resource or property value) E.g. https://example.com description or thing isa 0 https://docs.atomicdata.dev/core/paths.html

fn validate_store(&self) -> AtomicResult<()>

Checks Atomic Data in the store for validity. Returns an Error if it is not valid.

Validates:

  • [X] If the Values can be parsed using their Datatype (e.g. if Integers are integers)
  • [X] If all required fields of the class are present
  • [ ] If the URLs are publicly accessible and return the right type of data
  • [ ] Returns a report, instead of throws an error

fn populate(&self) -> AtomicResult<()>

Loads the default store

Loading content...

Implementors

impl Storelike for Store[src]

Loading content...