Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

More advanced querying on JobListParams.Metadata()

オープン
#570 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
go, postgresql
領域
backend, databases

調査の方向性

Start in job_list_params.go with JobListParams, NewJobListParams, Metadata, and toDBParams, then trace how client.JobList consumes the converted parameters. Review the proposed Where behavior alongside existing conditions and copying semantics. Done means the maintainer-approved API supports the metadata query example without breaking existing filters, with the requested documentation and tests.

索引モデルが issue の本文から書いたものです。

説明

Right now JobListParams.Metadata() only offers querying via metadata >@ …, but I'd like to do slightly more advanced stuff. For example if the metadata contains:

{"object_id": 42}

And I'd like to list all jobs that match any of a set:

objectsUserHasAccessTo := []int{1, 5, 42}

params := NewJobListParams().Where(
    `(metadata->'object_id')::int = any(@objects)`,
    map[string]any{"objects": objectsUserHasAccessTo},
)

client.JobList(ctx, params)

I don't mind writing a patch for this; the simplest would be to just allow appending to the condition list and argument map, via the patch below. Although arguably that would give too much control (and the ability to do very stupid things).

Then again, restricting this would probably more trouble than its worth(?) The alternative is writing my own query from scratch, which allows for even more stupid stuff.

Well, let me know what you want and I'll submit a working patch with docs, tests, etc.

diff --git i/job_list_params.go w/job_list_params.go
index ffdc39a..7edd6f9 100644
--- i/job_list_params.go
+++ w/job_list_params.go
@@ -174,6 +174,8 @@ type JobListParams struct {
        sortField        JobListOrderByField
        sortOrder        SortOrder
        states           []rivertype.JobState
+       whereSQL         string
+       whereArgs        map[string]any
 }

 // NewJobListParams creates a new JobListParams to return available jobs sorted
@@ -263,6 +265,12 @@ func (p *JobListParams) toDBParams() (*dblist.JobListParams, error) {
                conditions = append(conditions, `metadata @> @metadata_fragment::jsonb`)
                namedArgs["metadata_fragment"] = p.metadataFragment
        }
+       if p.whereSQL != "" {
+               conditions = append(conditions, p.whereSQL)
+               for k, v := range p.whereArgs {
+                       namedArgs[k] = v
+               }
+       }

        if p.after != nil {
                if p.after.time.IsZero() { // order by ID only
@@ -346,6 +354,13 @@ func (p *JobListParams) Metadata(json string) *JobListParams {
        return paramsCopy
 }

+func (p *JobListParams) Where(sql string, args map[string]any) *JobListParams {
+       paramsCopy := p.copy()
+       paramsCopy.whereSQL = sql
+       paramsCopy.whereArgs = args
+       return paramsCopy
+}
+
 // Queues returns an updated filter set that will only return jobs from the
 // given queues.
 func (p *JobListParams) Queues(queues ...string) *JobListParams {
主要言語
Go
スター
5.7k
フォーク
179
平均マージ
2日 19時間
マージ済み PR(30日)
12

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

riverqueue/river のほかの issue

riverqueue/river の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。