You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CREATE TABLE [collections] (
[id] INTEGERPRIMARY KEY,
[name] TEXT,
[model] TEXT
);
CREATE UNIQUE INDEX [idx_collections_name]
ON [collections] ([name]);
So the primary key is an integer (because it's going to have a huge number of rows foreign key related to it, and I don't want to store a larger text value thousands of times), but there is a unique constraint on the name - that would be the primary key column if not for all of those foreign keys.
Problem is, fetching the collection by name is actually pretty inconvenient.
Fetch by numeric ID:
try:
table["collections"].get(1)
exceptNotFoundError:
# It doesn't exist
This came up working on this feature:
I have a table with this schema:
So the primary key is an integer (because it's going to have a huge number of rows foreign key related to it, and I don't want to store a larger text value thousands of times), but there is a unique constraint on the
name
- that would be the primary key column if not for all of those foreign keys.Problem is, fetching the collection by name is actually pretty inconvenient.
Fetch by numeric ID:
Fetching by name:
It would be neat if, for columns where we know that we should always get 0 or one result, we could do this instead:
The existing
.get()
method doesn't have any non-positional arguments, so using**kwargs
like that should work:sqlite-utils/sqlite_utils/db.py
Line 1495 in 1260bdc
The text was updated successfully, but these errors were encountered: