iql
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

IQL

Inline Query Language

This package aims to make SQL-like queries type safe and easy to build dynamically with an expressive API

Test Status Coverage Status

Bugs Code Smells Maintainability Rating Reliability Rating Security Rating Technical Debt Vulnerabilities

Snyk Vulnerabilities for GitHub Repo

npm NPM npm npm bundle size

GitHub issues GitHub pull requests GitHub code size in bytes Lines of code GitHub top language

import { Client } from 'pg';
import { query } from 'iql';
import type { QueryResult } from 'iql';

interface IRawUser {
 id: string;
 name: string;
}

interface IUserParams {
 id: string;
 ids: string[];
}

const findA = query<IRawUser, IUserParams>`
SELECT id, name FROM public.users
  WHERE id = ${'id'}
-- WHERE id = $1
  OR id = ${(agg) => agg.key('id')}
-- OR id = $1
  OR id = ${(agg, { id }) => agg.value(id)} -- This creates a new parameter each time it is called
-- OR id = $2
  OR id IN (${(agg, { ids }) => agg.values(ids)}); -- Creates parameters for each member of passed value, each time it is called.
  OR id IN (${(agg) => agg.values('ids')}); -- Same as above
-- OR id IN ($3, $4, ..., $N);
`;

const pg = new Client();

const result = await pg.query<QueryResult<typeof findA>>(findA.compile({ id: '6', ids: ['a', 'b', '5'] }));

// row is of type IRawUser
result.rows.forEach((row) => {});

Supported query executors

Component Query executors Notes
pg pg Used as input to the {Pool,Client}#query method. Also exported as query for backwards compatibility.
bq @google-cloud/bigquery Used as input to the BigQuery#createQueryJob method.

Package Sidebar

Install

npm i iql

Homepage

altnext.com

Weekly Downloads

0

Version

0.3.1

License

MIT

Unpacked Size

43.4 kB

Total Files

28

Last publish

Collaborators

  • roikoren755
  • uncledick
  • joni7777
  • altnext-publisher