Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JSON/JSONB ? #36

Open
kevinschoon opened this issue Mar 9, 2018 · 2 comments
Open

Support JSON/JSONB ? #36

kevinschoon opened this issue Mar 9, 2018 · 2 comments

Comments

@kevinschoon
Copy link

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
Copy link
Collaborator

novln commented Mar 9, 2018

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.

@kevinschoon
Copy link
Author

@novln Thanks for the suggestions, I will give this a shot as time permits and create a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants