Exemple #1
0
    def append(self, table: SoloHatsudenkiTable):
        self._check()
        query = {
            TransactionGetKind.Get.value: {
                'TableName': HatsudenkiClient.resolve_table_name(table.get_collection_name()),
                'Key': table.serialized_key
            }
        }

        self._task.append(query)
Exemple #2
0
 def exec_query(self, limit=100):
     query = defaultdict(lambda: {'Keys': []})
     w = 0
     for task in self._task:
         query[HatsudenkiClient.resolve_table_name(task.table_name)]['Keys'].append(task.keys)
         w += 1
         if w >= limit:
             r = dict(query)
             w = 0
             query.clear()
             yield HatsudenkiClient.batch_get_item(r)
     if w is not 0:
         yield HatsudenkiClient.batch_get_item(dict(query))
Exemple #3
0
    def append_put(self, table: SoloHatsudenkiTable, overwrite=False):
        self._check()
        cond = table.not_exist_condition() if not overwrite else None

        query = {
            TransactionWriteKind.Put.value: {
                'TableName': HatsudenkiClient.resolve_table_name(table.get_collection_name()),
                'Item': table.serialize(),

                **(cond.to_parameter() if cond is not None else {})
            }
        }

        self._task.append(query)
Exemple #4
0
    def get(self, target_table_type: Type[T]) -> List[T]:
        col_items = self.result[HatsudenkiClient.resolve_table_name(target_table_type.get_collection_name())]
        tt = target_table_type.get_table_type()

        if tt in {TableType.RootTable, TableType.SingleSoloTable, TableType.SingleMultiTable}:
            yield from (target_table_type.deserialize(c) for c in col_items)
            return

        for item in col_items:
            if tt is TableType.ChildTable:
                if item[target_table_type.get_range_key_name()]['S'].startswith(target_table_type.get_tag_name()):
                    yield target_table_type.deserialize(item)
            elif tt is TableType.ChildSoloTable:
                if item[target_table_type.get_range_key_name()]['S'] == target_table_type.get_tag_name():
                    yield target_table_type.deserialize(item)
Exemple #5
0
    def append_update(self, table: SoloHatsudenkiTable):
        self._check()
        upd = UpdateExpression()

        table.build_update_expression(upd)
        cond = table.exist_condition()

        upd.add('_v', 1)
        cond.op_and()
        with cond:
            cond.equal('_v', table._v)
            cond.op_or()
            cond.attribute_exists('_v')
        key = table.serialized_key

        query = {
            TransactionWriteKind.Update.value: {
                'TableName': HatsudenkiClient.resolve_table_name(table.get_collection_name()),
                'Key': key,
                **(upd.to_parameter(cond))
            }
        }

        self._task.append(query)
Exemple #6
0
 def real_table_name(self):
     return HatsudenkiClient.resolve_table_name(self.table_name)