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 🙏

© 2026 – Pkg Stats / Ryan Hefner

sql-filtrex

v1.0.1

Published

SQL-like expression parser to generate Where Expression for end-users

Readme

SQL-like Expression Parser for Generating WHERE Clauses

A lightweight, SQL-like expression parser built with Jison, designed to help end-users create dynamic WHERE expressions. It supports logical operators, comparison expressions, SQL functions, and external constants.

This package is dependency-free, except for SQL generation. You need to install and provide a compatible SQLBricks library (e.g., sql-bricks, sql-bricks-sqlite, sql-bricks-postgres, or a custom wrapper).


Refs

[!WARNING] This package uses sql-bricks to generate queries, so it is as safe as sql-bricks itself. Use at your own risk.

Features

  • Supports logical operators: AND, OR, && (and), || (or)
  • Handles comparison operators: =, !=, >, <, >=, <=,<> and is null , is not null
  • support IN clauses with constants and literals
  • Validates and processes SQL functions like UPPER(), LOWER(), SUBSTR()
  • Supports external constants for dynamic value substitution
  • Case-insensitive parsing for SQL keywords
  • Supports sql-bricks parameters => ? , @ , ?1 , @1 , @name

Installation

You can install sql-filtrex via npm:

npm install sql-filtrex

Peer Dependency

sql-filtrex requires a SQL builder library that follows the SQLBricks interface for query generation. You can install the appropriate SQLBricks variant based on your database:

# For general SQL
npm install sql-bricks

# For SQLite
npm install sql-bricks-sqlite

# For PostgreSQL
npm install sql-bricks-postgres

💡 You can also use any custom library that implements the same method interface as sql-bricks.


Usage

You can refer to the test files for more detailed examples. Here's a simple way to use sql-filtrex to generate a WHERE expression:

const { filterToQuery } = require("sql-filtrex");
const sql = require("sql-bricks"); // Install the appropriate SQLBricks version for your DB engine

Example

const options = {
  constants: { MY_CONST: "foo" }, // Optional: replace constants in the expression
  columns: ["field1", "field2"], // Optional: restrict allowed fields (empty = allow all)
  functions: ["UPPER", "LOWER", "SUBSTR"], // Optional: allow specific SQL functions
};

// No DB connection needed—just provide a compatible sql-bricks instance
const filterWhere = filterToQuery(
  sql,
  "field1 = MY_CONST and price >= 10",
  options,
);

// `filterWhere` is equivalent to:
// sql.and(sql.eq('field1', 'foo'), sql.gte('price', 10))

// Use it like any other sql-bricks expression
const sqlQuery = sql.select().from("my_table").where(filterWhere).all();

console.log(sqlQuery);
// Output: SELECT * FROM my_table WHERE field1 = 'foo' AND price >= 10

Configuration

  • constants: An object mapping constant names to their values. These are substituted during parsing.
  • functions: An array of permitted SQL function names. The parser will validate function usage against this list.
  • columns: An array of permitted column names. The parser will validate column usage against this list,empty list means columns will not be checked.

License

This project is licensed under the MIT License.