mirror of
https://github.com/hanzo-ds/connect.git
synced 2026-10-30 20:31:24 +00:00
Imports read `datastore_connect`, distribution `datastore-connect`, so nothing has to import another product's name to talk to Hanzo Datastore. Cut from upstream 0.8.17 — the version this stack already ran — rather than from upstream HEAD, so it is a PURE RENAME with no behaviour change. Forking from HEAD would have dragged versions along with the name (connect alone jumped 0.8.17 -> 1.6.0, a major), which is a different and much riskier change wearing a rename's clothes. X-ClickHouse-* headers are untouched: they are wire protocol the server sends and expects, and a different token shape from the module name.
30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
from typing import Callable
|
|
|
|
from datastore_connect.driver import Client
|
|
|
|
|
|
def test_contexts(test_client: Client, table_context: Callable):
|
|
with table_context('test_contexts', ['key Int32', 'value1 String', 'value2 String']) as ctx:
|
|
data = [[1, 'v1', 'v2'], [2, 'v3', 'v4']]
|
|
insert_context = test_client.create_insert_context(table=ctx.table, data=data)
|
|
test_client.insert(context=insert_context)
|
|
query_context = test_client.create_query_context(
|
|
query=f'SELECT value1, value2 FROM {ctx.table} WHERE key = {{k:Int32}}',
|
|
parameters={'k': 2},
|
|
column_oriented=True)
|
|
result = test_client.query(context=query_context)
|
|
assert result.result_set[1][0] == 'v4'
|
|
query_context.set_parameter('k', 1)
|
|
result = test_client.query(context=query_context)
|
|
assert result.row_count == 1
|
|
assert result.result_set[1][0]
|
|
|
|
data = [[1, 'v5', 'v6'], [2, 'v7', 'v8']]
|
|
test_client.insert(data=data, context=insert_context)
|
|
result = test_client.query(context=query_context)
|
|
assert result.row_count == 2
|
|
|
|
insert_context.data = [[5, 'v5', 'v6'], [7, 'v7', 'v8']]
|
|
test_client.insert(context=insert_context)
|
|
assert test_client.command(f'SELECT count() FROM {ctx.table}') == 6
|