@@ -605,7 +605,13 @@ def cursor_to_dict(cursor: Cursor) -> List[Dict[str, Any]]:
605
605
results = [dict (zip (col_headers , row )) for row in cursor ]
606
606
return results
607
607
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 :
609
615
"""Runs a single query for a result set.
610
616
611
617
Args:
@@ -614,7 +620,7 @@ def execute(self, desc: str, decoder: Callable, query: str, *args: Any):
614
620
query - The query string to execute
615
621
*args - Query args.
616
622
Returns:
617
- Deferred which results to the result of decoder(results)
623
+ The result of decoder(results)
618
624
"""
619
625
620
626
def interaction (txn ):
@@ -624,7 +630,7 @@ def interaction(txn):
624
630
else :
625
631
return txn .fetchall ()
626
632
627
- return self .runInteraction (desc , interaction )
633
+ return await self .runInteraction (desc , interaction )
628
634
629
635
# "Simple" SQL API methods that operate on a single table with no JOINs,
630
636
# no complex WHERE clauses, just a dict of values for columns.
@@ -673,15 +679,30 @@ def simple_insert_txn(
673
679
674
680
txn .execute (sql , vals )
675
681
676
- def simple_insert_many (
682
+ async def simple_insert_many (
677
683
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 )
680
693
681
694
@staticmethod
682
695
def simple_insert_many_txn (
683
696
txn : LoggingTransaction , table : str , values : List [Dict [str , Any ]]
684
697
) -> 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
+ """
685
706
if not values :
686
707
return
687
708
@@ -1397,17 +1418,17 @@ def simple_select_one_txn(
1397
1418
1398
1419
return dict (zip (retcols , row ))
1399
1420
1400
- def simple_delete_one (
1421
+ async def simple_delete_one (
1401
1422
self , table : str , keyvalues : Dict [str , Any ], desc : str = "simple_delete_one"
1402
- ) -> defer . Deferred :
1423
+ ) -> None :
1403
1424
"""Executes a DELETE query on the named table, expecting to delete a
1404
1425
single row.
1405
1426
1406
1427
Args:
1407
1428
table: string giving the table name
1408
1429
keyvalues: dict of column names and values to select the row with
1409
1430
"""
1410
- return self .runInteraction (desc , self .simple_delete_one_txn , table , keyvalues )
1431
+ await self .runInteraction (desc , self .simple_delete_one_txn , table , keyvalues )
1411
1432
1412
1433
@staticmethod
1413
1434
def simple_delete_one_txn (
@@ -1446,15 +1467,15 @@ def simple_delete_txn(
1446
1467
txn .execute (sql , list (keyvalues .values ()))
1447
1468
return txn .rowcount
1448
1469
1449
- def simple_delete_many (
1470
+ async def simple_delete_many (
1450
1471
self ,
1451
1472
table : str ,
1452
1473
column : str ,
1453
1474
iterable : Iterable [Any ],
1454
1475
keyvalues : Dict [str , Any ],
1455
1476
desc : str ,
1456
- ) -> defer . Deferred :
1457
- return self .runInteraction (
1477
+ ) -> int :
1478
+ return await self .runInteraction (
1458
1479
desc , self .simple_delete_many_txn , table , column , iterable , keyvalues
1459
1480
)
1460
1481
@@ -1537,52 +1558,6 @@ def get_cache_dict(
1537
1558
1538
1559
return cache , min_val
1539
1560
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
-
1586
1561
@classmethod
1587
1562
def simple_select_list_paginate_txn (
1588
1563
cls ,
@@ -1647,14 +1622,14 @@ def simple_select_list_paginate_txn(
1647
1622
1648
1623
return cls .cursor_to_dict (txn )
1649
1624
1650
- def simple_search_list (
1625
+ async def simple_search_list (
1651
1626
self ,
1652
1627
table : str ,
1653
1628
term : Optional [str ],
1654
1629
col : str ,
1655
1630
retcols : Iterable [str ],
1656
1631
desc = "simple_search_list" ,
1657
- ):
1632
+ ) -> Optional [ List [ Dict [ str , Any ]]] :
1658
1633
"""Executes a SELECT query on the named table, which may return zero or
1659
1634
more rows, returning the result as a list of dicts.
1660
1635
@@ -1665,10 +1640,10 @@ def simple_search_list(
1665
1640
retcols: the names of the columns to return
1666
1641
1667
1642
Returns:
1668
- defer.Deferred: resolves to list[dict[str, Any]] or None
1643
+ A list of dictionaries or None.
1669
1644
"""
1670
1645
1671
- return self .runInteraction (
1646
+ return await self .runInteraction (
1672
1647
desc , self .simple_search_list_txn , table , term , col , retcols
1673
1648
)
1674
1649
0 commit comments