Skip to content

Commit

Permalink
Added some more types, refs #266, #290
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 24, 2021
1 parent 33c9d00 commit 747be60
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sqlite_utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from sqlite_fts4 import rank_bm25 # type: ignore
import sys
import textwrap
from typing import Generator, Iterable, Union, Optional, List
import uuid

SQLITE_MAX_VARS = 999
Expand Down Expand Up @@ -359,13 +360,17 @@ def reset_counts(self):
for table in tables
)

def query(self, sql, params=None):
def query(
self, sql: str, params: Optional[Union[Iterable, dict]] = None
) -> Generator[dict, None, None]:
cursor = self.execute(sql, params or tuple())
keys = [d[0] for d in cursor.description]
for row in cursor:
yield dict(zip(keys, row))

def execute_returning_dicts(self, sql, params=None):
def execute_returning_dicts(
self, sql: str, params: Optional[Union[Iterable, dict]] = None
) -> List[dict]:
return list(self.query(sql, params))

def resolve_foreign_keys(self, name, foreign_keys):
Expand Down

0 comments on commit 747be60

Please sign in to comment.