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 5cf5b83 commit 29e01e9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
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 29e01e9

Please sign in to comment.