@@ -10,6 +10,12 @@ class QueryResult:
1010 def result (self : Self ) -> list [dict [Any , Any ]]:
1111 """Return result from database as a list of dicts."""
1212
13+ class SingleQueryResult :
14+ """Single result."""
15+
16+ def result (self : Self ) -> dict [Any , Any ]:
17+ """Return result from database as a dict."""
18+
1319class IsolationLevel (Enum ):
1420 """Class for Isolation Level for transactions."""
1521
@@ -269,6 +275,108 @@ class Transaction:
269275 # This way transaction begins and commits by itself.
270276 ```
271277 """
278+ async def execute_many (
279+ self : Self ,
280+ querystring : str ,
281+ parameters : list [list [Any ]] | None = None ,
282+ ) -> None : ...
283+ """Execute query multiple times with different parameters.
284+
285+ Querystring can contain `$<number>` parameters
286+ for converting them in the driver side.
287+
288+ ### Parameters:
289+ - `querystring`: querystring to execute.
290+ - `parameters`: list of list of parameters to pass in the query.
291+
292+ ### Example:
293+ ```python
294+ import asyncio
295+
296+ from psqlpy import PSQLPool, QueryResult
297+
298+
299+ async def main() -> None:
300+ db_pool = PSQLPool()
301+ await db_pool.startup()
302+
303+ transaction = await db_pool.transaction()
304+ await transaction.begin()
305+ query_result: QueryResult = await transaction.execute_many(
306+ "INSERT INTO users (name, age) VALUES ($1, $2)",
307+ [["boba", 10], ["boba", 20]],
308+ )
309+ dict_result: List[Dict[Any, Any]] = query_result.result()
310+ # You must call commit manually
311+ await transaction.commit()
312+
313+ # Or you can transaction as a async context manager
314+
315+ async def main() -> None:
316+ db_pool = PSQLPool()
317+ await psqlpy.startup()
318+
319+ transaction = await db_pool.transaction()
320+ async with transaction:
321+ query_result: QueryResult = await transaction.execute(
322+ "SELECT username FROM users WHERE id = $1",
323+ [100],
324+ )
325+ dict_result: List[Dict[Any, Any]] = query_result.result()
326+ # This way transaction begins and commits by itself.
327+ ```
328+ """
329+ async def fetch_row (
330+ self : Self ,
331+ querystring : str ,
332+ parameters : list [Any ] | None = None ,
333+ ) -> SingleQueryResult :
334+ """Execute the query and return first row.
335+
336+ Querystring can contain `$<number>` parameters
337+ for converting them in the driver side.
338+
339+ ### Parameters:
340+ - `querystring`: querystring to execute.
341+ - `parameters`: list of parameters to pass in the query.
342+
343+ ### Example:
344+ ```python
345+ import asyncio
346+
347+ from psqlpy import PSQLPool, QueryResult
348+
349+
350+ async def main() -> None:
351+ db_pool = PSQLPool()
352+ await db_pool.startup()
353+
354+ transaction = await db_pool.transaction()
355+ await transaction.begin()
356+ query_result: SingleQueryResult = await transaction.execute(
357+ "SELECT username FROM users WHERE id = $1",
358+ [100],
359+ )
360+ dict_result: Dict[Any, Any] = query_result.result()
361+ # You must call commit manually
362+ await transaction.commit()
363+
364+ # Or you can transaction as a async context manager
365+
366+ async def main() -> None:
367+ db_pool = PSQLPool()
368+ await psqlpy.startup()
369+
370+ transaction = await db_pool.transaction()
371+ async with transaction:
372+ query_result: SingleQueryResult = await transaction.execute(
373+ "SELECT username FROM users WHERE id = $1",
374+ [100],
375+ )
376+ dict_result: Dict[Any, Any] = query_result.result()
377+ # This way transaction begins and commits by itself.
378+ ```
379+ """
272380 async def savepoint (self : Self , savepoint_name : str ) -> None :
273381 """Create new savepoint.
274382
0 commit comments