Skip to content

Commit 20e2073

Browse files
committed
fixes #15
1 parent 8848c90 commit 20e2073

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

fastlite/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
__version__ = "0.0.8"
22
from .core import *
33
from .kw import *
4-

fastlite/core.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,23 @@ def create_mod(db, mod_fn, with_views=False, store=True, suf=''):
104104
# %% ../nbs/00_core.ipynb 34
105105
@patch
106106
def __call__(
107-
self:(Table|View), where:str|None=None,
108-
where_args: Iterable|dict|NoneType=None, with_pk:bool=False, order_by: str|None=None,
109-
limit:int|None=None, offset:int|None=None, as_cls:bool=True, **kwargs)->list:
107+
self:(Table|View),
108+
where:str|None=None, # SQL where fragment to use, for example `id > ?`
109+
where_args: Iterable|dict|NoneType=None, # Parameters to use with `where`; iterable for `id>?`, or dict for `id>:id`
110+
order_by: str|None=None, # Column or fragment of SQL to order by
111+
limit:int|None=None, # Number of rows to limit to
112+
offset:int|None=None, # SQL offset
113+
select:str = "*", # Comma-separated list of columns to select
114+
with_pk:bool=False, # Return tuple of (pk,row)?
115+
as_cls:bool=True, # Convert returned dict to stored dataclass?
116+
**kwargs)->list:
110117
"Shortcut for `rows_where` or `pks_and_rows_where`, depending on `with_pk`"
111-
112118
f = getattr(self, 'pks_and_rows_where' if with_pk else 'rows_where')
113119
xtra = getattr(self, 'xtra_id', {})
114120
if xtra:
115121
xw = ' and '.join(f"[{k}] = {v!r}" for k,v in xtra.items())
116122
where = f'{xw} and {where}' if where else xw
117-
res = f(where=where, where_args=where_args, order_by=order_by, limit=limit, offset=offset, **kwargs)
123+
res = f(where=where, where_args=where_args, order_by=order_by, limit=limit, offset=offset, select=select, **kwargs)
118124
if as_cls and hasattr(self,'cls'):
119125
if with_pk: res = ((k,self.cls(**v)) for k,v in res)
120126
else: res = (self.cls(**o) for o in res)

fastlite/kw.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
opt_bool = Union[bool, Default, None]
77

8-
def database(path, wal=True):
8+
def database(path, wal=True)->Any:
99
path = Path(path)
1010
path.parent.mkdir(exist_ok=True)
1111
db = Database(path)
@@ -35,6 +35,7 @@ def ids_and_rows_where(
3535
order_by: Optional[str] = None,
3636
limit: Optional[int] = None,
3737
offset: Optional[int] = None,
38+
select: str = '*',
3839
) -> Generator[Tuple[Any, Dict], None, None]:
3940
"""
4041
Like ``.rows_where()`` but returns ``(rowid, row)`` pairs.
@@ -47,8 +48,8 @@ def ids_and_rows_where(
4748
:param limit: Integer number of rows to limit to
4849
:param offset: Integer for SQL offset
4950
"""
50-
cs = [c.name for c in self.columns]
51-
select = ",".join("[{}]".format(c) for c in cs)
51+
#cs = [c.name for c in self.columns]
52+
#select = ",".join("[{}]".format(c) for c in cs)
5253
select = "_rowid_ as __rid, " + select
5354
for row in self.rows_where(select=select, where=where, where_args=where_args, order_by=order_by, limit=limit, offset=offset):
5455
yield row.pop('__rid'), row

nbs/00_core.ipynb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,17 +505,23 @@
505505
"#| exports\n",
506506
"@patch\n",
507507
"def __call__(\n",
508-
" self:(Table|View), where:str|None=None,\n",
509-
" where_args: Iterable|dict|NoneType=None, with_pk:bool=False, order_by: str|None=None,\n",
510-
" limit:int|None=None, offset:int|None=None, as_cls:bool=True, **kwargs)->list:\n",
508+
" self:(Table|View),\n",
509+
" where:str|None=None, # SQL where fragment to use, for example `id > ?`\n",
510+
" where_args: Iterable|dict|NoneType=None, # Parameters to use with `where`; iterable for `id>?`, or dict for `id>:id`\n",
511+
" order_by: str|None=None, # Column or fragment of SQL to order by\n",
512+
" limit:int|None=None, # Number of rows to limit to\n",
513+
" offset:int|None=None, # SQL offset\n",
514+
" select:str = \"*\", # Comma-separated list of columns to select\n",
515+
" with_pk:bool=False, # Return tuple of (pk,row)?\n",
516+
" as_cls:bool=True, # Convert returned dict to stored dataclass?\n",
517+
" **kwargs)->list:\n",
511518
" \"Shortcut for `rows_where` or `pks_and_rows_where`, depending on `with_pk`\"\n",
512-
"\n",
513519
" f = getattr(self, 'pks_and_rows_where' if with_pk else 'rows_where')\n",
514520
" xtra = getattr(self, 'xtra_id', {})\n",
515521
" if xtra:\n",
516522
" xw = ' and '.join(f\"[{k}] = {v!r}\" for k,v in xtra.items())\n",
517523
" where = f'{xw} and {where}' if where else xw\n",
518-
" res = f(where=where, where_args=where_args, order_by=order_by, limit=limit, offset=offset, **kwargs)\n",
524+
" res = f(where=where, where_args=where_args, order_by=order_by, limit=limit, offset=offset, select=select, **kwargs)\n",
519525
" if as_cls and hasattr(self,'cls'):\n",
520526
" if with_pk: res = ((k,self.cls(**v)) for k,v in res)\n",
521527
" else: res = (self.cls(**o) for o in res)\n",

0 commit comments

Comments
 (0)