View Source Cosmox.Container (Cosmox v0.1.0)

Handles the operation concerning the database containers.

Link to this section Summary

Functions

Creates a continaer with the given id, inside the database with the given database id. The function does not check whether the database exists or not, it will delegate this check directly to Cosmos.

Deletes the given container within the given database id.

Gets the container with the given name within the database with the given id.

Gets the container partition keys.

Link to this section Functions

Link to this function

create_container(database_id, container_id, mode \\ :none)

View Source
@spec create_container(
  database_id :: binary(),
  container_id :: binary(),
  mode :: Cosmox.Database.database_throughput_mode()
) ::
  {:ok, Cosmox.Structs.Collection} | {:error, Cosmox.Response.ErrorMessage.t()}

Creates a continaer with the given id, inside the database with the given database id. The function does not check whether the database exists or not, it will delegate this check directly to Cosmos.

example

Example

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

_colls: "colls/",
_etag: ""00006618-0000-0c00-0000-630ddb830000"",
_rid: "lJweAA==",
_self: "dbs/lJweAA==/",
_ts: 1661852547,
_users: "users/",
id: "test_db"

}}

iex> Cosmox.Container.create_container("test_db", "test_container") {:ok, %Cosmox.Structs.Collection{

_conflicts: "conflicts/",
_docs: "docs/",
_etag: ""00006818-0000-0c00-0000-630ddbc20000"",
_rid: "lJweAM76mmE=",
_self: "dbs/lJweAA==/colls/lJweAM76mmE=/",
_sprocs: "sprocs/",
_triggers: "triggers/",
_ts: 1661852610,
_udfs: "udfs/",
conflict_resolution_policy: %Cosmox.Structs.Collections.ConflictResolutionPolicy{
  conflict_resolution_path: "/_ts",
  conflict_resolution_procedure: "",
  mode: "LastWriterWins"
},
geospatial_config: %Cosmox.Structs.Collections.GeospatialConfig{
  type: "Geography"
},
id: "test_container",
indexing_policy: %Cosmox.Structs.Collections.IndexingPolicy{
  automatic: true,
  excludedPaths: [%Cosmox.Structs.Path{path: "/"_etag"/?"}],
  includedPaths: [%Cosmox.Structs.Path{path: "/*"}],
  indexingMode: "consistent"
},
partition_key: %Cosmox.Structs.PartitionKey{
  kind: "Hash",
  paths: ["/pk"],
  version: 2
}

}}

Link to this function

delete_container(database_id, container_id)

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

Deletes the given container within the given database id.

example

Example

iex(11)> Cosmox.Container.delete_container("test_db", "test_container") :ok

Link to this function

get_container(database_id, container_id)

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

Gets the container with the given name within the database with the given id.

example

Example

iex> Cosmox.Container.create_container("test_db", "test_container") {:ok, %Cosmox.Structs.Collection{

_conflicts: "conflicts/",
_docs: "docs/",
_etag: ""00006818-0000-0c00-0000-630ddbc20000"",
_rid: "lJweAM76mmE=",
_self: "dbs/lJweAA==/colls/lJweAM76mmE=/",
_sprocs: "sprocs/",
_rid: "lJweAM76mmE=",
_self: "dbs/lJweAA==/colls/lJweAM76mmE=/",
_sprocs: "sprocs/",
_triggers: "triggers/",
_ts: 1661852610,
_udfs: "udfs/",
conflict_resolution_policy: %Cosmox.Structs.Collections.ConflictResolutionPolicy{
  conflict_resolution_path: "/_ts",
  conflict_resolution_procedure: "",
  mode: "LastWriterWins"
},
geospatial_config: %Cosmox.Structs.Collections.GeospatialConfig{
  type: "Geography"
},
id: "test_container",
indexing_policy: %Cosmox.Structs.Collections.IndexingPolicy{
  automatic: true,
  excludedPaths: [%Cosmox.Structs.Path{path: "/"_etag"/?"}],
  includedPaths: [%Cosmox.Structs.Path{path: "/*"}],
  indexingMode: "consistent"
},
partition_key: %Cosmox.Structs.PartitionKey{
  kind: "Hash",
  paths: ["/pk"],
  version: 2
}

}}

Link to this function

get_container_partition_keys(database_id, container_id)

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

Gets the container partition keys.

example

Example

iex(10)> Cosmox.Container.get_container_partition_keys("test_db", "test_container") {:ok, %Cosmox.Structs.PartitionKeyRangeResponse{

_count: 1,
_rid: "lJweAM76mmE=",
partition_key_ranges: [
  %Cosmox.Structs.PartitionKeyRange{
    _etag: ""00006a18-0000-0c00-0000-630ddbc20000"",
    _rid: "lJweAM76mmECAAAAAAAAUA==",
    _self: "dbs/lJweAA==/colls/lJweAM76mmE=/pkranges/lJweAM76mmECAAAAAAAAUA==/",
    _ts: 1661852610,
    id: "0",
    max_exclusive: "FF",
    min_inclusive: "",
    parents: [],
    rid_prefix: 0,
    status: "online",
    throughput_fraction: 1
  }
]

}}