{"id":15896049,"url":"https://github.com/numberoverzero/jsonquery","last_synced_at":"2025-03-20T15:32:13.587Z","repository":{"id":9875490,"uuid":"11876268","full_name":"numberoverzero/jsonquery","owner":"numberoverzero","description":"Basic json -\u003e sqlalchemy query builder","archived":false,"fork":false,"pushed_at":"2015-05-15T18:53:47.000Z","size":302,"stargazers_count":14,"open_issues_count":1,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-06T20:05:01.920Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/numberoverzero.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-04T08:58:37.000Z","updated_at":"2024-09-11T06:27:24.000Z","dependencies_parsed_at":"2022-09-10T14:11:36.822Z","dependency_job_id":null,"html_url":"https://github.com/numberoverzero/jsonquery","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numberoverzero%2Fjsonquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numberoverzero%2Fjsonquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numberoverzero%2Fjsonquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numberoverzero%2Fjsonquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/numberoverzero","download_url":"https://codeload.github.com/numberoverzero/jsonquery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221776117,"owners_count":16878490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-06T09:05:32.082Z","updated_at":"2024-10-28T04:01:53.877Z","avatar_url":"https://github.com/numberoverzero.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"jsonquery\n========================================================\n\n.. image:: https://travis-ci.org/numberoverzero/jsonquery.svg?branch=master\n    :target: https://travis-ci.org/numberoverzero/jsonquery\n.. image:: https://coveralls.io/repos/numberoverzero/jsonquery/badge.png?branch=master\n    :target: https://coveralls.io/r/numberoverzero/jsonquery?branch=master\n\nBasic json -\u003e sqlalchemy query builder\n\n\nInstallation\n========================================================\n\n::\n\n    pip install jsonquery\n\nBasic Usage\n========================================================\n\nLet's define a model and get an engine set up::\n\n    from sqlalchemy import Column, Integer, String, create_engine\n    from sqlalchemy.orm import sessionmaker\n    from sqlalchemy.ext.declarative import declarative_base\n\n    Base = declarative_base()\n\n    class User(Base):\n        __tablename__ = 'users'\n        id = Column(Integer, primary_key=True)\n        name = Column(String)\n        email = Column(String)\n        age = Column(Integer)\n        height = Column(Integer)\n    engine = create_engine(\"sqlite://\", echo=True)\n    Base.metadata.create_all(engine)\n    model = User\n    session = sessionmaker(bind=engine)()\n\nWe want to get all users whose name starts with 'Pat' and are\nat least 21::\n\n    from jsonquery import jsonquery\n\n    json = {\n        \"operator\": \"and\",\n        \"value\": [\n            {\n                \"operator\": \"\u003e=\",\n                \"column\": \"age\",\n                \"value\": 21\n            },\n            {\n                \"operator\": \"ilike\",\n                \"column\": \"name\",\n                \"value\": \"pat%\"\n            }\n        ]\n    }\n\n    query = jsonquery(session, User, json)\n    users = query.all()\n\nSupported Data Types\n========================================================\n\njsonquery doesn't care about column type.  Instead, it uses a whitelist of operators,\nwhere keys are strings (the same that would be passed in the \"operator\" field of a node)\nand the values are functions that take a column object and a value and return a\nsqlalchemy criterion.  Here are some examples::\n\n    def greater_than(column, value):\n        return column \u003e value\n    register_operator(\"\u003e\", greater_than)\n\n    def like(column, value):\n        like_func = getattr(column, 'like')\n        return like_func(value)\n    register_operator(\"like\", like)\n\nBy default, the following are registered::\n\n    \u003e, \u003e=, ==, !=, \u003c=, \u003c\n    like, ilike, in_\n\nUse ``unregister_operator(opstring)`` to remove an operator.\n\nFuture Goals\n========================================================\n\nThere are a few features I want to add, but these are mostly convenience and aren't necessary to\nthe core application, which I believe is satisfied.\n\nCompressed and/or format\n--------------------------------------------------------\n\nReduce repetitive column and operator specification when possible by allowing non-scalar values\nfor column operators.  By flipping the nesting restriction on logical operators, we can omit\nfields specified at the column level.  This is especially prominent in string matching,\nwhen the column and operator are the same, but we want to compare against 3+ values.\n\nCurrently::\n\n    {\n        \"operator\": \"or\",\n        \"value\": [\n            {\n                \"column\": \"age\",\n                \"operator\": \"\u003c=\",\n                \"value\": 16\n            },\n            {\n                \"column\": \"age\",\n                \"operator\": \"\u003e=\",\n                \"value\": 21\n            },\n            {\n                \"column\": \"age\",\n                \"operator\": \"==\",\n                \"value\": 18\n            }\n        ]\n    }\n\nWith compressed logical operators::\n\n    {\n        \"column\": \"age\"\n        \"value\": {\n            \"operator\": \"or\",\n            \"value\": [\n                {\n                    \"operator\": \"\u003c=\",\n                    \"value\": 16\n                },\n                {\n                    \"operator\": \"\u003e=\",\n                    \"value\": 21\n                },\n                {\n                    \"operator\": \"==\",\n                    \"value\": 18\n                }\n            ]\n        }\n    }\n\nOr, when the operator is the same::\n\n    {\n        \"column\": \"name\"\n        \"operator\": \"like\"\n        \"value\": {\n            \"operator\": \"or\",\n            \"value\": [\n                \"Bill\",\n                \"Mary\",\n                \"Steve\"\n            ]\n        }\n    }\n\nContributors\n========================================================\n\n* duesenfranz_ - Python 3 compatibility\n* svisser_ - Python 3 compatibility\n\n.. _duesenfranz: https://github.com/duesenfranz\n.. _svisser: https://github.com/svisser\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumberoverzero%2Fjsonquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnumberoverzero%2Fjsonquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumberoverzero%2Fjsonquery/lists"}