Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/florents-tselai/litejq

jq extension for SQLite.
https://github.com/florents-tselai/litejq

databases dsl jq json sqlite

Last synced: about 13 hours ago
JSON representation

jq extension for SQLite.

Awesome Lists containing this project

README

        

# liteJQ: jq support in SQLite


GitHub Repo stars
Release


**liteJQ** is an SQLite extension, written in C, that brings `jq` support to SQLite.
It uses vanilla `libjq`.

*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)

## Motivation

SQLite has been supporting JSON for years.
Complex queries, however, involving JSON can be more cumbersome to write and understand,
especially when compared to more complex systems like PostgreSQL.
**liteJQ** attempts to alleviate that by bringing the expressive power of jq into SQLite.

## Installation

```sh
make
```

This produces a `litejq` binary object, which should be loaded in SQLite at runtime.

Verify the installation.

```sh
sqlite3 :memory: < 1980');
```
The above query is equivalent to this one
```sql
select jq(d, '{title: .title, year: .year}')
from movies
where jq(d, '.year') > 1980;
```

**Extract Movies with Specific Keywords in Extract**

```sql
select jq(d, '.extract')
from movies
where jq(d, '.extract | contains("silent")');
```

**Filter movies by a specific genre (e.g., Drama)**

```sql
select jq(d, '{title: .title, year: .year, genres: .genres}')
from movies
where jq(d, '.genres[] == "Drama"');
```

**Filter movies where "Joan Lorring" and "John Dall" played together**

```sql
select jq(d, '{title: .title, year: .year, cast: .cast}')
from movies
where jq(d, '.cast | contains(["Joan Lorring", "John Dall"])');
```

**Group by movies by release year**

```sql
select jq(d, '.year'), count(*)
from movies
group by jq(d, '.year')
```

## Notes On Installation

For this to work, you'll need development files for both SQLite and jq.

### MacOS

```sh
brew install jq sqlite3
make all
```

I've found that `brew` installs header files auomatically for you,
so there's nothing else you have to do

Verify installation

```sh
sqlite3 :memory: <