BigQuery Adapter¶
Tip
turu-bigquery
depends on google-cloud-bigquery.
Todo
turu-bigquery
does not support async
yet.
bigquery does not officially support async.
Installation¶
Usage¶
Basic Usage¶
import pydantic
import turu.bigquery
class User(pydantic.BaseModel):
id: int
name: str
connection = turu.bigquery.connect()
with connection.cursor() as cursor:
user = cursor.execute_map(
User,
"SELECT 1, 'taro'",
).fetchone()
assert user == User(id=1, name="taro")
Parameters Usage¶
format style¶
import pydantic
import turu.bigquery
class User(pydantic.BaseModel):
id: int
name: str
connection = turu.bigquery.connect()
with connection.cursor() as cursor:
user = cursor.execute_map(
User,
"SELECT %s, %s",
[1, "taro"],
).fetchone()
assert user == User(id=1, name="taro")
Warning
Official documentation says that "BigQuery supports qmark parameters", but it is not.
Keyword Parameters Usage¶
named style¶
import pydantic
import turu.bigquery
class User(pydantic.BaseModel):
id: int
name: str
connection = turu.bigquery.connect()
with connection.cursor() as cursor:
user = cursor.execute_map(
User,
"SELECT %(id)s, %(name)s",
{"id": 1, "name": "taro"},
).fetchone()
assert user == User(id=1, name="taro")
Info
bigquery supports "Providing explicit type information". Please see more information in official documentation.