View Source Cosmox.Database (Cosmox v0.1.0)

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.

Defines the default resource creation API headers.

Link to this section Types

Link to this type

database_throughput_mode()

View Source
@type database_throughput_mode() :: :none | :fixed | :autopilot

Link to this section Functions

Link to this function

create_database(database_id, mode \\ :none)

View Source
@spec create_database(database_id :: binary(), mode :: 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"
  }
]

}

Link to this function

resource_creation_headers(arg1)

View Source
@spec resource_creation_headers(database_throughput_mode()) :: [{binary(), binary()}]

Defines the default resource creation API headers.