Schema frame API for TerminusDB.
Wraps the /api/schema endpoint, which returns the class frame for a class or
all classes for a database's schema. A "frame" is a JSON-LD description of a
schema class: its properties, types, key strategy, and documentation.
All functions require a TerminusDB.Config scoped to a database (via
TerminusDB.Config.with_database/2).
Quick start
config =
TerminusDB.Config.new(endpoint: "http://localhost:6363")
|> TerminusDB.Config.with_database("mydb")
# Get the frame for a specific class
{:ok, frame} = TerminusDB.Schema.frame(config, "Person")
# => %{"@type" => "Class", "name" => "xsd:string", ...}
# Get all class frames
{:ok, all} = TerminusDB.Schema.all(config)
# => %{"Person" => %{"@type" => "Class", ...}, "Room" => %{...}}
Summary
Functions
Returns all class frames for the database's schema.
Returns all class frames, or raises TerminusDB.Error.
Returns the class frame for a specific class class_name, or all class frames
if class_name is nil.
Returns the class frame, or raises TerminusDB.Error.
Types
Functions
@spec all(TerminusDB.Config.t(), [frame_opt()]) :: {:ok, map()} | {:error, TerminusDB.Error.t()}
Returns all class frames for the database's schema.
Equivalent to frame(config, nil, opts).
Examples
iex> config = TerminusDB.Config.new(
...> endpoint: "http://localhost:6363",
...> adapter: fn req ->
...> {req, Req.Response.new(status: 200, body: %{"@context" => %{"@type" => "Context"}, "Person" => %{"@type" => "Class"}})}
...> end
...> ) |> TerminusDB.Config.with_database("mydb")
iex> {:ok, all} = TerminusDB.Schema.all(config)
iex> Map.keys(all)
["Person"]
@spec all!(TerminusDB.Config.t(), [frame_opt()]) :: map()
Returns all class frames, or raises TerminusDB.Error.
Examples
iex> config = TerminusDB.Config.new(
...> endpoint: "http://localhost:6363",
...> adapter: fn req -> {req, Req.Response.new(status: 200, body: %{"Person" => %{"@type" => "Class"}})} end
...> ) |> TerminusDB.Config.with_database("mydb")
iex> TerminusDB.Schema.all!(config)
%{"Person" => %{"@type" => "Class"}}
@spec frame(TerminusDB.Config.t(), String.t() | nil, [frame_opt()]) :: {:ok, map()} | {:error, TerminusDB.Error.t()}
Returns the class frame for a specific class class_name, or all class frames
if class_name is nil.
Options
:compress_ids— compress the URLs returned using prefixes (defaulttrue).:expand_abstract— expand abstract classes into lists of concrete classes in frame options (defaulttrue).:organization— overridesconfig.organization.
Examples
Get the frame for a specific class:
iex> config = TerminusDB.Config.new(
...> endpoint: "http://localhost:6363",
...> adapter: fn req ->
...> {req, Req.Response.new(status: 200, body: %{"@type" => "Class", "name" => "xsd:string"})}
...> end
...> ) |> TerminusDB.Config.with_database("mydb")
iex> {:ok, frame} = TerminusDB.Schema.frame(config, "Person")
iex> frame["name"]
"xsd:string"Get all class frames (pass nil or omit class_name):
iex> config = TerminusDB.Config.new(
...> endpoint: "http://localhost:6363",
...> adapter: fn req ->
...> {req, Req.Response.new(status: 200, body: %{"Person" => %{"@type" => "Class"}, "Room" => %{"@type" => "Class"}})}
...> end
...> ) |> TerminusDB.Config.with_database("mydb")
iex> {:ok, all} = TerminusDB.Schema.frame(config)
iex> Map.keys(all) |> Enum.sort()
["Person", "Room"]
@spec frame!(TerminusDB.Config.t(), String.t() | nil, [frame_opt()]) :: map()
Returns the class frame, or raises TerminusDB.Error.
Examples
iex> config = TerminusDB.Config.new(
...> endpoint: "http://localhost:6363",
...> adapter: fn req -> {req, Req.Response.new(status: 200, body: %{"@type" => "Class", "name" => "xsd:string"})} end
...> ) |> TerminusDB.Config.with_database("mydb")
iex> TerminusDB.Schema.frame!(config, "Person")
%{"@type" => "Class", "name" => "xsd:string"}