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-select-query-generator

v1.2.0

Published

Generate SQL Server SELECT queries with joins, filters, pagination, total counts, and JSON output.

Readme

SQL SELECT Query Generator

Version

Generate SQL Server SELECT queries with joins, filters, pagination, a total count, and FOR JSON PATH output.

Installation

npm install sql-select-query-generator

Node.js 18 or newer is required.

Usage

const queryGenerator = require("sql-select-query-generator");

const sampleQuery = {
  tableName: "Orders",
  searchField: "customer.name",
  selectColumns: [{ fieldName: "*", alias: "" }],
  customOrSearch: ["customer.address", "customer.phone"],
  customAndSearch: ["t.total_cost"],
  joins: [
    {
      tableName: "Customers",
      joinName: "customer",
      type: "LEFT",
      isCustomJoin: false,
      selectColumns: [
        { fieldName: "name", alias: "customer_name" },
        { fieldName: "address", alias: "" },
        { fieldName: "phone", alias: "phone" },
      ],
    },
  ],
  queryParams: {
    limit: 20,
    offset: 5,
    sortBy: "DESC",
    orderBy: "t.id",
    searchTerm: "abc",
  },
};

const sql = await queryGenerator(sampleQuery);
console.log(sql);

For a runnable version, use npm run example or see examples/basic.js.

Options

| Field | Description | | --- | --- | | tableName | Required target table. It is aliased as t. | | selectColumns | Required columns from the target table. Supports alias and field_type: "json". | | searchField | Primary field searched by queryParams.searchTerm. Search text is matched literally within %...%. | | customOrSearch | Additional fields included in the text-search OR group. It can be used without searchField. | | customAndSearch | Fields that must also match the search term. It can be used without searchField. | | customSearch | Exact { field, value } filters. String values are SQL-escaped. | | nullCheckColumns | Fields required to be non-null. The old misspelling nullCheckColums remains supported. | | customColumnQuery | Trusted custom SELECT expression appended to the selected columns. | | joins | Join definitions with tableName, joinName, optional type, selected columns, and optional custom join/filter fields. | | queryParams | searchTerm, orderBy (default t.id), sortBy (ASC or DESC), offset (default 0), and limit (default 20). |

The function returns a Promise containing the SQL string. Table names, column names, join expressions, orderBy, and customColumnQuery are SQL syntax and must come from trusted application configuration. User-provided values belong in searchTerm or exact-search value fields, which escape single quotes.

Contributing

Contributions are welcome. Read CONTRIBUTING.md, follow the code of conduct, and run npm test before opening a pull request. See the changelog for release notes.

Report vulnerabilities privately as described in SECURITY.md.

Releases are published automatically from version tags through npm Trusted Publishing. Maintainer setup and release commands are in CONTRIBUTING.md.

Contributors

See the repository's contributors.

Author

@amrishkhan05

License

MIT