Class: Cequel::Schema::Map

Inherits:
CollectionColumn show all
Defined in:
lib/cequel/schema/column.rb

Overview

A Map column

See Also:

Since:

  • 1.0.0

Instance Attribute Summary collapse

Attributes inherited from Column

#name, #type

Instance Method Summary collapse

Methods inherited from CollectionColumn

#collection_column?, #indexed?

Methods inherited from Column

#==, #clustering_column?, #collection_column?, #data_column?, #inspect, #key?, #partition_key?, #to_s, #type?

Constructor Details

#initialize(name, key_type, value_type) ⇒ Map

Returns a new instance of Map.

Parameters:

  • name (Symbol)

    name of this column

  • key_type (Type)

    type of the keys in the map

  • value_type (Type)

    type of the values in the map

Since:

  • 1.0.0



273
274
275
276
# File 'lib/cequel/schema/column.rb', line 273

def initialize(name, key_type, value_type)
  super(name, value_type)
  @key_type = key_type
end

Instance Attribute Details

#key_typeType (readonly)

Returns the type of keys in this map.

Returns:

  • (Type)

    the type of keys in this map

Since:

  • 1.0.0



265
266
267
# File 'lib/cequel/schema/column.rb', line 265

def key_type
  @key_type
end

Instance Method Details

#cast(value) ⇒ Hash

Returns hash with keys and values cast to correct type for column.

Parameters:

  • value

    the value to cast

Returns:

  • (Hash)

    hash with keys and values cast to correct type for column

Since:

  • 1.0.0



288
289
290
291
292
# File 'lib/cequel/schema/column.rb', line 288

def cast(value)
  value.each_with_object({}) do |(key, element), hash|
    hash[@key_type.cast(key)] = @type.cast(element)
  end
end

#to_cqlString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a CQL fragment representing this column in a table definition.

Returns:

  • (String)

    a CQL fragment representing this column in a table definition

Since:

  • 1.0.0



279
280
281
# File 'lib/cequel/schema/column.rb', line 279

def to_cql
  "#{@name} MAP <#{@key_type}, #{@type}>"
end