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

node-soda2-parser

v2.2.0

Published

Parse Socrata SODA2 API to Abstract Syntax Tree (AST)

Downloads

10

Readme

SODA2 Parser

Parse Socrata's SODA2 API to Abstract Syntax Tree (AST). This library is 99% node-sqlparser and 1% SODA2 to SQL with SODA2 unit tests.

Usage

var Parser = require('node-soda2-parser');
var ast = Parser.parse("$select=date, type, magnitude&$where=magnitude > 3.0 and source = 'pr'&$group=type");

Parses to:

{ type: 'select',
  distinct: null,
  columns:
   [ { expr: { type: 'column_ref', table: '', column: 'date' },
       as: null },
     { expr: { type: 'column_ref', table: '', column: 'type' },
       as: null },
     { expr: { type: 'column_ref', table: '', column: 'magnitude' },
       as: null } ],
  from: null,
  where:
   { type: 'binary_expr',
     operator: 'AND',
     left:
      { type: 'binary_expr',
        operator: '>',
        left: { type: 'column_ref', table: '', column: 'magnitude' },
        right: { type: 'number', value: 3 } },
     right:
      { type: 'binary_expr',
        operator: '=',
        left: { type: 'column_ref', table: '', column: 'source' },
        right: { type: 'string', value: 'pr' } } },
  groupby: [ { type: 'column_ref', table: '', column: 'type' } ],
  orderby: null,
  limit: null,
  params: [] }

With this AST, you can:

  • Convert it to clean SQL using Parser.stringify.parse(ast) (as seen in soda-postgres)
  • Write recursive functions to translate it to another query language
  • Write recursive functions to interact with an ORM
  • Print it out and hang it on the wall

Supported

Unit tests in test/soda ensure the following functionality from the SODA2 docs (which is basically everything except what's listed under Unsupported)

$select

  • Multiple fields
  • Field aliases
  • Functions, ie. $select=date_trunc_ym(datetime) AS month
  • Operators, ie. $select=depth * 3.28 AS depth_feet

$where

  • Basic filters, ie. foo=bar&animal=lion
  • Expressions
  • Recursive And/Or
  • Functions, ie. $where=within_box(incident_location, 47.5998951, -122.33707, 47.5942794, -122.3270522)
  • Between, ie. $where=date between '2015-01-10T12:00:00' and '2015-01-10T14:00:00'
  • Operators, ie. $where=end - start < 1
  • Modulo, ie. $where=foo % 2

Other

  • $group
  • $order
  • $limit
  • $offset

Unsupported

The following was tested and does not parse

  • Not between, ie. $where=date not between '2015-01-10T12:00:00' and '2015-01-10T14:00:00' (reference)
  • Escaping single quote by doubling, ie. $where=text_value='Bob''s string' (reference)
  • Double pipe concatenate, ie. $select=theft_date, dc_dist || dc_num AS dist_dc (reference)
  • Free text search, ie. $q=foobar (reference) (see issue)