`table.get(column=value)` option for retrieving things not by their primary key
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
調査の方向性
sqlite_utils/db.py の 1495 行目付近にある、既存の Table.get() メソッドの定義から始め、現在の位置引数による検索動作を確認してください。issue の unique-name 例に対応するキーワードによるカラム検索を追加し、NotFoundError の動作を維持したうえで、既存のデータベーステストを実行し、検索に成功するケースと行が見つからないケースのカバレッジを追加してください。
索引モデルが issue の本文から書いたものです。
説明
This came up working on this feature:
I have a table with this schema:
CREATE TABLE [collections] (
[id] INTEGER PRIMARY 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)
except NotFoundError:
# It doesn't exist
Fetching by name:
def get_collection(db, collection):
rows = db["collections"].rows_where("name = ?", [collection])
try:
return next(rows)
except StopIteration:
raise NotFoundError("Collection not found: {}".format(collection))
It would be neat if, for columns where we know that we should always get 0 or one result, we could do this instead:
try:
collection = table["collections"].get(name="entries")
except NotFoundError:
# It doesn't exist
The existing .get() method doesn't have any non-positional arguments, so using **kwargs like that should work:
- 主要言語
- Python
- スター
- 2.2k
- フォーク
- 172
- 平均マージ
- 9分
- マージ済み PR(30日)
- 1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
simonw/sqlite-utils のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
simonw/sqlite-utils#876 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
simonw/sqlite-utils#872 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
simonw/sqlite-utils#857 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
simonw/sqlite-utils#849 ·
-
bug documentation help wanted
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
simonw/sqlite-utils#493 · コメント 5 件 ·
simonw/sqlite-utils の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
-
hcocena オープンpolicies-accepted pre-review precheck-passed
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
Bioconductor/BiocContributions#214 · コメント 5 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
TencentCloud/Octop#1169 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
521xueweihan/HelloGitHub#3778 ·
-
The version checker's trailing attribute region has no control for a less-than inside a quoted value オープンarea: dashboard area: tests bug perceived difficulty: 2 python
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
Nitjsefnie-Harness-Commons/daedalus#1105 · コメント 1 件 ·