View Source Cosmox.Database (Cosmox v0.1.1)

Handles all the command to create, modify or delete a database.

Link to this section Summary

Functions

Creates a new database, given the database id (the name)).

Deletes the database with the given id.

Gets the database with the given database_id.

Returns a list of the database available on the CosmosDB instance.

Link to this section Functions

Link to this function

create_database(database_id, mode \\ :none)

View Source
@spec create_database(
  database_id :: binary(),
  mode :: Cosmox.Configuration.database_throughput_mode()
) ::
  {:ok, Cosmox.Structs.Database.t()}
  | {:error, binary()}
  | {:error, Exception.t()}

Creates a new database, given the database id (the name)).

example

Example

iex> Cosmox.Database.create_database("test_db") {:ok, %Cosmox.Structs.Database{

_colls: "colls/",
_etag: ""00006518-0000-0c00-0000-630dd4920000"",
_rid: "FONgAA==",
_self: "dbs/FONgAA==/",
_ts: 1661850770,
_users: "users/",
id: "test_db"

}}

Link to this function

delete_database(database_id)

View Source
@spec delete_database(database_id :: binary()) ::
  :ok | {:error, Cosmox.Response.ErrorMessage.t()}

Deletes the database with the given id.

example

Example

iex(5)> Cosmox.Database.delete_database("test_db") :ok

Link to this function

get_database(database_id)

View Source
@spec get_database(database_id :: binary()) ::
  {:ok, Cosmox.Structs.Database.t()}
  | {:error, Cosmox.Response.ErrorMessage.t()}

Gets the database with the given database_id.

example

Example

iex(4)> Cosmox.Database.get_database("test_db") {:ok, %Cosmox.Structs.Database{

_colls: "colls/",
_etag: ""00006518-0000-0c00-0000-630dd4920000"",
_rid: "FONgAA==",
_self: "dbs/FONgAA==/",
_ts: 1661850770,
_users: "users/",
id: "test_db"

}}

@spec list_databases() ::
  {:ok, Cosmox.Structs.DatabaseList.t()}
  | {:error, binary()}
  | {:error, Exception.t()}

Returns a list of the database available on the CosmosDB instance.

example

Example

iex> Cosmox.Database.list_databases() {:ok, %Cosmox.Structs.DatabaseList{

databases: [
  %Cosmox.Structs.Database{
    _colls: "colls/",
    _etag: ""00006518-0000-0c00-0000-630dd4920000"",
    _rid: "FONgAA==",
    _self: "dbs/FONgAA==/",
    _ts: 1661850770,
    _users: "users/",
    id: "test_db"
  }
]

}