-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extra options to lookup()
which get passed to insert()
#342
Comments
Looking at the code for sqlite-utils/sqlite_utils/db.py Lines 2756 to 2763 in 3b8abe6
|
def lookup(
self,
lookup_values: Dict[str, Any],
extra_values: Optional[Dict[str, Any]] = None,
pk="id",
**insert_kwargs,
):
"""
assert isinstance(lookup_values, dict)
if extra_values is not None:
assert isinstance(extra_values, dict)
combined_values = dict(lookup_values)
if extra_values is not None:
combined_values.update(extra_values)
if self.exists():
self.add_missing_columns([combined_values])
unique_column_sets = [set(i.columns) for i in self.indexes]
if set(lookup_values.keys()) not in unique_column_sets:
self.create_index(lookup_values.keys(), unique=True)
wheres = ["[{}] = ?".format(column) for column in lookup_values]
rows = list(
self.rows_where(
" and ".join(wheres), [value for _, value in lookup_values.items()]
)
)
try:
return rows[0][pk]
except IndexError:
return self.insert(combined_values, pk=pk, **insert_kwargs).last_pk
else:
pk = self.insert(combined_values, pk=pk, **insert_kwargs).last_pk
self.create_index(lookup_values.keys(), unique=True)
return pk I think I'll explicitly list the parameters, mainly so they can be typed and covered by automatic documentation. I do worry that I'll add more keyword arguments to |
Here's the current full method signature for sqlite-utils/sqlite_utils/db.py Lines 2462 to 2477 in 3b8abe6
I could add a test which uses introspection ( |
Also: I don't think |
And neither does |
I don't think I need the |
sqlite-utils/sqlite_utils/db.py Lines 2743 to 2746 in 3b8abe6
|
Using new feature from simonw/sqlite-utils#342
- Now depends on sqlite-utils 3.19, using new feature from simonw/sqlite-utils#342 - Include table schemas in README
For simonw/git-history#12 I found myself wanting to pass extra options to
lookup()
to set the column order, primary key etc.The text was updated successfully, but these errors were encountered: