Replies: 1 comment 1 reply
-
Maybe something like this: func authorsWhereCondition(params map[string]interface{}) BoolExpression {
var conditions []BoolExpression
for column, value := range params {
switch column {
case "Name":
val, ok := value.(string)
// handle !ok
conditions = append(conditions, Authors.Name.EQ(String(val)))
case "ID":
val, ok := value.(int32)
// handle !ok
conditions = append(conditions, Authors.ID.EQ(Int32(val)))
default:
// handle unknown column
}
}
return AND(conditions...)
} Which later can be used: params := map[string]interface{}{
"Name": "John",
"ID": 1,
}
SELECT(Authors.AllColumns).
FROM(Authors).
WHERE(authorsWhereCondition(params)) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi. My API requires us to support filter query parameters. For example,
filter=name.JKRowling
. For now, we are planning to only support equal comparisons, so the example would translate to a WHERE clause ofname = 'JKRowling'
in anAuthors
table for example.The problem now is that I should be able to map the column string name to the jet column equivalent and then call the EQ method on it. Somehow, we would need to be able to figure out the column data type as well. Unfortunately, I have not found a way to do this.
has anyone had the same requirements and found a way to do this? Some insight would be helpful. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions