{"id":17856064,"url":"https://github.com/Florents-Tselai/liteJQ","last_synced_at":"2025-03-20T14:30:50.597Z","repository":{"id":223913775,"uuid":"761895661","full_name":"Florents-Tselai/liteJQ","owner":"Florents-Tselai","description":"jq extension for SQLite.","archived":false,"fork":false,"pushed_at":"2024-07-08T07:18:36.000Z","size":220,"stargazers_count":93,"open_issues_count":4,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-11T21:51:19.433Z","etag":null,"topics":["databases","dsl","jq","json","sqlite"],"latest_commit_sha":null,"homepage":"https://tselai.com/litejq.html","language":"C","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/Florents-Tselai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["Florents-Tselai"]}},"created_at":"2024-02-22T17:29:42.000Z","updated_at":"2025-02-27T07:12:27.000Z","dependencies_parsed_at":"2024-03-09T08:29:43.018Z","dependency_job_id":"93a73391-5d96-45ef-9a1d-6beec0defad5","html_url":"https://github.com/Florents-Tselai/liteJQ","commit_stats":{"total_commits":25,"total_committers":1,"mean_commits":25.0,"dds":0.0,"last_synced_commit":"973fbdbebaf3c656efd8d43e82a0d9053e1a12a9"},"previous_names":["florents-tselai/litejq"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2FliteJQ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2FliteJQ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2FliteJQ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Florents-Tselai%2FliteJQ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Florents-Tselai","download_url":"https://codeload.github.com/Florents-Tselai/liteJQ/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244630053,"owners_count":20484306,"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":["databases","dsl","jq","json","sqlite"],"created_at":"2024-10-28T03:00:46.086Z","updated_at":"2025-03-20T14:30:50.126Z","avatar_url":"https://github.com/Florents-Tselai.png","language":"C","funding_links":["https://github.com/sponsors/Florents-Tselai","https://github.com/sponsors/Florents-Tselai/","https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026link=https://github.com/sponsors/Florents-Tselai/"],"categories":["Extensions"],"sub_categories":[],"readme":"# liteJQ: jq support in SQLite\u003c/strong\u003e\n\n\u003ca href=\"https://github.com/Florents-Tselai/litejq/actions/workflows/test.yml?branch=mainline\"\u003e\u003cimg src=\"https://github.com/Florents-Tselai/litejq/actions/workflows/test.yml/badge.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Florents-Tselai/liteJQ/stargazers\"\u003e\u003cimg alt=\"GitHub Repo stars\" src=\"https://img.shields.io/github/stars/Florents-Tselai/liteJQ\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Florents-Tselai/litejq/releases\"\u003e\u003cimg alt=\"Release\" src=\"https://img.shields.io/github/v/release/Florents-Tselai/liteJQ\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.linkedin.com/in/florentstselai/\"\u003e\u003cimg src=\"https://img.shields.io/badge/LinkedIn-0077B5?logo=linkedin\u0026logoColor=white\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/sponsors/Florents-Tselai/\"\u003e\u003cimg src=\"https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026link=https://github.com/sponsors/Florents-Tselai/\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/MIT License\"\u003e\u003cimg src=\"https://img.shields.io/badge/MIT License-blue.svg\"\u003e\u003c/a\u003e\n\n\n**liteJQ** is an SQLite extension, written in C, that brings `jq` support to SQLite.\nIt uses vanilla `libjq`.\n\n*Note*: If you like the idea, but you're more into Postgres, check out: [pgJQ: jq extension for Postgres](https://github.com/Florents-Tselai/pgJQ)\n\n## Motivation\n\nSQLite has been supporting JSON for years.\nComplex queries, however, involving JSON can be more cumbersome to write and understand,\nespecially when compared to more complex systems like PostgreSQL.\n**liteJQ** attempts to alleviate that by bringing the expressive power of jq into SQLite.\n\n## Installation\n\n```sh\nmake\n```\n\nThis produces a `litejq` binary object, which should be loaded in SQLite at runtime.\n\nVerify the installation.\n\n```sh\nsqlite3 :memory: \u003c\u003cEOF\n.load ./litejq\nselect jq('{\"key\": \"litejq is loaded\"}', '.key')\nEOF\n```\n\n## Usage\n\n```sqlite\nSELECT jq(json, jqprog)\n```\n\n### Examples\n\nWe'll use the movie dataset as a running example.\n```bash\nsqlite3 movies.db \u003c ./data/movies.sql\n```\nWe have a very simple schema:\n```sqlite\nCREATE TABLE [movies] (\n   \"d\" TEXT -- json\n);\n```\nColumn `d` holds json values in plain text like this.\n```json\n{\n    \"title\": \"The Corn Is Green\",\n    \"year\": 1945,\n    \"cast\": [\n      \"Bette Davis\",\n      \"Joan Lorring\",\n      \"John Dall\"\n    ],\n    \"genres\": [\n      \"Drama\"\n    ],\n    \"href\": \"The_Corn_Is_Green_(1945_film)\",\n    \"extract\": \"The Corn Is Green is a 1945 American drama film starring Bette Davis as a schoolteacher determined to bring education to a Welsh coal mining town despite great opposition. It was adapted from the 1938 play of the same name by Emlyn Williams, which originally starred Ethel Barrymore.\",\n    \"thumbnail\": \"https://upload.wikimedia.org/wikipedia/en/thumb/b/bf/The-corn-is-green-poster.jpg/320px-The-corn-is-green-poster.jpg\",\n    \"thumbnail_width\": 320,\n    \"thumbnail_height\": 248\n  }\n```\nIn any session, you should load the extension first after building it, like this:\n```sqlite\n.load ./litejq\n```\nThen you can start doing `jq` magic.\nLet's see some example queries.\n\n**List all movie titles**\n\n\n```sql\nselect jq(d, '.title')\nfrom movies;\n```\n\n**To find movies released after a specific year, for example, 1980**\n\n```sql\nselect jq(d, '{title: .title, year: .year}')\nfrom movies\nwhere jq(d, '.year \u003e 1980');\n```\nThe above query is equivalent to this one\n```sql\nselect jq(d, '{title: .title, year: .year}')\nfrom movies\nwhere jq(d, '.year') \u003e 1980;\n```\n\n**Extract Movies with Specific Keywords in Extract**\n\n```sql\nselect jq(d, '.extract')\nfrom movies\nwhere jq(d, '.extract | contains(\"silent\")');\n```\n\n**Filter movies by a specific genre (e.g., Drama)**\n\n```sql\nselect jq(d, '{title: .title, year: .year, genres: .genres}')\nfrom movies\nwhere jq(d, '.genres[] == \"Drama\"');\n```\n\n**Filter movies where \"Joan Lorring\" and \"John Dall\" played together**\n\n```sql\nselect jq(d, '{title: .title, year: .year, cast: .cast}')\nfrom movies\nwhere jq(d, '.cast | contains([\"Joan Lorring\", \"John Dall\"])');\n```\n\n**Group by movies by release year**\n\n```sql\nselect jq(d, '.year'), count(*)\nfrom movies\ngroup by jq(d, '.year')\n```\n\n## Notes On Installation\n\nFor this to work, you'll need development files for both SQLite and jq.\n\n### MacOS\n\n```sh\nbrew install jq sqlite3\nmake all\n```\n\nI've found that `brew` installs header files auomatically for you,\nso there's nothing else you have to do\n\nVerify installation\n\n```sh\nsqlite3 :memory: \u003c\u003cEOF\n.load ./litejq\nselect jq('{\"key\": \"value\"}', '.key')\nEOF\n```\n\n### Linux\n\n```sh\nsudo apt install sqlite3 libsqlite3-dev jq libjq-dev\n```\n\nOn Linux, sometimes things can be trickier because\nmany distros don't have `jq` configured with `pkg-config`\nso your best guess would be installing `jq` from source first.\n\nIf you already have `jq` installed to a known prefix,\ntry using it explicitly:\n\n```sh\nJQ_PREFIX=/usr/local make\n```\n\nIf this doesn't work,\nyou can (and probably should) build it from source.\n\n#### Build `jq` from source\n\n```sh\ncd /tmp \u0026\u0026\n  wget \"https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-1.7.1.tar.gz\" \u0026\u0026\n  tar xzf jq-1.7.1.tar.gz \u0026\u0026\n  cd jq-1.7.1 \u0026\u0026\n  ./configure --with-oniguruma=builtin --prefix=/usr/local \u0026\u0026\n  sudo make install\n```\n\nThen try again\n\n```sh\nmake\n```\n\n```sh\nsqlite3 :memory: \u003c\u003cEOF\n.load ./litejq\nselect jq('{\"key\": \"litejq is loaded\"}', '.key')\nEOF\n```\n\n# Others\n\n* I've also created [pgJQ](https://github.com/Florents-Tselai/pgJQ) which brings jq to Postgres.\n* There is another [jq-sqlite](https://mgdm.net/weblog/using-jq-in-sqlite/) similar, but it's written in Go and relies on a non-vanilla implementation of JQ.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFlorents-Tselai%2FliteJQ","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFlorents-Tselai%2FliteJQ","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFlorents-Tselai%2FliteJQ/lists"}