mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-27 12:24:11 +02:00
parent
33c9d00879
commit
747be6057d
1 changed files with 7 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ import re
|
||||||
from sqlite_fts4 import rank_bm25 # type: ignore
|
from sqlite_fts4 import rank_bm25 # type: ignore
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
from typing import Generator, Iterable, Union, Optional, List
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
SQLITE_MAX_VARS = 999
|
SQLITE_MAX_VARS = 999
|
||||||
|
|
@ -359,13 +360,17 @@ class Database:
|
||||||
for table in tables
|
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())
|
cursor = self.execute(sql, params or tuple())
|
||||||
keys = [d[0] for d in cursor.description]
|
keys = [d[0] for d in cursor.description]
|
||||||
for row in cursor:
|
for row in cursor:
|
||||||
yield dict(zip(keys, row))
|
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))
|
return list(self.query(sql, params))
|
||||||
|
|
||||||
def resolve_foreign_keys(self, name, foreign_keys):
|
def resolve_foreign_keys(self, name, foreign_keys):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue