WeaviateEx.Types.Tenant (WeaviateEx v0.7.4)

View Source

Tenant struct with typed activity status.

Represents a tenant in a multi-tenant collection with full type safety for activity status values.

Activity Status Types

  • :active - Tenant is active (alias for hot)
  • :inactive - Tenant is inactive (alias for cold)
  • :hot - Tenant data is in memory, ready for queries
  • :cold - Tenant is temporarily deactivated
  • :frozen - Tenant data is persisted but not in memory
  • :offloaded - Tenant data moved to cold storage
  • :offloading - Tenant is being offloaded to cold storage (transitional)
  • :onloading - Tenant is being loaded from cold storage (transitional)

Examples

tenant = Tenant.new("customer_123")
tenant = Tenant.new("customer_456", activity_status: :cold)

# Convert to API format
api_map = Tenant.to_map(tenant)
# => %{"name" => "customer_456", "activityStatus" => "COLD"}

# Parse from API response
tenant = Tenant.from_map(%{"name" => "customer_789", "activityStatus" => "FROZEN"})
# => %Tenant{name: "customer_789", activity_status: :frozen}

Summary

Functions

Checks if the tenant is active (hot or active status).

Creates a Tenant from a map (e.g., from API response).

Checks if the tenant is inactive.

Creates a new Tenant struct.

Sets the activity status of a tenant.

Converts the tenant to a map for the Weaviate API.

Checks if a status is valid.

Returns the list of valid activity statuses.

Validates the activity status.

Types

activity_status()

@type activity_status() ::
  :active
  | :inactive
  | :hot
  | :cold
  | :frozen
  | :offloaded
  | :offloading
  | :onloading

t()

@type t() :: %WeaviateEx.Types.Tenant{
  activity_status: activity_status(),
  name: String.t()
}

Functions

active?(tenant)

@spec active?(t()) :: boolean()

Checks if the tenant is active (hot or active status).

Examples

Tenant.active?(Tenant.new("t1", activity_status: :hot))
# => true

Tenant.active?(Tenant.new("t1", activity_status: :cold))
# => false

from_map(map)

@spec from_map(map()) :: t()

Creates a Tenant from a map (e.g., from API response).

Examples

Tenant.from_map(%{"name" => "customer_123", "activityStatus" => "FROZEN"})
# => %Tenant{name: "customer_123", activity_status: :frozen}

Tenant.from_map(%{"name" => "customer_456"})
# => %Tenant{name: "customer_456", activity_status: :active}

inactive?(tenant)

@spec inactive?(t()) :: boolean()

Checks if the tenant is inactive.

Examples

Tenant.inactive?(Tenant.new("t1", activity_status: :cold))
# => true

new(name, opts \\ [])

@spec new(
  String.t(),
  keyword()
) :: t()

Creates a new Tenant struct.

Options

  • :activity_status - Initial activity status (default: :active)

Examples

tenant = Tenant.new("customer_123")
tenant = Tenant.new("customer_456", activity_status: :cold)

set_status(tenant, status)

@spec set_status(t(), activity_status()) :: t()

Sets the activity status of a tenant.

Examples

tenant = Tenant.new("customer_123")
tenant = Tenant.set_status(tenant, :cold)

to_map(tenant)

@spec to_map(t()) :: map()

Converts the tenant to a map for the Weaviate API.

Examples

tenant = Tenant.new("customer_123", activity_status: :cold)
Tenant.to_map(tenant)
# => %{"name" => "customer_123", "activityStatus" => "COLD"}

valid_status?(status)

@spec valid_status?(atom()) :: boolean()

Checks if a status is valid.

Examples

Tenant.valid_status?(:hot)
# => true

Tenant.valid_status?(:invalid)
# => false

valid_statuses()

@spec valid_statuses() :: [activity_status()]

Returns the list of valid activity statuses.

Examples

Tenant.valid_statuses()
# => [:active, :inactive, :hot, :cold, :frozen, :offloaded]

validate_status!(status)

@spec validate_status!(atom()) :: :ok | no_return()

Validates the activity status.

Raises ArgumentError if the status is invalid.

Examples

Tenant.validate_status!(:hot)
# => :ok

Tenant.validate_status!(:invalid)
# ** (ArgumentError) Invalid activity_status: :invalid. Must be one of [:active, :inactive, :hot, :cold, :frozen, :offloaded]