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

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`.

# `t`

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

# `deletes`

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

# `empty`

```elixir
@spec empty() :: t()
```

Creates the empty changeset.

# `empty?`

Returns if the given changeset is empty.

# `extract`

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

# `from_rdf`

Deserializes a changeset from an `RDF.Dataset`.

# `inserts`

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

# `invert`

Inverts the changeset.

# `new`

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

Creates a new valid changeset.

# `new!`

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

Serializes the changeset to an `RDF.Dataset`.

# `update`

Updates the changes of a changeset.

# `validate`

Validates the given changeset structure.

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

---

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