-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
764 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
iql / [Exports](modules.md) | ||
|
||
# IQL | ||
|
||
Inline Query Language | ||
|
||
This package aims to make SQL-like queries type safe and easy to build dynamically with an expressive API | ||
|
||
[![Coverage Status](https://github.com/altnext/iql/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/AltNext/iql/actions/workflows/test.yml?query=branch%3Amain) | ||
[![Coverage Status](https://coveralls.io/repos/github/AltNext/iql/badge.svg?branch=main)](https://coveralls.io/github/AltNext/iql?branch=main) | ||
|
||
```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<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) => {}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
[iql](../README.md) / [Exports](../modules.md) / IParamAggregator | ||
|
||
# Interface: IParamAggregator<T, U\> | ||
|
||
The aggregator, used by the query function to parse and manipulate parameters | ||
|
||
## Type parameters | ||
|
||
| Name | | ||
| :------ | | ||
| `T` | | ||
| `U` | | ||
|
||
## Table of contents | ||
|
||
### Properties | ||
|
||
- [props](iparamaggregator.md#props) | ||
|
||
### Methods | ||
|
||
- [key](iparamaggregator.md#key) | ||
- [value](iparamaggregator.md#value) | ||
- [values](iparamaggregator.md#values) | ||
|
||
## Properties | ||
|
||
### props | ||
|
||
• **props**: [ValueType](../modules.md#valuetype)[] | ||
|
||
#### Defined in | ||
|
||
[src/interfaces.ts:30](https://github.com/altnext/iql/blob/1dab42b/src/interfaces.ts#L30) | ||
|
||
## Methods | ||
|
||
### key | ||
|
||
▸ **key**<K\>(`key`): `string` | ||
|
||
#### Type parameters | ||
|
||
| Name | Type | | ||
| :------ | :------ | | ||
| `K` | `K`: `string` \| `number` \| `symbol` | | ||
|
||
#### Parameters | ||
|
||
| Name | Type | | ||
| :------ | :------ | | ||
| `key` | `K` | | ||
|
||
#### Returns | ||
|
||
`string` | ||
|
||
#### Defined in | ||
|
||
[src/interfaces.ts:31](https://github.com/altnext/iql/blob/1dab42b/src/interfaces.ts#L31) | ||
|
||
___ | ||
|
||
### value | ||
|
||
▸ **value**(`item`): `string` | ||
|
||
#### Parameters | ||
|
||
| Name | Type | | ||
| :------ | :------ | | ||
| `item` | [ValueType](../modules.md#valuetype) | | ||
|
||
#### Returns | ||
|
||
`string` | ||
|
||
#### Defined in | ||
|
||
[src/interfaces.ts:32](https://github.com/altnext/iql/blob/1dab42b/src/interfaces.ts#L32) | ||
|
||
___ | ||
|
||
### values | ||
|
||
▸ **values**<K\>(`key`): `string` | ||
|
||
#### Type parameters | ||
|
||
| Name | Type | | ||
| :------ | :------ | | ||
| `K` | `K`: `string` \| `number` \| `symbol` | | ||
|
||
#### Parameters | ||
|
||
| Name | Type | | ||
| :------ | :------ | | ||
| `key` | `K` | | ||
|
||
#### Returns | ||
|
||
`string` | ||
|
||
#### Defined in | ||
|
||
[src/interfaces.ts:33](https://github.com/altnext/iql/blob/1dab42b/src/interfaces.ts#L33) | ||
|
||
▸ **values**(`items`): `string` | ||
|
||
#### Parameters | ||
|
||
| Name | Type | | ||
| :------ | :------ | | ||
| `items` | [ValueType](../modules.md#valuetype)[] | | ||
|
||
#### Returns | ||
|
||
`string` | ||
|
||
#### Defined in | ||
|
||
[src/interfaces.ts:34](https://github.com/altnext/iql/blob/1dab42b/src/interfaces.ts#L34) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
[iql](../README.md) / [Exports](../modules.md) / IPostgresInterval | ||
|
||
# Interface: IPostgresInterval | ||
|
||
Postgres internal representation of intervals | ||
|
||
## Table of contents | ||
|
||
### Properties | ||
|
||
- [days](ipostgresinterval.md#days) | ||
- [hours](ipostgresinterval.md#hours) | ||
- [milliseconds](ipostgresinterval.md#milliseconds) | ||
- [minutes](ipostgresinterval.md#minutes) | ||
- [seconds](ipostgresinterval.md#seconds) | ||
|
||
## Properties | ||
|
||
### days | ||
|
||
• `Optional` **days**: `number` | ||
|
||
#### Defined in | ||
|
||
[src/interfaces.ts:7](https://github.com/altnext/iql/blob/1dab42b/src/interfaces.ts#L7) | ||
|
||
___ | ||
|
||
### hours | ||
|
||
• `Optional` **hours**: `number` | ||
|
||
#### Defined in | ||
|
||
[src/interfaces.ts:8](https://github.com/altnext/iql/blob/1dab42b/src/interfaces.ts#L8) | ||
|
||
___ | ||
|
||
### milliseconds | ||
|
||
• `Optional` **milliseconds**: `number` | ||
|
||
#### Defined in | ||
|
||
[src/interfaces.ts:11](https://github.com/altnext/iql/blob/1dab42b/src/interfaces.ts#L11) | ||
|
||
___ | ||
|
||
### minutes | ||
|
||
• `Optional` **minutes**: `number` | ||
|
||
#### Defined in | ||
|
||
[src/interfaces.ts:9](https://github.com/altnext/iql/blob/1dab42b/src/interfaces.ts#L9) | ||
|
||
___ | ||
|
||
### seconds | ||
|
||
• `Optional` **seconds**: `number` | ||
|
||
#### Defined in | ||
|
||
[src/interfaces.ts:10](https://github.com/altnext/iql/blob/1dab42b/src/interfaces.ts#L10) |
Oops, something went wrong.