Skip to content

add handling of objects to processQuery #57

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

Closed
wants to merge 1 commit into from

Conversation

mrgleeco
Copy link

@mrgleeco mrgleeco commented Jul 13, 2019

Change to enable queries on standalone objects. This makes queries like this possible:

j := gojsonq.New().JSONString(`{"name":{"first":"Tom","last":"Hanks"},"age":61}`)
ct := j.Where("age", ">=", 60).Where("name.last", "eq", "Hanks").Count() // 1

@coveralls
Copy link

coveralls commented Jul 13, 2019

Pull Request Test Coverage Report for Build 307

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 305: 0.0%
Covered Lines: 951
Relevant Lines: 951

💛 - Coveralls

1 similar comment
@coveralls
Copy link

Pull Request Test Coverage Report for Build 307

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 305: 0.0%
Covered Lines: 951
Relevant Lines: 951

💛 - Coveralls

@thedevsaddam
Copy link
Owner

Please change the target branch from master to dev

@thedevsaddam
Copy link
Owner

How can I run the query ( SELECT * FROM . WHERE age < 30 )?

{
  "one":{
    "name":"John",
    "age":28
  },
  "two":{
    "name":"Jane",
    "age":30
  },
  "three":{
    "name":"Tom",
    "age":28
  }
}
j := gojsonq.New().FromString(data)
ct := j.Where("*.age", "=", 28).Get() // or more nested like. "*.*.age"
fmt.Println(ct)

@mrgleeco
Copy link
Author

mrgleeco commented Jul 14, 2019

This functionality seems extra; orthogonal (additional?) to the proposed patch.

Are wildcards supported in Where? All docs illustrate example arg strings as key op val, not keymatch

This might be reasonable in future work; docs could illustrate the current behavior and its limits

@thedevsaddam
Copy link
Owner

Issue #24 had an example of querying objects. In this particular case you need something like pattern matching/other good solution. I'm not sure what would be the use case of using Where for single object

@mrgleeco
Copy link
Author

the context is a single message object delivered in a queue (think pubsub or sns). In some cases it may be desirable to filterJSON. Use of the Count() can help guide further message handling

@mrgleeco
Copy link
Author

ping - any interest in merging this?

@thedevsaddam
Copy link
Owner

As Where clause is unnecessary for a single object query, you can simply use the Find method go get the value. I'm closing this PR.

Thank you

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

Successfully merging this pull request may close these issues.

4 participants