Skip to content

Commit

Permalink
Fixed condition interpreter
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandros Filios <[email protected]>
  • Loading branch information
alexandrosfilios committed Sep 23, 2024
1 parent 4dcece1 commit e61fe72
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,7 @@ func testTXIDStore(t *testing.T, store *SimpleTXIDStore[vc]) {
txids[i] = result.TxID
}
assert.Len(t, txids, 2)
assert.Equal(t, []string{"txid1025", "txid21"}, txids)
assert.Contains(t, txids, "txid21")
assert.Contains(t, txids, "txid1025")

}
44 changes: 42 additions & 2 deletions platform/view/services/db/driver/sql/postgres/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,46 @@ import (
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/common"
)

func NewInterpreter() common.Interpreter {
return common.NewInterpreter()
type interpreter struct {
common.Interpreter
}

func NewInterpreter() *interpreter {
return &interpreter{Interpreter: common.NewInterpreter()}
}

func (i *interpreter) In(field common.FieldName, vals []any) common.Condition {
tuples := make([]common.Tuple, len(vals))
for i, val := range vals {
tuples[i] = common.Tuple{val}
}
return i.InTuple([]common.FieldName{field}, tuples)
}
func (i *interpreter) InStrings(field common.FieldName, vals []string) common.Condition {
tuples := make([]common.Tuple, len(vals))
for i, val := range vals {
tuples[i] = common.Tuple{val}
}
return i.InTuple([]common.FieldName{field}, tuples)
}
func (i *interpreter) InInts(field common.FieldName, vals []int) common.Condition {
tuples := make([]common.Tuple, len(vals))
for i, val := range vals {
tuples[i] = common.Tuple{val}
}
return i.InTuple([]common.FieldName{field}, tuples)
}
func (i *interpreter) InTuple(fields []common.FieldName, vals []common.Tuple) common.Condition {
if len(vals) == 0 || len(fields) == 0 {
return common.EmptyCondition
}
ors := make([]common.Condition, len(vals))
for j, tuple := range vals {
ands := make([]common.Condition, len(tuple))
for k, val := range tuple {
ands[k] = i.Cmp(fields[k], "=", val)
}
ors[j] = i.And(ands...)
}
return i.Or(ors...)
}
48 changes: 3 additions & 45 deletions platform/view/services/db/driver/sql/sqlite/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,8 @@ SPDX-License-Identifier: Apache-2.0

package sqlite

import (
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/common"
)
import "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/common"

type interpreter struct {
common.Interpreter
}

func NewInterpreter() *interpreter {
return &interpreter{Interpreter: common.NewInterpreter()}
}

func (i *interpreter) In(field common.FieldName, vals []any) common.Condition {
tuples := make([]common.Tuple, len(vals))
for i, val := range vals {
tuples[i] = common.Tuple{val}
}
return i.InTuple([]common.FieldName{field}, tuples)
}
func (i *interpreter) InStrings(field common.FieldName, vals []string) common.Condition {
tuples := make([]common.Tuple, len(vals))
for i, val := range vals {
tuples[i] = common.Tuple{val}
}
return i.InTuple([]common.FieldName{field}, tuples)
}
func (i *interpreter) InInts(field common.FieldName, vals []int) common.Condition {
tuples := make([]common.Tuple, len(vals))
for i, val := range vals {
tuples[i] = common.Tuple{val}
}
return i.InTuple([]common.FieldName{field}, tuples)
}
func (i *interpreter) InTuple(fields []common.FieldName, vals []common.Tuple) common.Condition {
if len(vals) == 0 || len(fields) == 0 {
return common.EmptyCondition
}
ors := make([]common.Condition, len(vals))
for j, tuple := range vals {
ands := make([]common.Condition, len(tuple))
for k, val := range tuple {
ands[k] = i.Cmp(fields[k], "=", val)
}
ors[j] = i.And(ands...)
}
return i.Or(ors...)
func NewInterpreter() common.Interpreter {
return common.NewInterpreter()
}

0 comments on commit e61fe72

Please sign in to comment.