loukoum
loukoum copied to clipboard
Support JSON/JSONB ?
Do you had any plans to support Postgres JSON/JSONB data types? One example would be a "containment" query against JSONB
structures.
Currently I use a work around like this:
type Tag struct {
Key string
Value string
....
}
raw, _ := json.Marshal(Tag{Key: "some-key", "Value": "some-value"})
lk.Select().From("table").Where(lk.Raw(fmt.Sprintf(`tags @> '%s'`, string(raw))))
Thank you for your work on this wonderful library!
At the moment, I'm afraid not... But I'll be glad to give you some pointers and any help you require to implement this type.
https://github.com/ulule/loukoum/blob/b658af15b7c4b97df2c993875bda0e9fc5cc18fe/stmt/expression.go#L293
You could add below a Json
method that accept a JsonOp
interface.
Something like that:
func (identifier Identifier) Json(op JsonOp) InfixExpression {
return NewInfixExpression(identifier, op.Operator(), op.Expression())
}
Where JsonOp
are all kind of JSON operation that you want to support, like containment, existence or even path traversal...
Hope that helps.
@novln Thanks for the suggestions, I will give this a shot as time permits and create a PR.