GithubHelp home page GithubHelp logo

jsonql's Introduction

JsonQL

SQL represented in an unambiguous way in JSON.

  • Safely convertible to SQL on server with no injection attacks
  • Substitute columns or tables with secured versions on server

Everything is a json object: { type: type of object, ... }. Expressions can be literals for number, string, null and boolean.

Types

literal

Literal value. Has: type: "literal" value: some value (e.g. 5, "apple", etc.). Can be null for a null.

query

Top level. Has selects: [select] from: join or table or subquery or subexpression where: boolean expression (optional) groupBy: array of ordinals (1 based) or expressions (optional)
orderBy: array of { ordinal: (1 based) or expr: expression, direction: "asc"/"desc" (default asc), nulls: "last"/"first" (default is not set) } (optional) limit: integer (optional) offset: integer (optional) withs: common table expressions (optional). array of { query:, alias: } distinct: true/false (optional)

op

Expression. Has op:

>, <, <>, =, >=, <=, +, -, *, /, ~, ~*, like, and, or, not, is null, is not null, between avg, min, max, row_number, etc. exists, [], array_agg

For count(*), use count with no expressions.

Has exprs: [expression] modifier: "any", "all", "distinct" (optional) orderBy: array of { expr: expression, direction: "asc"/"desc" } for ordered functions like array_agg(xyz order by abc desc)

Can also contain over for window functions. Both partitionBy and orderBy are optional over: { partitionBy: [ list of expressions ], orderBy: [ list of { expr: expression, direction: "asc"/"desc", nulls: "last"/"first" (default is not set) } ]}

case

Case expression. Has:

input: optional input expression cases: Array of cases. Each has: when, then else: optional else expression

select

Contains an expression and alias { type: "select", expr: expression, alias: alias of expression }

DEPRECATED: Can also contain over for window functions. Both partitionBy and orderBy are optional over: { partitionBy: [ list of expressions ], orderBy: [ list of { expr: expression, direction: "asc"/"desc", nulls: "last"/"first" (default is not set) } ]}

scalar

Scalar subquery. Has: expr: expr where: boolean expression from: join or table orderBy: optional array of { ordinal: (1 based) or expr: expression, direction: "asc"/"desc" (default asc), nulls: "last"/"first" (default is not set) } limit: integer (optional) withs: common table expressions (optional). array of { query:, alias: }

field

References a field of an aliased table

{ type: "field" tableAlias: alias of table column: column of field }

column can be null/undefined to reference the entire row.

table

Single table, aliased. table can also refer to a CTE made by withs using its alias.

{ type: "table", table: tablename, alias: somealias }

join

Join of two tables or joins.

{ type: "join", left: table or join, right: table or join, kind: "inner"/"left"/"right", on: expression to join on }

subquery

query aliased.

{ type: "subquery", query: subquery query, alias: somealias }

subexpr

Subexpression is a from that is an expression, as in select * from someexpression as somealias

{ type: "subexpr", expr: subquery expression, alias: somealias }

token

Special literal token, used for PostGIS, etc. Currently "!bbox!", "!scale_denominator!", "!pixel_width!", "!pixel_height!"

union

Takes a series of unions

{ type: "union" queries: array of type query }

union all

Takes a series of unions

{ type: "union all" queries: array of type query }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.