https://github.com/altnext/iql
Open source inline query language
https://github.com/altnext/iql
Last synced: about 1 year ago
JSON representation
Open source inline query language
- Host: GitHub
- URL: https://github.com/altnext/iql
- Owner: AltNext
- License: mit
- Created: 2020-07-27T15:53:54.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2025-05-04T02:10:46.000Z (about 1 year ago)
- Last Synced: 2025-05-04T03:20:56.241Z (about 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 639 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 33
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# IQL
Inline Query Language
This package aims to make SQL-like queries type safe and easy to build dynamically with an expressive API
[](https://github.com/AltNext/iql/actions/workflows/test.yml?query=branch%3Amain)
[](https://coveralls.io/github/AltNext/iql?branch=main)
[](https://sonarcloud.io/dashboard?id=AltNext_iql)
[](https://sonarcloud.io/dashboard?id=AltNext_iql)
[](https://sonarcloud.io/dashboard?id=AltNext_iql)
[](https://sonarcloud.io/dashboard?id=AltNext_iql)
[](https://sonarcloud.io/dashboard?id=AltNext_iql)
[](https://sonarcloud.io/dashboard?id=AltNext_iql)
[](https://sonarcloud.io/dashboard?id=AltNext_iql)
[](https://app.snyk.io/org/altnext/project/https://app.snyk.io/org/altnext/project/615eb00b-5713-4b96-b95b-634bf66f43db)
[](https://www.npmjs.com/package/iql)
[](https://www.npmjs.com/package/iql)
[](https://www.npmjs.com/package/iql)
[](https://www.npmjs.com/package/iql)
[](https://www.github.com/altnext/iql)
[](https://www.github.com/altnext/iql)
[](https://www.github.com/altnext/iql)
[](https://www.github.com/altnext/iql)
[](https://www.github.com/altnext/iql)
```typescript
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`
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>(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. |