Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions api/v1/mocks/UnsafeVersionServiceServer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions api/v1/mocks/VersionServiceClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions api/v1/mocks/VersionServiceServer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions api/v1/project.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions api/v1/tenant.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/datastore/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func (m *memoryDatastore[E]) DeleteAll(ctx context.Context, ids ...string) error
}

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

m.lock.Lock()
defer m.lock.Unlock()
Expand Down
25 changes: 14 additions & 11 deletions pkg/datastore/mocks/Storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions pkg/datastore/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Storage[E Entity] interface {
Get(ctx context.Context, id string) (E, error)
GetHistory(ctx context.Context, id string, at time.Time, ve E) error
GetHistoryCreated(ctx context.Context, id string, ve E) error
Find(ctx context.Context, filter map[string]any, paging *v1.Paging) ([]E, *uint64, error)
Find(ctx context.Context, paging *v1.Paging, filters ...any) ([]E, *uint64, error)
}

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

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

if len(filter) > 0 {
for _, filter := range filters {
q = q.Where(filter)
}

q = q.OrderBy("id")

// Add paging query if paging is defined
Expand Down
2 changes: 1 addition & 1 deletion pkg/datastore/postgres_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func BenchmarkFindTenant(b *testing.B) {
f := make(map[string]any)
f["tenant ->> 'name'"] = "tenant-1"

t, _, err := ds.Find(context.Background(), f, nil)
t, _, err := ds.Find(context.Background(), nil, f)
require.NoError(b, err)
assert.NotNil(b, t)
assert.Len(b, t, 1)
Expand Down
Loading