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

@deguto/query-param-builder

v1.2.0

Published

Type-safe decorator & builder to generate dynamic SQL WHERE clauses from annotated TypeScript DTOs.

Downloads

27

Readme

@deguto/query-param-builder

GitHub Description: Type-safe decorator & builder to generate dynamic SQL WHERE clauses from annotated TypeScript DTOs.

📖 Overview

query-param-builder fornece um decorator @QueryParam e uma classe ParametroQueryBuilder para facilitar a construção dinâmica de condições SQL (cláusulas WHERE) e seus replacements a partir de DTOs anotados em TypeScript.

🎯 Features

  • Decorator @QueryParam: Anote propriedades do seu DTO com condições SQL e chaves de replacement.
  • ParametroQueryBuilder: Agrupa condições por alias e gera o SQL final com replacements.
  • Transporte simples e modular para projetos Node.js + TypeScript.

🚀 Installation

npm i @deguto/query-param-builder
# ou, se for scoped:
npm i @deguto/query-param-builder --save

⚙️ Usage

1. Defina seu DTO

import { QueryParam } from '@deguto/query-param-builder';

export class AnalisePrevisaoInput {
  @QueryParam(`a.cod_campo1 IN (:campo1)`, 'campo1', 'main')
  @QueryParam(`a.cod_campo1 IN (:campo1)`, 'campo1', 'contexto2')
  campo1?: string[];

  @QueryParam(`a.DATA_PRODUCAO as DATA_PRODUCAO,`, 'trazer_ordens', 'interno', 'select')
  @QueryParam(`a.DATA_PRODUCAO,`, 'trazer_ordens', 'interno', 'groupBy')
  @QueryParam(`DATA_PRODUCAO,`, 'trazer_ordens', 'principal', 'groupBy')
  @QueryParam(`ORDER BY data_producao`, 'trazer_ordens', 'principal', 'orderBy')
  trazer_ordens: boolean;

  @QueryParam(`TRUNC(C.data) >= TO_DATE(:dataInicial, 'YYYY-MM-DD')`, 'dataInicial', 'contexto2')
  dataInicial?: string;

  @QueryParam(`TRUNC(C.data) <= TO_DATE(:dataFinal, 'YYYY-MM-DD')`, 'dataFinal', 'contexto2')
  dataFinal?: string;
}

2. Gere as condições SQL

import { ParametroQueryBuilder } from '@deguto/query-param-builder';

const input = new AnalisePrevisaoInput();
input.campo1 = ['0111', '0222'];
input.dataInicial = '2025-04-01';
input.dataFinal = '2025-04-30';

const builder = new ParametroQueryBuilder(input);

// Obtém string com condições para o alias 'contexto2'
const whereClause = builder.getConditions('contexto2');
// Obtém objeto de replacements para passar ao Sequelize, TypeORM, etc.
const replacements = builder.getReplacements('contexto2');
// Obtém string com propriedades para select para o alias 'contexto2'
const propertiesSelect = builder.getSelect('contexto2');
// Obtém string com propriedades para Group by para o alias 'contexto2'
const propertiesGroupBy = builder.getReplacements('contexto2');
// Obtém string com propriedades para Order by para o alias 'contexto2'
const propertiesOrderBy = builder.getOrderBy('contexto2');



🏗️ Development

  1. Clone o repositório:

git clone https://github.com/d3gut0/query-param-builder.git cd query-param-builder

2. Instale dependências:
   ```bash
npm install
  1. Build:

npm run build

4. Teste local com `npm link`:
   ```bash
npm link
# no projeto consumidor:
npm link @deguto/query-param-builder

📚 API Reference

@QueryParam(condition: string, replacementKey: string, alias: string)

  • condition: string da condição SQL (ex.: a.id = :id).
  • replacementKey: chave usada no objeto de replacements.
  • alias: contexto/alias onde a condição será aplicada.

class ParametroQueryBuilder

  • constructor(input: object): recebe instância do DTO.
  • getConditions(alias: string): string: retorna string de condições SQL concatenadas.
  • getReplacements(alias: string): Record<string, any>: retorna objeto de replacements.

📝 License

Este projeto está licenciado sob a MIT License.

query-param-builder