Skip to content

Commit

Permalink
Merge 8c509be into 1dab42b
Browse files Browse the repository at this point in the history
  • Loading branch information
roikoren755 committed Jun 21, 2021
2 parents 1dab42b + 8c509be commit 39bdd12
Show file tree
Hide file tree
Showing 11 changed files with 764 additions and 79 deletions.
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,37 @@ This package aims to make SQL-like queries type safe and easy to build dynamical
[![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;
id: string;
name: string;
}

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

const findA = query<IRawUser, IUserParams>`
SELECT id, name FROM public.users
WHERE id = ${'id'};
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) => {});
```
46 changes: 46 additions & 0 deletions docs/README.md
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) => {});
```
122 changes: 122 additions & 0 deletions docs/interfaces/iparamaggregator.md
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)
65 changes: 65 additions & 0 deletions docs/interfaces/ipostgresinterval.md
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)
Loading

0 comments on commit 39bdd12

Please sign in to comment.