Sparta spanner library
Project description
sparta-spanner
Sparta Google Spanner library.
Usage
import os
import sparta.spanner
from sparta.spanner.utils import zip_results
project_id = os.getenv("PROJECT_ID")
instance_id = os.getenv("INSTANCE_ID")
database_id = os.getenv("DATABASE_ID")
db_service = sparta.spanner.DBService(
project_id=project_id,
instance_id=instance_id,
database_id=database_id,
pool_size=5,
session_request_timeout=2,
)
# Blocking
results = zip_results(db_service.execute_sql("SELECT 1 as my_field"))
assert results is not None
assert len(results) == 1
assert results[0] == {"my_field": 1}
# Non-Blocking
def task(snapshot):
result1 = zip_results(snapshot.execute_sql("SELECT 1 as my_field"))
result2 = zip_results(snapshot.execute_sql("SELECT 2 as my_field"))
return result1 + result2
results = await db_service.run_in_snapshot(task, multi_use=True)
assert results is not None
assert len(results) == 2
assert results[0] == {"my_field": 1}
assert results[1] == {"my_field": 2}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sparta-spanner-0.0.6.tar.gz
(7.3 kB
view hashes)
Built Distribution
Close
Hashes for sparta_spanner-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 721b87bafc19f6a72101878631f0866b067fbf93616ff1c496276ed86e7b58b7 |
|
MD5 | 203572ff3e28c18d7d2f3858c02c1128 |
|
BLAKE2b-256 | 9df599be6349c052da2d55ad3d392f1f4bd21d86dd08491e3fa5ddaab11e3f61 |