mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37:32 +00:00
event data search query
This commit is contained in:
@@ -48,6 +48,8 @@ const (
|
||||
OperationLess
|
||||
//OperationIn checks if a stored value matches one of the passed value list
|
||||
OperationIn
|
||||
//OperationJSONContains checks if a stored value matches the given json
|
||||
OperationJSONContains
|
||||
|
||||
operationCount
|
||||
)
|
||||
@@ -70,6 +72,8 @@ const (
|
||||
FieldEditorUser
|
||||
//FieldEventType represents the event type field
|
||||
FieldEventType
|
||||
//FieldEventData represents the event data field
|
||||
FieldEventData
|
||||
|
||||
fieldCount
|
||||
)
|
||||
|
@@ -252,6 +252,8 @@ func (db *CRDB) columnName(col repository.Field) string {
|
||||
return "editor_user"
|
||||
case repository.FieldEventType:
|
||||
return "event_type"
|
||||
case repository.FieldEventData:
|
||||
return "event_data"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
@@ -272,6 +274,8 @@ func (db *CRDB) operation(operation repository.Operation) string {
|
||||
return ">"
|
||||
case repository.OperationLess:
|
||||
return "<"
|
||||
case repository.OperationJSONContains:
|
||||
return "@>"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package sql
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
@@ -137,6 +138,10 @@ func prepareCondition(criteria querier, filters []*repository.Filter) (clause st
|
||||
switch value.(type) {
|
||||
case []bool, []float64, []int64, []string, []repository.AggregateType, []repository.EventType, *[]bool, *[]float64, *[]int64, *[]string, *[]repository.AggregateType, *[]repository.EventType:
|
||||
value = pq.Array(value)
|
||||
case map[string]interface{}:
|
||||
var err error
|
||||
value, err = json.Marshal(value)
|
||||
logging.Log("SQL-BSsNy").OnError(err).Warn("unable to marshal search value")
|
||||
}
|
||||
|
||||
clauses[i] = getCondition(criteria, filter)
|
||||
|
@@ -15,6 +15,7 @@ type SearchQueryFactory struct {
|
||||
aggregateIDs []string
|
||||
eventSequence uint64
|
||||
eventTypes []EventType
|
||||
eventData map[string]interface{}
|
||||
resourceOwner string
|
||||
}
|
||||
|
||||
@@ -83,6 +84,11 @@ func (factory *SearchQueryFactory) OrderAsc() *SearchQueryFactory {
|
||||
return factory
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) EventData(query map[string]interface{}) *SearchQueryFactory {
|
||||
factory.eventData = query
|
||||
return factory
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) build() (*repository.SearchQuery, error) {
|
||||
if factory == nil ||
|
||||
len(factory.aggregateTypes) < 1 ||
|
||||
@@ -98,6 +104,7 @@ func (factory *SearchQueryFactory) build() (*repository.SearchQuery, error) {
|
||||
factory.eventSequenceFilter,
|
||||
factory.eventTypeFilter,
|
||||
factory.resourceOwnerFilter,
|
||||
factory.eventDataFilter,
|
||||
} {
|
||||
if filter := f(); filter != nil {
|
||||
if err := filter.Validate(); err != nil {
|
||||
@@ -159,3 +166,10 @@ func (factory *SearchQueryFactory) resourceOwnerFilter() *repository.Filter {
|
||||
}
|
||||
return repository.NewFilter(repository.FieldResourceOwner, factory.resourceOwner, repository.OperationEquals)
|
||||
}
|
||||
|
||||
func (factory *SearchQueryFactory) eventDataFilter() *repository.Filter {
|
||||
if len(factory.eventData) == 0 {
|
||||
return nil
|
||||
}
|
||||
return repository.NewFilter(repository.FieldEventData, factory.eventData, repository.OperationJSONContains)
|
||||
}
|
||||
|
Reference in New Issue
Block a user