-
Notifications
You must be signed in to change notification settings - Fork 431
/
Copy pathtable.py
320 lines (301 loc) · 12 KB
/
table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
"""
PynamoDB Connection classes
~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
from pynamodb.connection.base import Connection
class TableConnection(object):
"""
A higher level abstraction over botocore
"""
def __init__(self,
table_name,
region=None,
host=None,
connect_timeout_seconds=None,
read_timeout_seconds=None,
max_retry_attempts=None,
base_backoff_ms=None,
max_pool_connections=None,
extra_headers=None,
aws_access_key_id=None,
aws_secret_access_key=None,
dax_write_endpoints=None,
dax_read_endpoints=None,
fall_back_to_dynamodb=False):
if not dax_read_endpoints:
dax_read_endpoints = []
if not dax_write_endpoints:
dax_write_endpoints = []
self._hash_keyname = None
self._range_keyname = None
self.table_name = table_name
self.connection = Connection(region=region,
host=host,
connect_timeout_seconds=connect_timeout_seconds,
read_timeout_seconds=read_timeout_seconds,
max_retry_attempts=max_retry_attempts,
base_backoff_ms=base_backoff_ms,
max_pool_connections=max_pool_connections,
extra_headers=extra_headers,
base_backoff_ms=base_backoff_ms,
dax_write_endpoints=dax_write_endpoints,
dax_read_endpoints=dax_read_endpoints,
fall_back_to_dynamodb=fall_back_to_dynamodb)
if aws_access_key_id and aws_secret_access_key:
self.connection.session.set_credentials(aws_access_key_id,
aws_secret_access_key)
def get_meta_table(self, refresh=False):
"""
Returns a MetaTable
"""
return self.connection.get_meta_table(self.table_name, refresh=refresh)
def delete_item(self, hash_key,
range_key=None,
condition=None,
expected=None,
conditional_operator=None,
return_values=None,
return_consumed_capacity=None,
return_item_collection_metrics=None):
"""
Performs the DeleteItem operation and returns the result
"""
return self.connection.delete_item(
self.table_name,
hash_key,
range_key=range_key,
condition=condition,
expected=expected,
conditional_operator=conditional_operator,
return_values=return_values,
return_consumed_capacity=return_consumed_capacity,
return_item_collection_metrics=return_item_collection_metrics)
def update_item(self,
hash_key,
range_key=None,
actions=None,
attribute_updates=None,
condition=None,
expected=None,
conditional_operator=None,
return_consumed_capacity=None,
return_item_collection_metrics=None,
return_values=None
):
"""
Performs the UpdateItem operation
"""
return self.connection.update_item(
self.table_name,
hash_key,
range_key=range_key,
actions=actions,
attribute_updates=attribute_updates,
condition=condition,
expected=expected,
conditional_operator=conditional_operator,
return_consumed_capacity=return_consumed_capacity,
return_item_collection_metrics=return_item_collection_metrics,
return_values=return_values)
def put_item(self, hash_key,
range_key=None,
attributes=None,
condition=None,
expected=None,
conditional_operator=None,
return_values=None,
return_consumed_capacity=None,
return_item_collection_metrics=None):
"""
Performs the PutItem operation and returns the result
"""
return self.connection.put_item(
self.table_name,
hash_key,
range_key=range_key,
attributes=attributes,
condition=condition,
expected=expected,
conditional_operator=conditional_operator,
return_values=return_values,
return_consumed_capacity=return_consumed_capacity,
return_item_collection_metrics=return_item_collection_metrics)
def batch_write_item(self,
put_items=None,
delete_items=None,
return_consumed_capacity=None,
return_item_collection_metrics=None):
"""
Performs the batch_write_item operation
"""
return self.connection.batch_write_item(
self.table_name,
put_items=put_items,
delete_items=delete_items,
return_consumed_capacity=return_consumed_capacity,
return_item_collection_metrics=return_item_collection_metrics)
def batch_get_item(self, keys, consistent_read=None, return_consumed_capacity=None, attributes_to_get=None):
"""
Performs the batch get item operation
"""
return self.connection.batch_get_item(
self.table_name,
keys,
consistent_read=consistent_read,
return_consumed_capacity=return_consumed_capacity,
attributes_to_get=attributes_to_get)
def get_item(self, hash_key, range_key=None, consistent_read=False, attributes_to_get=None):
"""
Performs the GetItem operation and returns the result
"""
return self.connection.get_item(
self.table_name,
hash_key,
range_key=range_key,
consistent_read=consistent_read,
attributes_to_get=attributes_to_get)
def rate_limited_scan(
self,
filter_condition=None,
attributes_to_get=None,
page_size=None,
limit=None,
conditional_operator=None,
scan_filter=None,
segment=None,
total_segments=None,
exclusive_start_key=None,
timeout_seconds=None,
read_capacity_to_consume_per_second=None,
allow_rate_limited_scan_without_consumed_capacity=None,
max_sleep_between_retry=None,
max_consecutive_exceptions=None,
consistent_read=None,
index_name=None):
"""
Performs the scan operation with rate limited
"""
return self.connection.rate_limited_scan(
self.table_name,
filter_condition=filter_condition,
attributes_to_get=attributes_to_get,
page_size=page_size,
limit=limit,
conditional_operator=conditional_operator,
scan_filter=scan_filter,
segment=segment,
total_segments=total_segments,
exclusive_start_key=exclusive_start_key,
timeout_seconds=timeout_seconds,
read_capacity_to_consume_per_second=read_capacity_to_consume_per_second,
allow_rate_limited_scan_without_consumed_capacity=allow_rate_limited_scan_without_consumed_capacity,
max_sleep_between_retry=max_sleep_between_retry,
max_consecutive_exceptions=max_consecutive_exceptions,
consistent_read=consistent_read,
index_name=index_name)
def scan(self,
filter_condition=None,
attributes_to_get=None,
limit=None,
conditional_operator=None,
scan_filter=None,
return_consumed_capacity=None,
segment=None,
total_segments=None,
exclusive_start_key=None,
consistent_read=None,
index_name=None):
"""
Performs the scan operation
"""
return self.connection.scan(
self.table_name,
filter_condition=filter_condition,
attributes_to_get=attributes_to_get,
limit=limit,
conditional_operator=conditional_operator,
scan_filter=scan_filter,
return_consumed_capacity=return_consumed_capacity,
segment=segment,
total_segments=total_segments,
exclusive_start_key=exclusive_start_key,
consistent_read=consistent_read,
index_name=index_name)
def query(self,
hash_key,
range_key_condition=None,
filter_condition=None,
attributes_to_get=None,
consistent_read=False,
exclusive_start_key=None,
index_name=None,
key_conditions=None,
query_filters=None,
limit=None,
return_consumed_capacity=None,
scan_index_forward=None,
conditional_operator=None,
select=None
):
"""
Performs the Query operation and returns the result
"""
return self.connection.query(
self.table_name,
hash_key,
range_key_condition=range_key_condition,
filter_condition=filter_condition,
attributes_to_get=attributes_to_get,
consistent_read=consistent_read,
exclusive_start_key=exclusive_start_key,
index_name=index_name,
key_conditions=key_conditions,
query_filters=query_filters,
limit=limit,
return_consumed_capacity=return_consumed_capacity,
scan_index_forward=scan_index_forward,
conditional_operator=conditional_operator,
select=select)
def describe_table(self):
"""
Performs the DescribeTable operation and returns the result
"""
return self.connection.describe_table(self.table_name)
def delete_table(self):
"""
Performs the DeleteTable operation and returns the result
"""
return self.connection.delete_table(self.table_name)
def update_table(self,
read_capacity_units=None,
write_capacity_units=None,
global_secondary_index_updates=None):
"""
Performs the UpdateTable operation and returns the result
"""
return self.connection.update_table(
self.table_name,
read_capacity_units=read_capacity_units,
write_capacity_units=write_capacity_units,
global_secondary_index_updates=global_secondary_index_updates)
def create_table(self,
attribute_definitions=None,
key_schema=None,
read_capacity_units=None,
write_capacity_units=None,
global_secondary_indexes=None,
local_secondary_indexes=None,
stream_specification=None):
"""
Performs the CreateTable operation and returns the result
"""
return self.connection.create_table(
self.table_name,
attribute_definitions=attribute_definitions,
key_schema=key_schema,
read_capacity_units=read_capacity_units,
write_capacity_units=write_capacity_units,
global_secondary_indexes=global_secondary_indexes,
local_secondary_indexes=local_secondary_indexes,
stream_specification=stream_specification
)