# `Gno.Store.Adapter`
[🔗](https://github.com/rdf-elixir/gno/blob/v0.1.0/lib/gno/store/adapter.ex#L1)

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}"`)

# `endpoint_url`

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

# `graph_name`

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

# `result`

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

# `t`

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

# `type`

```elixir
@type type() :: module()
```

# `check_availability`

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

Check store availability.

# `check_setup`

```elixir
@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`

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

# `default_graph_iri`

```elixir
@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`

```elixir
@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`

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

# `determine_query_endpoint`

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

# `determine_update_endpoint`

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

# `handle_sparql`

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

# `setup`

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

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

# `teardown`

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

Store-specific cleanup on setup failure.

# `type`

```elixir
@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?`

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

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

# `type_name`

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
