Database management API for TerminusDB.
A database is the top-level container holding a schema, instance data, and a full
commit history. This module wraps the /api/db endpoints.
All functions accept a TerminusDB.Config and return {:ok, result} or
{:error, TerminusDB.Error.t()}. The !/-suffixed variants raise instead.
The organization defaults to config.organization but can be overridden per call
via the :organization option.
Examples
config = TerminusDB.Config.new(endpoint: "http://localhost:6363")
{:ok, _} = TerminusDB.Database.create(config, "mydb",
label: "My Database",
comment: "A demo database",
schema: true
)
{:ok, details} = TerminusDB.Database.info(config, "mydb")
true = TerminusDB.Database.exists?(config, "mydb")
:ok = TerminusDB.Database.delete(config, "mydb")
Summary
Functions
Creates a new database db_name in the configured (or given) organization.
Creates a database, returning the response body or raising TerminusDB.Error.
Deletes the database db_name.
Deletes a database, returning the response body or raising TerminusDB.Error.
Returns true if the database db_name exists, false otherwise.
Returns details for the database db_name (a list of database descriptors).
Returns database details, or raises TerminusDB.Error.
Lists all databases available to the authenticated user.
Lists all databases, or raises TerminusDB.Error.
Updates metadata (label, comment, etc.) for the database db_name.
Updates a database, returning the response body or raising TerminusDB.Error.
Types
Functions
@spec create(TerminusDB.Config.t(), String.t(), [create_opt()]) :: {:ok, map()} | {:error, TerminusDB.Error.t()}
Creates a new database db_name in the configured (or given) organization.
Options
:label— human-readable name (defaults todb_name).:comment— description (defaults to"").:schema— whether to initialize a schema graph (defaulttrue).:public— whether the database is accessible to all users.:prefixes— custom@base/@schemaIRI prefixes.:organization— overridesconfig.organization.
Returns {:ok, response_body} on success. The response is a map of the shape
%{"@type" => "api:DbCreateResponse", "api:status" => "api:success"}.
Examples
iex> {:ok, _} =
...> TerminusDB.Database.create(config, "mydb", label: "My DB", schema: true)
@spec create!(TerminusDB.Config.t(), String.t(), [create_opt()]) :: map()
Creates a database, returning the response body or raising TerminusDB.Error.
@spec delete(TerminusDB.Config.t(), String.t(), [delete_opt()]) :: {:ok, map() | nil} | {:error, TerminusDB.Error.t()}
Deletes the database db_name.
Options
:force— force deletion of databases in inconsistent states (defaultfalse).:organization— overridesconfig.organization.
Examples
iex> :ok = TerminusDB.Database.delete(config, "mydb")
iex> :ok = TerminusDB.Database.delete(config, "mydb", force: true)
@spec delete!(TerminusDB.Config.t(), String.t(), [delete_opt()]) :: map() | nil
Deletes a database, returning the response body or raising TerminusDB.Error.
@spec exists?(TerminusDB.Config.t(), String.t(), [delete_opt()]) :: boolean()
Returns true if the database db_name exists, false otherwise.
Uses HEAD /api/db/:org/:db. A 404 is interpreted as "does not exist"; any other
non-success response raises TerminusDB.Error.
Options
:organization— overridesconfig.organization.
@spec info(TerminusDB.Config.t(), String.t(), [info_opt()]) :: {:ok, [map()]} | {:error, TerminusDB.Error.t()}
Returns details for the database db_name (a list of database descriptors).
Options
:branches— include branch information (defaultfalse).:verbose— return all available information (defaultfalse).:organization— overridesconfig.organization.
@spec info!(TerminusDB.Config.t(), String.t(), [info_opt()]) :: [map()]
Returns database details, or raises TerminusDB.Error.
@spec list(TerminusDB.Config.t(), [info_opt()]) :: {:ok, [map()]} | {:error, TerminusDB.Error.t()}
Lists all databases available to the authenticated user.
Options
:branches— include branch information (defaultfalse).:verbose— return all available information (defaultfalse).
@spec list!(TerminusDB.Config.t(), [info_opt()]) :: [map()]
Lists all databases, or raises TerminusDB.Error.
@spec update(TerminusDB.Config.t(), String.t(), [create_opt()]) :: {:ok, map()} | {:error, TerminusDB.Error.t()}
Updates metadata (label, comment, etc.) for the database db_name.
Accepts the same body options as create/3 (:label, :comment, :schema,
:public, :prefixes) plus :organization.
@spec update!(TerminusDB.Config.t(), String.t(), [create_opt()]) :: map()
Updates a database, returning the response body or raising TerminusDB.Error.