Module: DynamoDbFramework::Table
- Defined in:
- lib/dynamodb_framework/dynamodb_table.rb
Defined Under Namespace
Classes: InvalidConfigException
Instance Method Summary
collapse
-
#all(store:) ⇒ Object
-
#config ⇒ Object
-
#create(store:, read_capacity: 25, write_capacity: 25) ⇒ Object
-
#delete_item(store:, partition:, range: nil) ⇒ Object
-
#drop(store:) ⇒ Object
-
#exists?(store:) ⇒ Boolean
-
#full_table_name ⇒ Object
-
#get_item(store:, partition:, range: nil) ⇒ Object
-
#partition_key(field, type) ⇒ Object
-
#put_item(store:, item:) ⇒ Object
-
#query(partition:) ⇒ Object
-
#range_key(field, type) ⇒ Object
-
#table_name(value) ⇒ Object
-
#update(store:, read_capacity:, write_capacity:) ⇒ Object
Instance Method Details
#all(store:) ⇒ Object
79
80
81
82
83
|
# File 'lib/dynamodb_framework/dynamodb_table.rb', line 79
def all(store:)
repository = DynamoDbFramework::Repository.new(store)
repository.table_name = config[:table_name]
repository.all
end
|
#config ⇒ Object
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/dynamodb_framework/dynamodb_table.rb', line 10
def config
details = {
table_name: full_table_name,
partition_key: self.instance_variable_get(:@partition_key)
}
if self.instance_variable_defined?(:@range_key)
details[:range_key] = self.instance_variable_get(:@range_key)
end
details
end
|
#create(store:, read_capacity: 25, write_capacity: 25) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/dynamodb_framework/dynamodb_table.rb', line 44
def create(store:, read_capacity: 25, write_capacity: 25)
unless self.instance_variable_defined?(:@partition_key)
raise DynamoDbFramework::Table::InvalidConfigException.new('Partition key must be specified.')
end
partition_key = self.instance_variable_get(:@partition_key)
if self.instance_variable_defined?(:@range_key)
range_key = self.instance_variable_get(:@range_key)
end
builder = DynamoDbFramework::AttributesBuilder.new
builder.add({ name: partition_key[:field], type: partition_key[:type], key: :partition })
if range_key != nil
builder.add({ name: range_key[:field], type: range_key[:type], key: :range })
end
DynamoDbFramework::TableManager.new(store).create_table({ name: full_table_name, attributes: builder.attributes, read_capacity: read_capacity, write_capacity: write_capacity })
end
|
#delete_item(store:, partition:, range: nil) ⇒ Object
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/dynamodb_framework/dynamodb_table.rb', line 102
def delete_item(store:, partition:, range: nil)
repository = DynamoDbFramework::Repository.new(store)
repository.table_name = config[:table_name]
if range != nil
range_key = config[:range_key][:field]
end
repository.delete_item(partition_key: config[:partition_key][:field], partition_key_value: partition, range_key: range_key, range_key_value: range)
end
|
#exists?(store:) ⇒ Boolean
#full_table_name ⇒ Object
#get_item(store:, partition:, range: nil) ⇒ Object
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/dynamodb_framework/dynamodb_table.rb', line 91
def get_item(store:, partition:, range: nil)
repository = DynamoDbFramework::Repository.new(store)
repository.table_name = config[:table_name]
if range != nil
repository.get_by_key(config[:partition_key][:field], partition, config[:range_key][:field], range)
else
repository.get_by_key(config[:partition_key][:field], partition)
end
end
|
#partition_key(field, type) ⇒ Object
36
37
38
|
# File 'lib/dynamodb_framework/dynamodb_table.rb', line 36
def partition_key(field, type)
self.instance_variable_set(:@partition_key, { field: field, type: type })
end
|
#put_item(store:, item:) ⇒ Object
85
86
87
88
89
|
# File 'lib/dynamodb_framework/dynamodb_table.rb', line 85
def put_item(store:, item:)
repository = DynamoDbFramework::Repository.new(store)
repository.table_name = config[:table_name]
repository.put(item)
end
|
#query(partition:) ⇒ Object
75
76
77
|
# File 'lib/dynamodb_framework/dynamodb_table.rb', line 75
def query(partition:)
DynamoDbFramework::Query.new(table_name: config[:table_name], partition_key: config[:partition_key][:field], partition_value: partition)
end
|
#range_key(field, type) ⇒ Object
40
41
42
|
# File 'lib/dynamodb_framework/dynamodb_table.rb', line 40
def range_key(field, type)
self.instance_variable_set(:@range_key, { field: field, type: type })
end
|
#table_name(value) ⇒ Object
21
22
23
|
# File 'lib/dynamodb_framework/dynamodb_table.rb', line 21
def table_name(value)
self.instance_variable_set(:@table_name, value)
end
|
#update(store:, read_capacity:, write_capacity:) ⇒ Object