npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mwater/jsonql

v1.14.1

Published

JSON representation of SQL

Downloads

31

Readme

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 }