Gno.Changeset (Gno v0.1.0)

Copy Markdown View Source

Structured representation of intended RDF graph changes.

A changeset declares changes through four actions:

  • :add - insert new statements (no effect if already present)
  • :update - add statements while removing existing values for the same subject/predicate combinations (property-level overwrite)
  • :replace - add statements while removing all existing statements about the same subjects (subject-level overwrite)
  • :remove - delete statements (no effect if not present)

Creating Changesets

Changesets can be created from keyword lists, maps, or RDF.Diff structs:

# From keyword list
Gno.Changeset.new(add: EX.S |> EX.p(EX.O))

# Multiple actions
Gno.Changeset.new(
  add: EX.S |> EX.p(EX.O1),
  replace: EX.S2 |> EX.p(EX.O2),
  remove: EX.S3 |> EX.p(EX.O3)
)

Before applying, a changeset is typically converted to a Gno.EffectiveChangeset that contains only the minimal changes needed against the current repository state. This happens automatically during Gno.commit/2.

Summary

Functions

Returns a combined graph of all statements that will be deleted by the changeset.

Creates the empty changeset.

Returns if the given changeset is empty.

Extracts a Gno.Changeset from the given keywords and returns it with the remaining unprocessed keywords.

Deserializes a changeset from an RDF.Dataset.

Returns a combined graph of all statements that will be inserted by the changeset.

Inverts the changeset.

Creates a new valid changeset.

Creates a new valid changeset.

Serializes the changeset to an RDF.Dataset.

Updates the changes of a changeset.

Validates the given changeset structure.

Types

t()

@type t() :: %Gno.Changeset{
  add: RDF.Graph.t() | nil,
  remove: RDF.Graph.t() | nil,
  replace: RDF.Graph.t() | nil,
  update: RDF.Graph.t() | nil
}

Functions

deletes(changeset)

Returns a combined graph of all statements that will be deleted by the changeset.

empty()

@spec empty() :: t()

Creates the empty changeset.

empty?(changeset)

Returns if the given changeset is empty.

extract(keywords)

Extracts a Gno.Changeset from the given keywords and returns it with the remaining unprocessed keywords.

from_rdf(dataset, opts \\ [])

Deserializes a changeset from an RDF.Dataset.

inserts(changeset)

Returns a combined graph of all statements that will be inserted by the changeset.

invert(changeset)

Inverts the changeset.

new(changes, opts \\ [])

@spec new(Gno.Changeset.Action.changes(), opts :: keyword()) ::
  {:ok, t()} | {:error, any()}

Creates a new valid changeset.

new!(args, opts \\ [])

@spec new!(
  Gno.Changeset.Action.changes(),
  keyword()
) :: t()

Creates a new valid changeset.

As opposed to new/1 this function fails in error cases.

to_rdf(changeset, opts \\ [])

Serializes the changeset to an RDF.Dataset.

update(changeset, changes)

Updates the changes of a changeset.

validate(changeset, opts \\ [])

Validates the given changeset structure.

If valid, the given structure is returned unchanged in an :ok tuple. Otherwise, an :error tuple is returned.