jackc / jackc/pgx

MultiRange Generics Suggestion

Open
#1,870 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

https://github.com/jackc/pgx/blob/6f2ce92356f35263258ef7baa4cde86a3e1c6255/pgtype/multirange.go#L406
Might be looking for the following arcane generics invocation (the idea being that you require one constraint on the S and then require the other in a generic interface that embeds a *S)!

```go
type constraint[T pgtype.RangeValuer] interface {
pgtype.RangeScanner
*T
}

type Multirange[S pgtype.RangeValuer, T constraint[S]] []T

func (r Multirange[S, T]) IsNull() bool {
return r == nil
}

func (r Multirange[S, T]) Len() int {
return len(r)
}

func (r Multirange[S, T]) Index(i int) any {
return r[i]
}

func (r Multirange[S, T]) IndexType() any {
var zero T
return zero
}

func (r *Multirange[S, T]) ScanNull() error {
*r = nil
return nil
}

func (r *Multirange[S, T]) SetLen(n int) error {
*r = make([]T, n)
return nil
}

func (r Multirange[S, T]) ScanIndex(i int) any {
return &r[i]
}

func (r Multirange[S, T]) ScanIndexType() any {
return new(T)
}

```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pgtype/multirange.go around line 406 and compare the existing Multirange implementation with the proposed generic constraints and methods. Determine whether the suggestion can be integrated while preserving the current scanning behavior; done means the design is resolved and the resulting behavior is covered by the relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.