Skip to content

Commit 2cbea94

Browse files
authored
Add filters for project and tenant labels. (#131)
1 parent 2b74fce commit 2cbea94

21 files changed

+777
-154
lines changed

api/v1/mocks/UnsafeVersionServiceServer.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/mocks/VersionServiceClient.go

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/mocks/VersionServiceServer.go

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/project.pb.go

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1/tenant.pb.go

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/datastore/memory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ func (m *memoryDatastore[E]) DeleteAll(ctx context.Context, ids ...string) error
7070
}
7171

7272
// Find implements Storage.
73-
func (m *memoryDatastore[E]) Find(ctx context.Context, filter map[string]any, paging *v1.Paging) ([]E, *uint64, error) {
74-
m.log.Debug("find", "entity", m.entity, "filter", filter)
73+
func (m *memoryDatastore[E]) Find(ctx context.Context, paging *v1.Paging, filters ...any) ([]E, *uint64, error) {
74+
m.log.Debug("find", "entity", m.entity, "filter", filters)
7575

7676
m.lock.Lock()
7777
defer m.lock.Unlock()

pkg/datastore/mocks/Storage.go

Lines changed: 14 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/datastore/postgres.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Storage[E Entity] interface {
3232
Get(ctx context.Context, id string) (E, error)
3333
GetHistory(ctx context.Context, id string, at time.Time, ve E) error
3434
GetHistoryCreated(ctx context.Context, id string, ve E) error
35-
Find(ctx context.Context, filter map[string]any, paging *v1.Paging) ([]E, *uint64, error)
35+
Find(ctx context.Context, paging *v1.Paging, filters ...any) ([]E, *uint64, error)
3636
}
3737

3838
// Entity defines a database entity which is stored in jsonb format and with version information
@@ -370,14 +370,15 @@ func (ds *datastore[E]) DeleteAll(ctx context.Context, ids ...string) error {
370370
}
371371

372372
// Find returns matching elements from the database
373-
func (ds *datastore[E]) Find(ctx context.Context, filter map[string]any, paging *v1.Paging) ([]E, *uint64, error) {
374-
ds.log.Debug("find", "entity", ds.jsonField, "filter", filter)
373+
func (ds *datastore[E]) Find(ctx context.Context, paging *v1.Paging, filters ...any) ([]E, *uint64, error) {
374+
ds.log.Debug("find", "entity", ds.jsonField, "filters", filters)
375375
q := ds.sb.Select(ds.jsonField).
376376
From(ds.tableName)
377377

378-
if len(filter) > 0 {
378+
for _, filter := range filters {
379379
q = q.Where(filter)
380380
}
381+
381382
q = q.OrderBy("id")
382383

383384
// Add paging query if paging is defined

pkg/datastore/postgres_benchmark_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func BenchmarkFindTenant(b *testing.B) {
9090
f := make(map[string]any)
9191
f["tenant ->> 'name'"] = "tenant-1"
9292

93-
t, _, err := ds.Find(context.Background(), f, nil)
93+
t, _, err := ds.Find(context.Background(), nil, f)
9494
require.NoError(b, err)
9595
assert.NotNil(b, t)
9696
assert.Len(b, t, 1)

0 commit comments

Comments
 (0)