@@ -605,7 +605,13 @@ def cursor_to_dict(cursor: Cursor) -> List[Dict[str, Any]]:
605605 results = [dict (zip (col_headers , row )) for row in cursor ]
606606 return results
607607
608- def execute (self , desc : str , decoder : Callable , query : str , * args : Any ):
608+ async def execute (
609+ self ,
610+ desc : str ,
611+ decoder : Optional [Callable [[Cursor ], R ]],
612+ query : str ,
613+ * args : Any
614+ ) -> R :
609615 """Runs a single query for a result set.
610616
611617 Args:
@@ -614,7 +620,7 @@ def execute(self, desc: str, decoder: Callable, query: str, *args: Any):
614620 query - The query string to execute
615621 *args - Query args.
616622 Returns:
617- Deferred which results to the result of decoder(results)
623+ The result of decoder(results)
618624 """
619625
620626 def interaction (txn ):
@@ -624,7 +630,7 @@ def interaction(txn):
624630 else :
625631 return txn .fetchall ()
626632
627- return self .runInteraction (desc , interaction )
633+ return await self .runInteraction (desc , interaction )
628634
629635 # "Simple" SQL API methods that operate on a single table with no JOINs,
630636 # no complex WHERE clauses, just a dict of values for columns.
@@ -673,15 +679,30 @@ def simple_insert_txn(
673679
674680 txn .execute (sql , vals )
675681
676- def simple_insert_many (
682+ async def simple_insert_many (
677683 self , table : str , values : List [Dict [str , Any ]], desc : str
678- ) -> defer .Deferred :
679- return self .runInteraction (desc , self .simple_insert_many_txn , table , values )
684+ ) -> None :
685+ """Executes an INSERT query on the named table.
686+
687+ Args:
688+ table: string giving the table name
689+ values: dict of new column names and values for them
690+ desc: string giving a description of the transaction
691+ """
692+ await self .runInteraction (desc , self .simple_insert_many_txn , table , values )
680693
681694 @staticmethod
682695 def simple_insert_many_txn (
683696 txn : LoggingTransaction , table : str , values : List [Dict [str , Any ]]
684697 ) -> None :
698+ """Executes an INSERT query on the named table.
699+
700+ Args:
701+ txn: The transaction to use.
702+ table: string giving the table name
703+ values: dict of new column names and values for them
704+ desc: string giving a description of the transaction
705+ """
685706 if not values :
686707 return
687708
@@ -1397,17 +1418,17 @@ def simple_select_one_txn(
13971418
13981419 return dict (zip (retcols , row ))
13991420
1400- def simple_delete_one (
1421+ async def simple_delete_one (
14011422 self , table : str , keyvalues : Dict [str , Any ], desc : str = "simple_delete_one"
1402- ) -> defer . Deferred :
1423+ ) -> None :
14031424 """Executes a DELETE query on the named table, expecting to delete a
14041425 single row.
14051426
14061427 Args:
14071428 table: string giving the table name
14081429 keyvalues: dict of column names and values to select the row with
14091430 """
1410- return self .runInteraction (desc , self .simple_delete_one_txn , table , keyvalues )
1431+ await self .runInteraction (desc , self .simple_delete_one_txn , table , keyvalues )
14111432
14121433 @staticmethod
14131434 def simple_delete_one_txn (
@@ -1446,15 +1467,15 @@ def simple_delete_txn(
14461467 txn .execute (sql , list (keyvalues .values ()))
14471468 return txn .rowcount
14481469
1449- def simple_delete_many (
1470+ async def simple_delete_many (
14501471 self ,
14511472 table : str ,
14521473 column : str ,
14531474 iterable : Iterable [Any ],
14541475 keyvalues : Dict [str , Any ],
14551476 desc : str ,
1456- ) -> defer . Deferred :
1457- return self .runInteraction (
1477+ ) -> int :
1478+ return await self .runInteraction (
14581479 desc , self .simple_delete_many_txn , table , column , iterable , keyvalues
14591480 )
14601481
@@ -1537,52 +1558,6 @@ def get_cache_dict(
15371558
15381559 return cache , min_val
15391560
1540- def simple_select_list_paginate (
1541- self ,
1542- table : str ,
1543- orderby : str ,
1544- start : int ,
1545- limit : int ,
1546- retcols : Iterable [str ],
1547- filters : Optional [Dict [str , Any ]] = None ,
1548- keyvalues : Optional [Dict [str , Any ]] = None ,
1549- order_direction : str = "ASC" ,
1550- desc : str = "simple_select_list_paginate" ,
1551- ) -> defer .Deferred :
1552- """
1553- Executes a SELECT query on the named table with start and limit,
1554- of row numbers, which may return zero or number of rows from start to limit,
1555- returning the result as a list of dicts.
1556-
1557- Args:
1558- table: the table name
1559- orderby: Column to order the results by.
1560- start: Index to begin the query at.
1561- limit: Number of results to return.
1562- retcols: the names of the columns to return
1563- filters:
1564- column names and values to filter the rows with, or None to not
1565- apply a WHERE ? LIKE ? clause.
1566- keyvalues:
1567- column names and values to select the rows with, or None to not
1568- apply a WHERE clause.
1569- order_direction: Whether the results should be ordered "ASC" or "DESC".
1570- Returns:
1571- defer.Deferred: resolves to list[dict[str, Any]]
1572- """
1573- return self .runInteraction (
1574- desc ,
1575- self .simple_select_list_paginate_txn ,
1576- table ,
1577- orderby ,
1578- start ,
1579- limit ,
1580- retcols ,
1581- filters = filters ,
1582- keyvalues = keyvalues ,
1583- order_direction = order_direction ,
1584- )
1585-
15861561 @classmethod
15871562 def simple_select_list_paginate_txn (
15881563 cls ,
@@ -1647,14 +1622,14 @@ def simple_select_list_paginate_txn(
16471622
16481623 return cls .cursor_to_dict (txn )
16491624
1650- def simple_search_list (
1625+ async def simple_search_list (
16511626 self ,
16521627 table : str ,
16531628 term : Optional [str ],
16541629 col : str ,
16551630 retcols : Iterable [str ],
16561631 desc = "simple_search_list" ,
1657- ):
1632+ ) -> Optional [ List [ Dict [ str , Any ]]] :
16581633 """Executes a SELECT query on the named table, which may return zero or
16591634 more rows, returning the result as a list of dicts.
16601635
@@ -1665,10 +1640,10 @@ def simple_search_list(
16651640 retcols: the names of the columns to return
16661641
16671642 Returns:
1668- defer.Deferred: resolves to list[dict[str, Any]] or None
1643+ A list of dictionaries or None.
16691644 """
16701645
1671- return self .runInteraction (
1646+ return await self .runInteraction (
16721647 desc , self .simple_search_list_txn , table , term , col , retcols
16731648 )
16741649
0 commit comments