Skip to main content

A JSON query to SQL parser loosely based on the Loopback Query Language

Project description

JTOS

JSON to SQL. Inspired by the Loopback Query Language, this is a standalone Python library to convert JSON objects to SQL.

Schema

Select

{
  "select": {
    "tables": [],
    "fields": []
   }
}

Joins

{
  "join": {
    "type": "LEFT | RIGHT etc",
    "conditions":{
      "from": {
        "table": "",
        "field": ""
      },
      "to": {
        "table": "",
        "field": ""
      }
    } 
  }
}

Where Conditions

{
  "where": [
    {
      "field": "",
      "op": <op>,
      "val": "",
      "join": "o|a"
    }
  ]
}

NOTE: An operator should only be included from the second index and it will be prepended to the built string

Ordering

{
  "select":{
    ...,
    "orderBy": {
      "<field>": "ASC|DESC"
    }
  }
}

Paging

{
  "limit": 100,
  "offset": 3
}

Insert

{
  "insert": {
    "table": "",
    "values": {
      "<field>": "<value>"
    }
  }
}

Operations

  • gt - >
  • lt - <
  • gte - >=
  • lte - <=
  • e - =
  • ne - !=
  • l - LIKE
  • nl - NOT LIKE
  • a - AND
  • a - OR

Notes

This does no authentication or validation, it just blindly trusts the tests.

Do not run on production unless you are comfortable with it in your test environment first

Contributing

Tests, please! But also any work on Upserts or Delete are also greatly appreciated

TODO

  • Select
  • Where
  • Joins
  • Insert
  • Upsert (this syntax is quite different so maybe needs a different parser)
  • Delete

Examples

Examples are included in the tests directory

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

JTOS-0.8.2.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

JTOS-0.8.2-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page