Skip to content

Commit

Permalink
Merge 53f925e into 1dab42b
Browse files Browse the repository at this point in the history
  • Loading branch information
roikoren755 committed Jun 21, 2021
2 parents 1dab42b + 53f925e commit 9643114
Show file tree
Hide file tree
Showing 14 changed files with 707 additions and 75 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-readers-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"iql": minor
---

feat!: add prefix to {to,from} transformers
5 changes: 5 additions & 0 deletions .changeset/tall-pumpkins-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"iql": patch
---

doc: add typedocs
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn docs
git add docs/
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) => {});
```
102 changes: 102 additions & 0 deletions docs/interfaces/iparamaggregator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[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)[]

## Methods

### key

**key**<K\>(`key`): `string`

#### Type parameters

| Name | Type |
| :------ | :------ |
| `K` | `K`: `string` \| `number` \| `symbol` |

#### Parameters

| Name | Type |
| :------ | :------ |
| `key` | `K` |

#### Returns

`string`

___

### value

**value**(`item`): `string`

#### Parameters

| Name | Type |
| :------ | :------ |
| `item` | [ValueType](../modules.md#valuetype) |

#### Returns

`string`

___

### values

**values**<K\>(`key`): `string`

#### Type parameters

| Name | Type |
| :------ | :------ |
| `K` | `K`: `string` \| `number` \| `symbol` |

#### Parameters

| Name | Type |
| :------ | :------ |
| `key` | `K` |

#### Returns

`string`

**values**(`items`): `string`

#### Parameters

| Name | Type |
| :------ | :------ |
| `items` | [ValueType](../modules.md#valuetype)[] |

#### Returns

`string`
45 changes: 45 additions & 0 deletions docs/interfaces/ipostgresinterval.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[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`

___

### hours

`Optional` **hours**: `number`

___

### milliseconds

`Optional` **milliseconds**: `number`

___

### minutes

`Optional` **minutes**: `number`

___

### seconds

`Optional` **seconds**: `number`
Loading

0 comments on commit 9643114

Please sign in to comment.