ulule/loukoum

Support JSON/JSONB ?

kevinschoon opened this issue · 2 comments

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!

novln commented

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.

func (identifier Identifier) NotBetween(from, to interface{}) Between {

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.