本文整理汇总了Python中cqlengine.query.BatchQuery类的典型用法代码示例。如果您正苦于以下问题:Python BatchQuery类的具体用法?Python BatchQuery怎么用?Python BatchQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BatchQuery类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_batch_is_executed
def test_batch_is_executed(self):
b = BatchQuery()
inst = TestMultiKeyModel.batch(b).create(partition=self.pkey, cluster=2, count=3, text='4')
with self.assertRaises(TestMultiKeyModel.DoesNotExist):
TestMultiKeyModel.get(partition=self.pkey, cluster=2)
b.execute()
示例2: test_delete_success_case
def test_delete_success_case(self):
inst = TestMultiKeyModel.create(partition=self.pkey, cluster=2, count=3, text='4')
b = BatchQuery()
inst.batch(b).delete()
TestMultiKeyModel.get(partition=self.pkey, cluster=2)
b.execute()
with self.assertRaises(TestMultiKeyModel.DoesNotExist):
TestMultiKeyModel.get(partition=self.pkey, cluster=2)
示例3: test_update_success_case
def test_update_success_case(self):
inst = TestMultiKeyModel.create(partition=self.pkey, cluster=2, count=3, text='4')
b = BatchQuery()
inst.count = 4
inst.batch(b).save()
inst2 = TestMultiKeyModel.get(partition=self.pkey, cluster=2)
assert inst2.count == 3
b.execute()
inst3 = TestMultiKeyModel.get(partition=self.pkey, cluster=2)
assert inst3.count == 4
示例4: Batch
class Batch(BatchQuery):
'''
Performs a batch of insert queries using async connections
'''
def __init__(self, **kwargs):
self.instances = []
self._batch = BatchQuery()
def batch_insert(self, model_instance):
self.instances.append(model_instance)
def __enter__(self):
return self
def add_query(self, query):
self._batch.add_query(query)
def add_callback(self, fn, *args, **kwargs):
raise TypeError('not supported')
def execute(self):
promises = []
session = get_session()
for instance in self.instances:
query = instance.__dmlquery__(instance.__class__, instance)
query.batch(self._batch)
query.save()
for query in self._batch.queries:
statement = SimpleStatement(str(query))
params = query.get_context()
promises.append(session.execute_async(statement, params))
return [r.result() for r in promises]
def __exit__(self, exc_type, exc_val, exc_tb):
self.execute()
示例5: test_callbacks_properly_execute_callables_and_tuples
def test_callbacks_properly_execute_callables_and_tuples(self):
call_history = []
def my_callback(*args, **kwargs):
call_history.append(args)
# adding on init:
batch = BatchQuery()
batch.add_callback(my_callback)
batch.add_callback(my_callback, 'more', 'args')
batch.execute()
assert len(call_history) == 2
assert [(), ('more', 'args')] == call_history
示例6: test_API_managing_callbacks
def test_API_managing_callbacks(self):
# Callbacks can be added at init and after
def my_callback(*args, **kwargs):
pass
# adding on init:
batch = BatchQuery()
batch.add_callback(my_callback)
batch.add_callback(my_callback, 2, named_arg='value')
batch.add_callback(my_callback, 1, 3)
assert batch._callbacks == [
(my_callback, (), {}),
(my_callback, (2,), {'named_arg':'value'}),
(my_callback, (1, 3), {})
]
示例7: test_empty_batch
def test_empty_batch(self):
b = BatchQuery()
b.execute()
with BatchQuery() as b:
pass
示例8: __init__
def __init__(self, **kwargs):
self.instances = []
self._batch = BatchQuery()