Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
awrichar committed Sep 16, 2024
2 parents e4b52cb + c8d7a03 commit 39e36b9
Show file tree
Hide file tree
Showing 22 changed files with 2,197 additions and 250 deletions.
4 changes: 2 additions & 2 deletions core/go/internal/domainmgr/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import (
"github.com/hyperledger/firefly-signer/pkg/ethtypes"
"github.com/hyperledger/firefly-signer/pkg/secp256k1"
"github.com/kaleido-io/paladin/core/internal/components"
"github.com/kaleido-io/paladin/core/internal/filters"
"github.com/kaleido-io/paladin/core/internal/msgs"
"github.com/kaleido-io/paladin/core/internal/statestore"

"github.com/kaleido-io/paladin/toolkit/pkg/algorithms"
"github.com/kaleido-io/paladin/toolkit/pkg/log"
"github.com/kaleido-io/paladin/toolkit/pkg/prototk"
"github.com/kaleido-io/paladin/toolkit/pkg/query"
"github.com/kaleido-io/paladin/toolkit/pkg/retry"
"github.com/kaleido-io/paladin/toolkit/pkg/tktypes"
)
Expand Down Expand Up @@ -194,7 +194,7 @@ func (d *domain) FindAvailableStates(ctx context.Context, req *prototk.FindAvail
return nil, err
}

var query filters.QueryJSON
var query query.QueryJSON
err := json.Unmarshal([]byte(req.QueryJson), &query)
if err != nil {
return nil, i18n.WrapError(ctx, err, msgs.MsgDomainInvalidQueryJSON)
Expand Down
12 changes: 6 additions & 6 deletions core/go/internal/domainmgr/private_smart_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (
"github.com/hyperledger/firefly-common/pkg/i18n"
"github.com/hyperledger/firefly-signer/pkg/abi"
"github.com/kaleido-io/paladin/core/internal/components"
"github.com/kaleido-io/paladin/core/internal/filters"
"github.com/kaleido-io/paladin/core/internal/msgs"
"github.com/kaleido-io/paladin/core/internal/statestore"

"github.com/kaleido-io/paladin/toolkit/pkg/prototk"
"github.com/kaleido-io/paladin/toolkit/pkg/query"
"github.com/kaleido-io/paladin/toolkit/pkg/tktypes"
)

Expand Down Expand Up @@ -418,11 +418,11 @@ func (dc *domainContract) loadStates(ctx context.Context, refs []*prototk.StateR
statesByID := make(map[tktypes.Bytes32]*statestore.State)
err := dc.dm.stateStore.RunInDomainContext(dc.d.name, func(ctx context.Context, dsi statestore.DomainStateInterface) error {
for schemaID, stateIDs := range rawIDsBySchema {
statesForSchema, err := dsi.FindAvailableStates(schemaID, &filters.QueryJSON{
Statements: filters.Statements{
Ops: filters.Ops{
In: []*filters.OpMultiVal{
{Op: filters.Op{Field: ".id"}, Values: stateIDs},
statesForSchema, err := dsi.FindAvailableStates(schemaID, &query.QueryJSON{
Statements: query.Statements{
Ops: query.Ops{
In: []*query.OpMultiVal{
{Op: query.Op{Field: ".id"}, Values: stateIDs},
},
},
},
Expand Down
31 changes: 16 additions & 15 deletions core/go/internal/filters/query_traverser.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/hyperledger/firefly-common/pkg/i18n"
"github.com/kaleido-io/paladin/core/internal/msgs"
"github.com/kaleido-io/paladin/toolkit/pkg/query"
"github.com/kaleido-io/paladin/toolkit/pkg/tktypes"
)

Expand All @@ -36,14 +37,14 @@ type Traverser[T any] interface {
Order(f string) Traverser[T]
And(ot T) Traverser[T]
BuildOr(ot ...T) Traverser[T]
IsEqual(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsLike(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsNull(e *Op, fieldName string, field FieldResolver) Traverser[T]
IsLessThan(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsLessThanOrEqual(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsGreaterThan(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsGreaterThanOrEqual(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsIn(e *OpMultiVal, fieldName string, field FieldResolver, testValues []driver.Value) Traverser[T]
IsEqual(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsLike(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsNull(e *query.Op, fieldName string, field FieldResolver) Traverser[T]
IsLessThan(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsLessThanOrEqual(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsGreaterThan(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsGreaterThanOrEqual(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[T]
IsIn(e *query.OpMultiVal, fieldName string, field FieldResolver, testValues []driver.Value) Traverser[T]
}

var allMods = []string{"not", "caseInsensitive"}
Expand Down Expand Up @@ -71,7 +72,7 @@ func (fm FieldMap) ResolverFor(fieldName string) FieldResolver {

type queryTraverser[T any] struct {
ctx context.Context
jsonFilter *QueryJSON
jsonFilter *query.QueryJSON
fieldSet FieldSet
}

Expand Down Expand Up @@ -170,7 +171,7 @@ func resolveFieldAndValues(ctx context.Context, fieldSet FieldSet, fieldName str
return field, values, nil
}

func (qt *queryTraverser[T]) addSimpleFilters(t Traverser[T], jf *Statements) Traverser[T] {
func (qt *queryTraverser[T]) addSimpleFilters(t Traverser[T], jf *query.Statements) Traverser[T] {
for _, e := range joinShortNames(jf.Equal, jf.Eq, jf.NEq) {
field, testValue, err := resolveFieldAndValue(qt.ctx, qt.fieldSet, e.Field, e.Value)
if err != nil {
Expand Down Expand Up @@ -198,8 +199,8 @@ func (qt *queryTraverser[T]) addSimpleFilters(t Traverser[T], jf *Statements) Tr
return t
}

func joinShortNames(long, short, negated []*OpSingleVal) []*OpSingleVal {
res := make([]*OpSingleVal, len(long)+len(short)+len(negated))
func joinShortNames(long, short, negated []*query.OpSingleVal) []*query.OpSingleVal {
res := make([]*query.OpSingleVal, len(long)+len(short)+len(negated))
copy(res, long)
copy(res[len(long):], short)
negs := res[len(short)+len(long):]
Expand All @@ -210,8 +211,8 @@ func joinShortNames(long, short, negated []*OpSingleVal) []*OpSingleVal {
return res
}

func joinInAndNin(in, nin []*OpMultiVal) []*OpMultiVal {
res := make([]*OpMultiVal, len(in)+len(nin))
func joinInAndNin(in, nin []*query.OpMultiVal) []*query.OpMultiVal {
res := make([]*query.OpMultiVal, len(in)+len(nin))
copy(res, in)
negs := res[len(in):]
copy(negs, nin)
Expand All @@ -221,7 +222,7 @@ func joinInAndNin(in, nin []*OpMultiVal) []*OpMultiVal {
return res
}

func (qt *queryTraverser[T]) BuildAndFilter(t Traverser[T], jf *Statements) Traverser[T] {
func (qt *queryTraverser[T]) BuildAndFilter(t Traverser[T], jf *query.Statements) Traverser[T] {
t = t.NewRoot()
t = qt.addSimpleFilters(t, jf)
if t.Error() != nil {
Expand Down
19 changes: 10 additions & 9 deletions core/go/internal/filters/query_traverser_gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (
"database/sql/driver"
"fmt"

"github.com/kaleido-io/paladin/toolkit/pkg/query"
"gorm.io/gorm"
)

func (qj *QueryJSON) BuildGORM(ctx context.Context, db *gorm.DB, fieldSet FieldSet) *gorm.DB {
func BuildGORM(ctx context.Context, qj *query.QueryJSON, db *gorm.DB, fieldSet FieldSet) *gorm.DB {
gt := &gormTraverser{
// We can't assume anything about the db passed in - if it's a clone (internal concept
// in GORM I can't work out how to detect), then it will aggregate WHERE clauses
Expand Down Expand Up @@ -86,7 +87,7 @@ func (t *gormTraverser) BuildOr(ot ...*gormTraverser) Traverser[*gormTraverser]
return or
}

func (t *gormTraverser) IsEqual(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
func (t *gormTraverser) IsEqual(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
if e.CaseInsensitive {
if e.Not {
t.db = t.db.Where(fmt.Sprintf("LOWER(%s) != LOWER(?)", field.SQLColumn()), testValue)
Expand All @@ -103,7 +104,7 @@ func (t *gormTraverser) IsEqual(e *OpSingleVal, fieldName string, field FieldRes
return t
}

func (t *gormTraverser) IsLike(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
func (t *gormTraverser) IsLike(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
if e.CaseInsensitive {
if e.Not {
t.db = t.db.Where(fmt.Sprintf("%s NOT ILIKE ?", field.SQLColumn()), testValue)
Expand All @@ -120,7 +121,7 @@ func (t *gormTraverser) IsLike(e *OpSingleVal, fieldName string, field FieldReso
return t
}

func (t *gormTraverser) IsNull(e *Op, fieldName string, field FieldResolver) Traverser[*gormTraverser] {
func (t *gormTraverser) IsNull(e *query.Op, fieldName string, field FieldResolver) Traverser[*gormTraverser] {
if e.Not {
t.db = t.db.Where(fmt.Sprintf("%s IS NOT NULL", field.SQLColumn()))
} else {
Expand All @@ -129,27 +130,27 @@ func (t *gormTraverser) IsNull(e *Op, fieldName string, field FieldResolver) Tra
return t
}

func (t *gormTraverser) IsLessThan(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
func (t *gormTraverser) IsLessThan(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
t.db = t.db.Where(fmt.Sprintf("%s < ?", field.SQLColumn()), testValue)
return t
}

func (t *gormTraverser) IsLessThanOrEqual(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
func (t *gormTraverser) IsLessThanOrEqual(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
t.db = t.db.Where(fmt.Sprintf("%s <= ?", field.SQLColumn()), testValue)
return t
}

func (t *gormTraverser) IsGreaterThan(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
func (t *gormTraverser) IsGreaterThan(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
t.db = t.db.Where(fmt.Sprintf("%s > ?", field.SQLColumn()), testValue)
return t
}

func (t *gormTraverser) IsGreaterThanOrEqual(e *OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
func (t *gormTraverser) IsGreaterThanOrEqual(e *query.OpSingleVal, fieldName string, field FieldResolver, testValue driver.Value) Traverser[*gormTraverser] {
t.db = t.db.Where(fmt.Sprintf("%s >= ?", field.SQLColumn()), testValue)
return t
}

func (t *gormTraverser) IsIn(e *OpMultiVal, fieldName string, field FieldResolver, testValues []driver.Value) Traverser[*gormTraverser] {
func (t *gormTraverser) IsIn(e *query.OpMultiVal, fieldName string, field FieldResolver, testValues []driver.Value) Traverser[*gormTraverser] {
if e.Not {
t.db = t.db.Where(fmt.Sprintf("%s NOT IN (?)", field.SQLColumn()), testValues)
} else {
Expand Down
Loading

0 comments on commit 39e36b9

Please sign in to comment.