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

fish-query

v0.2.4

Published

Simple query string builder

Downloads

42

Readme

Fish Query

Build Status Coverage Status

Super simple query string builder. Currently only supports SELECT and cater to PostgreSQL query format.
Built using ES6 Class.

Installation

NPM:
> npm install fish-query

Yarn:
> yarn add fish-query

Usage

const QueryBuilder = require('fish-query');

const queryClass = new QueryBuilder();

let queryString = queryClass
                    .addSelect('firstName')
                    .setFirstTable('user')
                    .generateQuery();
console.log(queryString);

Output should be SELECT firstName from user;

Method

> addSelect

Add the select column on query
Parameter:

  1. String. e.g. : user
  2. Object with property: tableName, columnName, columnAlias (will be formatted to PostgreSQL accepted format)

> addMultipleSelect

Add multiple select column on query
Parameter: Array of Parameters on addSelect

> removeSelect

Remove select column on query Parameter:

  1. String. e.g. : firstName
  2. Object with property: tableName, columnName (will be formatted to PostgreSQL accepted format)

> setFirstTable

Table name specified on FROM
Parameter:

  1. String. e.g. : user
  2. Object with property: tableName, alias (will be formatted to PostgreSQL accepted format)

> joinTable

Join the tables Parameter Object:

  1. joinType: 'FULL JOIN', 'INNER JOIN', etc
  2. firstTable: new table that wants to be joined
  3. firstTableAlias: alias of the new table (optional)
  4. firstKey: the key that wants to be connected to second table
  5. secondTable: other table that wants to be compared with first table
  6. secondTableAlias: other table alias (optional)
  7. secondKey: the key that wants to be connected to first table

Alias will be prioritized when comparing

> addWhere

Add where condition Parameter Object:

  1. column: String or Object. If Object the properties are : tableName, columnName
  2. operator: '=', etc
  3. value: value to be compared

Currently only supports AND for all the where clause.

> addOrder

Add Order By Parameter:

  1. String, e.g. : 'firstName DESC'
  2. Object with property:
    orderBy: Object with property: tableName, columnName
    orderType: 'ASC', 'DESC'

> generateQuery

Generate the Query String after setting up the QueryBuilder instance.

Tests

> npm test

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
As this is a very initial phase, any contribution would be welcomed to support other query formats, or to have UPDATE, INSERT, DELETE, etc.

Future Plan

Add UPDATE, INSERT, DELETE

Author Note

'Ah, I want to eat fish query'

License

MIT License