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

Added Object Query Language #553

Merged
merged 7 commits into from
Oct 16, 2024
Merged

Conversation

dsblank
Copy link
Member

@dsblank dsblank commented Oct 7, 2024

This PR adds a Python Object Query Language to the gramps-web-api. This allows using standard Python on Gramps primary objects. This is based on @DavidMStraub 's "Gramps Query Language".

The QL lives here: https://github.com/dsblank/object-ql and can work on any Python objects. It contains adopted copies of the GQL tests, and should be a drop-in replacement for GQL.

Example queries include:

Find the person with a particular gramps_id:

person.gramps_id == 'person001'

Find all of the people with notes:

person.get_note_list()

Find all of the people with notes that mention 'vote':

any([('vote' in str(get_note(handle).text)) for handle in person.get_note_list()])

If you don't know what the type is, you can use obj, like:

"23" in obj.gramps_id

@DavidMStraub
Copy link
Member

Thanks! I think it's always good to have multiple options to choose from, so I would be happy to include this even if there is overlap with GQL. Just some comments:

  • The reason for the failing checks is that, currently, Gramps Web API still supports Python 3.8. I think it'll work if you just include from __future__ import annotations in your library in the relevant files. I know 3.8 reaches EOL this month, so we might drop support at some point in the near future, but not for the next release.
  • Please include some unit tests. Ideally also with some malicious query attempt 🙂
  • It would be good to settle on a name for your library. Are you sure it will stay "Pythonish QL"?

@dsblank
Copy link
Member Author

dsblank commented Oct 7, 2024

@DavidMStraub, thanks for looking this over!

The reason for the failing checks is that, currently, Gramps Web API still supports Python 3.8. I think it'll work if you just include from future import annotations in your library in the relevant files. I know 3.8 reaches EOL this month, so we might drop support at some point in the near future, but not for the next release.

Good catch... I'll add that.

Please include some unit tests. Ideally also with some malicious query attempt 🙂

There are unit tests here: https://github.com/dsblank/pythonish-ql/tree/main/tests that are based on yours. Do you mean something other than that?

It would be good to settle on a name for your library. Are you sure it will stay "Pythonish QL"?

Ha, no I don't like it. Let me revise that. :)

@dsblank dsblank changed the title Added pythonish query language Added Object Query Language Oct 7, 2024
@dsblank
Copy link
Member Author

dsblank commented Oct 7, 2024

I think I have addressed all of the above, now with a new name object-ql. I'll continue to test on https://github.com/dsblank/object-ql and explore any possible security issues.

@dsblank
Copy link
Member Author

dsblank commented Oct 8, 2024

object_ql now supports a security infrastructure, and resource limitations. Updated minimum version to 0.1.2.

@DavidMStraub
Copy link
Member

Great, thanks! The only thing that's missing is some simple unit tests that the query with oql works as expected. For GQL, I was lazy and just added a couple of cases in test_people.py, you could just copy & paste them for OQL.

@dsblank
Copy link
Member Author

dsblank commented Oct 15, 2024

I'll finish this up with tests. But now that it is looking like we'll have a nice json repr, the prospect of having a query language that looks like python but queries like SQL is possible. Next challenge!

@DavidMStraub DavidMStraub merged commit 598cc80 into gramps-project:master Oct 16, 2024
2 checks passed
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.

2 participants