Databases, over the unary half of the protocol.
Mirrors TypeDB.Database — same names, same return shapes, same
%TypeDB.Error{} — so that switching transports does not rewrite the code
that manages databases either.
Creating a database that already exists succeeds here, and — contrary to what
this module used to claim — it succeeds over the HTTP API too. TypeDB 3.x
treats it as a no-op on both. create_if_not_exists/3 exists so that callers
who mean the idempotent thing say so, not because the two transports disagree;
the shared behaviour suite asserts that they do not.
Summary
Functions
Creates a database.
Creates a database, raising on failure.
Creates a database unless it is already there.
Creates a database unless it is there, raising on failure.
Deletes a database and everything in it.
Deletes a database, raising on failure.
Whether name exists.
Writes a database's schema and data to two files.
Exports a database to two files, raising on failure.
A database's name, or an error when it does not exist.
A database's name, raising when it does not exist.
Creates a database from the two files export_to_files/5 wrote.
Imports a database from two files, raising on failure.
Every database on the server.
Every database on the server, raising on failure.
The database's full schema as TypeQL.
The database's schema, raising on failure.
The type part of the schema, without the functions.
The type schema, raising on failure.
Functions
@spec create(TypeDB.GRPC.Connection.t(), String.t(), keyword()) :: :ok | {:error, TypeDB.Error.t()}
Creates a database.
A no-op for one that already exists, on this transport and over HTTP alike.
Creates a database, raising on failure.
@spec create_if_not_exists(TypeDB.GRPC.Connection.t(), String.t(), keyword()) :: :ok | {:error, TypeDB.Error.t()}
Creates a database unless it is already there.
Creates a database unless it is there, raising on failure.
@spec delete(TypeDB.GRPC.Connection.t(), String.t(), keyword()) :: :ok | {:error, TypeDB.Error.t()}
Deletes a database and everything in it.
Deletes a database, raising on failure.
@spec exists?(TypeDB.GRPC.Connection.t(), String.t(), keyword()) :: boolean()
Whether name exists.
Raises TypeDB.Error for anything other than a clean answer — the same
contract as TypeDB.Database.exists?/3, and for the reason recorded there: a
boolean cannot express "I could not ask", and answering false to that is
what makes unless exists?(conn, x), do: create(conn, x) try to create while
the server is down.
@spec export_to_files( TypeDB.GRPC.Connection.t(), String.t(), Path.t(), Path.t(), keyword() ) :: :ok | {:error, TypeDB.Error.t()}
Writes a database's schema and data to two files.
The one thing this driver does that the HTTP one cannot do at all. TypeDB's
HTTP API has no export and no import — /v1/databases/x/export answers 404
with a valid token while /schema on the same token answers 200 — so a graph
written through the sibling can be read back only by replaying whatever
journal the application kept. This is the native thing: the server streams the
schema and then every entity, attribute and relation, and the pair of files is
a complete backup.
schema_path gets TypeQL you can read; data_path gets the items in TypeDB's
own binary format, which is the format its other drivers and its console
write, so a dump is not tied to this driver. Both are truncated if they exist,
and both are removed again if the export fails part-way — a half-written
backup that looks like a backup is worse than none.
Nothing is held in memory: items are written as they arrive.
:ok = TypeDB.GRPC.Database.export_to_files(conn, "social", "social.tql", "social.data")Options
:timeout— how long to wait, defaulting to the connection's. An export of a large graph is not a request-sized operation; give it a real budget.
Exports a database to two files, raising on failure.
@spec get(TypeDB.GRPC.Connection.t(), String.t(), keyword()) :: {:ok, String.t()} | {:error, TypeDB.Error.t()}
A database's name, or an error when it does not exist.
The same contract as TypeDB.Database.get/3 and as Rust's
DatabaseManager::get: absence is an error carrying the server's own code,
not a false. exists?/3 is the boolean question, and it raises when it
cannot ask.
A name rather than a handle object: everything else in this module is a function taking one, so a struct here would be a second way to say the same thing.
A database's name, raising when it does not exist.
@spec import_from_files( TypeDB.GRPC.Connection.t(), String.t(), Path.t(), Path.t(), keyword() ) :: :ok | {:error, TypeDB.Error.t()}
Creates a database from the two files export_to_files/5 wrote.
The database must not already exist — the import creates it, defines the schema and then loads the items, and TypeDB refuses to import over something that is there. Items are read from disk and sent in batches as the stream drains them, so restoring a graph larger than memory is a restore rather than a problem.
The data file is TypeDB's own format, so this restores a dump taken by any of its drivers, not only by this one.
:ok = TypeDB.GRPC.Database.import_from_files(conn, "social_restored", "social.tql", "social.data")Options
:timeout— how long to wait for the server to finish, defaulting to the connection's. This covers the load, not one request, so it usually wants raising.
Imports a database from two files, raising on failure.
@spec list( TypeDB.GRPC.Connection.t(), keyword() ) :: {:ok, [String.t()]} | {:error, TypeDB.Error.t()}
Every database on the server.
Every database on the server, raising on failure.
@spec schema(TypeDB.GRPC.Connection.t(), String.t(), keyword()) :: {:ok, String.t()} | {:error, TypeDB.Error.t()}
The database's full schema as TypeQL.
The database's schema, raising on failure.
@spec type_schema(TypeDB.GRPC.Connection.t(), String.t(), keyword()) :: {:ok, String.t()} | {:error, TypeDB.Error.t()}
The type part of the schema, without the functions.
The type schema, raising on failure.