示例#1
0
 def db_get_item_id_and_orders(self,
                               partition,
                               field,
                               value,
                               order_by='creation_date',
                               order_min=None,
                               order_max=None,
                               start_key=None,
                               limit=100,
                               reverse=False):
     # order_field 가 'creation_date' 이 아니면 아직 사용 불가능
     if isinstance(start_key, str):
         start_key = json.loads(start_key)
     dynamo = DynamoDB(self.boto3_session)
     response = dynamo.get_inverted_queries(self.app_id, partition, field,
                                            value, 'eq', order_by,
                                            order_min, order_max, start_key,
                                            limit, reverse)
     items = response.get('Items', [])
     end_key = response.get('LastEvaluatedKey', None)
     item_id_and_creation_date_list = [{
         'item_id': item.get('item_id'),
         order_by: item.get(order_by)
     } for item in items]
     if end_key is not None:
         end_key = json.dumps(encode_dict(end_key))
     return item_id_and_creation_date_list, end_key
示例#2
0
 def __init__(self, credential, app_id, boto3_session=None):
     super(AWSResource, self).__init__(credential, app_id)
     if boto3_session:
         self.boto3_session = boto3_session
     elif credential:
         self.boto3_session = get_boto3_session(credential)
     self.dynamo = DynamoDB(self.boto3_session)
     self.s3 = S3(self.boto3_session)
示例#3
0
 def db_get_items_in_partition(self, partition, order_by='creation_date', order_min=None, order_max=None, start_key=None, limit=100, reverse=False):
     if isinstance(start_key, str):
         start_key = json.loads(start_key)
     dynamo = DynamoDB(self.boto3_session)
     result = dynamo.get_items_in_partition_by_order(self.app_id, partition, order_by, order_min, order_max, start_key, limit, reverse)
     end_key = result.get('LastEvaluatedKey', None)
     items = result.get('Items', [])
     if end_key is not None:
         end_key = json.dumps(encode_dict(end_key))
     return items, end_key
示例#4
0
 def db_get_count(self, partition, field=None, value=None):
     """
     Returns the number of items that satisfy the condition field == value
     :param partition: Partition to count
     :param field: Field name to check out
     :param value: Field value to find out
     :return:
     """
     dynamo = DynamoDB(self.boto3_session)
     if field and value:
         count_id = '{}-{}-{}-count'.format(partition, field, value)
     else:
         count_id = '{}-count'.format(partition)
     item = dynamo.get_item_count(self.app_id, count_id).get('Item', {'count': 0})
     count = item.get('count')
     return count
示例#5
0
 def _create_dynamo_db_table(self):
     dynamo = DynamoDB(self.boto3_session)
     dynamo.init_table(self.app_id)
示例#6
0
 def db_update_item(self, item_id, item):
     dynamo = DynamoDB(self.boto3_session)
     item = decode_dict(item)
     result = dynamo.update_item(self.app_id, item_id, item)
     return bool(result)
示例#7
0
 def db_put_item(self, partition, item, item_id=None, creation_date=None):
     dynamo = DynamoDB(self.boto3_session)
     item = decode_dict(item)
     result = dynamo.put_item(self.app_id, partition, item, item_id, creation_date)
     return bool(result)
示例#8
0
 def db_get_items(self, item_ids):
     dynamo = DynamoDB(self.boto3_session)
     result = dynamo.get_items(self.app_id, item_ids)
     return result.get('Items', [])
示例#9
0
 def db_get_item(self, item_id):
     dynamo = DynamoDB(self.boto3_session)
     item = dynamo.get_item(self.app_id, item_id)
     return item.get('Item', None)
示例#10
0
 def db_delete_item_batch(self, item_ids):
     result = True
     dynamo = DynamoDB(self.boto3_session)
     for item_id in item_ids:
         result &= bool(dynamo.delete_item(self.app_id, item_id))
     return result
示例#11
0
 def db_delete_item(self, item_id):
     dynamo = DynamoDB(self.boto3_session)
     result = dynamo.delete_item(self.app_id, item_id)
     return bool(result)
示例#12
0
 def db_get_partitions(self):
     dynamo = DynamoDB(self.boto3_session)
     response = dynamo.get_partitions(self.app_id)
     items = response.get('Items', [])
     return items
示例#13
0
 def db_has_partition(self, partition):
     dynamo = DynamoDB(self.boto3_session)
     response = dynamo.get_partition(self.app_id, partition)
     return bool(response)
示例#14
0
 def _remove_dynamo_db_table(self):
     dynamo = DynamoDB(self.boto3_session)
     dynamo.delete_table(self.app_id)