Gno.Store.Adapter behaviour (Gno v0.1.0)

Copy Markdown View Source

Behaviour for SPARQL triple store adapters.

Adapters implement endpoint discovery, SPARQL operation dispatch, and lifecycle management (setup/teardown/availability checks).

use Options

The use Gno.Store.Adapter macro provides default implementations and supports endpoint URL construction via these options:

  • :query_endpoint_path - path appended to the base URL for SPARQL queries (e.g. "query")
  • :update_endpoint_path - path for SPARQL updates (e.g. "update")
  • :graph_store_endpoint_path - path for Graph Store Protocol operations (e.g. "data")
  • :dataset_endpoint_segment_template - a URI template for constructing the dataset-specific URL segment (e.g. "/{dataset}")

Summary

Callbacks

Check store availability.

Check if store is set up (dataset exists and is functional).

Returns the store-specific IRI of the default graph.

Returns the default graph semantics of this store adapter type.

Store-specific preparation before repository initialization. E.g., creating datasets, setting permissions, etc.

Store-specific cleanup on setup failure.

Functions

Returns the Gno.Store.Adapter module for the given string.

Checks if the given module is a Gno.Store.Adapter module.

Returns the store adapter name for the given store adapter module.

Types

endpoint_url()

@type endpoint_url() :: String.t() | nil

graph_name()

@type graph_name() :: RDF.IRI.t() | nil

result()

@type result() :: SPARQL.Query.Result.t() | RDF.Data.Source.t() | nil

t()

@type t() :: %{
  :__struct__ => type(),
  :__id__ => term(),
  :query_endpoint => RDF.IRI.t() | nil,
  :update_endpoint => RDF.IRI.t() | nil,
  :graph_store_endpoint => RDF.IRI.t() | nil,
  :scheme => String.t() | nil,
  :host => String.t() | nil,
  :port => integer() | nil,
  :userinfo => String.t() | nil,
  optional(atom()) => term()
}

type()

@type type() :: module()

Callbacks

check_availability(t, keyword)

@callback check_availability(
  t(),
  keyword()
) :: :ok | {:error, Gno.Store.UnavailableError.t()}

Check store availability.

check_setup(t, keyword)

@callback check_setup(
  t(),
  keyword()
) :: :ok | {:error, Gno.Store.UnavailableError.t()}

Check if store is set up (dataset exists and is functional).

dataset_endpoint_segment(t)

@callback dataset_endpoint_segment(t()) :: {:ok, binary()} | {:error, any()}

default_graph_iri()

@callback default_graph_iri() :: RDF.IRI.t() | nil

Returns the store-specific IRI of the default graph.

Used to restrict queries to the real default graph on stores with :union semantics via the default-graph-uri SPARQL protocol parameter. Returns nil for stores with :isolated semantics.

default_graph_semantics()

@callback default_graph_semantics() :: :isolated | :union

Returns the default graph semantics of this store adapter type.

  • :isolated — the default graph contains only explicitly inserted triples
  • :union — the default graph is the union of all graphs

determine_graph_store_endpoint(t)

@callback determine_graph_store_endpoint(t()) :: {:ok, endpoint_url()} | {:error, any()}

determine_query_endpoint(t)

@callback determine_query_endpoint(t()) :: {:ok, endpoint_url()} | {:error, any()}

determine_update_endpoint(t)

@callback determine_update_endpoint(t()) :: {:ok, endpoint_url()} | {:error, any()}

handle_sparql(t, t, graph_name, keyword)

@callback handle_sparql(Gno.Store.SPARQL.Operation.t(), t(), graph_name(), keyword()) ::
  {:ok, result()} | :ok | {:error, any()}

setup t, keyword

@callback setup(
  t(),
  keyword()
) :: :ok | {:error, term()}

Store-specific preparation before repository initialization. E.g., creating datasets, setting permissions, etc.

teardown(t, keyword)

@callback teardown(
  t(),
  keyword()
) :: :ok | {:error, term()}

Store-specific cleanup on setup failure.

Functions

type(string)

@spec type(type()) :: binary()
@spec type(binary()) :: type() | nil

Returns the Gno.Store.Adapter module for the given string.

Example

iex> Gno.Store.Adapter.type("Oxigraph")
Gno.Store.Adapters.Oxigraph

iex> Gno.Store.Adapter.type("Commit")
nil

iex> Gno.Store.Adapter.type("NonExisting")
nil

type?(module)

@spec type?(module()) :: boolean()

Checks if the given module is a Gno.Store.Adapter module.

type_name(type)

Returns the store adapter name for the given store adapter module.

Example

iex> Gno.Store.Adapter.type_name(Gno.Store.Adapters.Fuseki)
"Fuseki"

iex> Gno.Store.Adapter.type_name(Gno.Store.Adapters.Oxigraph)
"Oxigraph"

iex> Gno.Store.Adapter.type_name(Gno.Repository)
** (RuntimeError) Invalid Gno.Store.Adapter type: Gno.Repository

iex> Gno.Store.Adapter.type_name(NonExisting)
** (RuntimeError) Invalid Gno.Store.Adapter type: NonExisting