diff --git a/fastlite/core.py b/fastlite/core.py index 2da6280..e8b4f55 100644 --- a/fastlite/core.py +++ b/fastlite/core.py @@ -25,7 +25,7 @@ def __init__(self, db): self.db = db def __repr__(self): return ", ".join(dir(self)) def __contains__(self, s): return (s if isinstance(s,str) else s.name) in dir(self) def __getitem__(self, idxs): - if isinstance(idxs,str): idxs = [idxs] + if isinstance(idxs,str): return self.db.table(idxs) return [self.db.table(o) for o in idxs] def __getattr__(self, k): if k[0]=='_': raise AttributeError diff --git a/fastlite/kw.py b/fastlite/kw.py index 573ec99..b0d8660 100644 --- a/fastlite/kw.py +++ b/fastlite/kw.py @@ -75,18 +75,16 @@ def transform_sql( drop_foreign_keys=drop_foreign_keys, add_foreign_keys=add_foreign_keys, foreign_keys=foreign_keys, column_order=column_order, keep_table=keep_table) + @patch -def update( - self:Table, - pk_values: Union[list, tuple, str, int, float], - updates: Any = None, - alter: bool = False, - conversions: Optional[dict] = None, - **kwargs) -> Table: +def update(self:Table, updates: dict|None=None, pk_values: list|tuple|str|int|float|None=None, + alter: bool=False, conversions: dict|None=None, **kwargs): if not updates: updates={} if is_dataclass(updates): updates = asdict(updates) updates = {**updates, **kwargs} - self._orig_update(pk_values=pk_values, updates=updates, alter=alter, conversions=conversions) + if not pk_values: pk_values = [updates[o] for o in self.pks] + self._orig_update(pk_values, updates=updates, alter=alter, conversions=conversions) + return self.get(self.last_pk) @patch @@ -121,7 +119,7 @@ def insert( @patch def upsert( self:Table, - record: Dict[str, Any]=None, + record:Any=None, pk=DEFAULT, foreign_keys=DEFAULT, column_order: Optional[Union[List[str], Default]] = DEFAULT, diff --git a/nbs/00_core.ipynb b/nbs/00_core.ipynb index 3175070..0b91a56 100644 --- a/nbs/00_core.ipynb +++ b/nbs/00_core.ipynb @@ -78,7 +78,7 @@ " def __repr__(self): return \", \".join(dir(self))\n", " def __contains__(self, s): return (s if isinstance(s,str) else s.name) in dir(self)\n", " def __getitem__(self, idxs):\n", - " if isinstance(idxs,str): idxs = [idxs]\n", + " if isinstance(idxs,str): return self.db.table(idxs)\n", " return [self.db.table(o) for o in idxs]\n", " def __getattr__(self, k):\n", " if k[0]=='_': raise AttributeError\n", diff --git a/nbs/index.ipynb b/nbs/index.ipynb index a582c85..cb9e727 100644 --- a/nbs/index.ipynb +++ b/nbs/index.ipynb @@ -594,6 +594,41 @@ "- `lookup`" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can access a table that doesn't actually exist yet:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "