I need to keep YDB handler() function and execute SQL query simultaneously. But standart code from documentation only suggests static data to upsert. My task is to pass dynamic one. Is there a way to skip handle() or add arguments to execute_query()?
# Create the session pool instance to manage YDB sessions.
pool = ydb.SessionPool(driver)
def execute_query(session):
# Create the transaction and execute query.
return session.transaction().execute(
'select 1 as cnt;',
commit_tx=True,
settings=ydb.BaseRequestSettings().with_timeout(3).with_operation_timeout(2)
)
def handler(event, context):
# Execute query with the retry_operation helper.
result = pool.retry_operation_sync(execute_query)
return {
'statusCode': 200,
'body': str(result[0].rows[0].cnt == 1),
}
When I pass dynamic_arg like this i get an error: execute_query() missing 1 required positional argument: 'dynamic_arg'
dynamic_arg = somefunc()
def execute_query(session, dynamic_arg):
# Выполним SQL-запрос
return session.transaction().execute(
f"""
UPSERT INTO tproger (date, engagementRate, reactionsMedian, subscribers, subscriptions, subscriptionsPct, unsubscriptions, unsubscriptionsPct, views, wau) VALUES
({dynamic_arg}, 1, 2, 3, 4, 5, 6, 7, 8, 9);
""",
commit_tx=True,
settings=ydb.BaseRequestSettings().with_timeout(3).with_operation_timeout(2)
)
def handler():
# Исполним запрос с retry_operation helper
result = pool.retry_operation_sync(execute_query(dynamic_arg))
return {
'statusCode': 200,
'body': str(result[0].rows[0].cnt == 1),
}