Skip to content

Commit

Permalink
Stringified select statement (#24)
Browse files Browse the repository at this point in the history
* add stringified select statement code

* add tests

* add docs
  • Loading branch information
lucasavila00 authored Jul 1, 2022
1 parent 0c1b37a commit 2b4226a
Show file tree
Hide file tree
Showing 35 changed files with 2,362 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules/
*.exec.json
# *.exec.md
docs-ts-out/
dist/
dist/
TODO.md
2 changes: 1 addition & 1 deletion docs-eval/clickhouse-usage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Clickhouse Usage
nav_order: 23
nav_order: 60
parent: Examples
layout: default
---
Expand Down
25 changes: 24 additions & 1 deletion docs-eval/join.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ layout: default
</details>

```ts eval --replacePrintedInput=../src,sql-select-ts
import { table, SafeString, sql, unionAll } from "../src";
import {
table,
SafeString,
sql,
unionAll,
fromStringifiedSelectStatement,
castSafe,
} from "../src";
```

We will use these tables
Expand Down Expand Up @@ -77,6 +84,22 @@ yield admins
.stringify();
```

## Join Stringified Select

```ts eval --yield=sql
const aQueryThatIsAString = users.selectStar().stringify();

const usersStringifiedQuery = fromStringifiedSelectStatement<
"id" | "age" | "name"
>(castSafe(aQueryThatIsAString));

yield admins
.joinStringifiedSelect("u", "LEFT", usersStringifiedQuery)
.on((f) => equals(f["u.id"], f["adm.id"]))
.selectStar()
.stringify();
```

## Join Compound

```ts eval --yield=sql
Expand Down
19 changes: 18 additions & 1 deletion docs-eval/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,24 @@ layout: default
</details>

```ts eval --replacePrintedInput=../src,sql-select-ts
import { fromNothing, sql, table, unionAll } from "../src";
import {
fromNothing,
sql,
table,
unionAll,
fromStringifiedSelectStatement,
} from "../src";
```

# From Raw String (Stringified Select Statement)

```ts eval --yield=sql
const q = fromStringifiedSelectStatement<"a">(sql`SELECT 1 AS a`);

yield q
.selectStar()
.orderBy((f) => f.a)
.stringify();
```

# From Nothing
Expand Down
2 changes: 1 addition & 1 deletion docs-eval/sqlite-usage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: SQLite Usage
nav_order: 23
nav_order: 50
parent: Examples
layout: default
---
Expand Down
54 changes: 54 additions & 0 deletions docs/api/classes/compound.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,34 @@ commaJoinTable: <
Added in v0.0.0
### joinStringifiedSelect (property)
**Signature**
```ts
joinStringifiedSelect: <
Alias1 extends string,
Selection2 extends string,
Alias2 extends string
>(
thisCompoundAlias: Alias1,
operator: string,
selectAlias: Alias2,
select: StringifiedSelectStatement<Selection2>
) =>
JoinedFactory<
| Exclude<Selection, Selection2>
| Exclude<Selection2, Selection>
| `${Alias2}.${Selection2}`
| `${Alias1}.${Selection}`,
Alias1 | Alias2,
Extract<Selection2, Selection>,
Extract<Selection2, Selection>
>;
```
Added in v0.0.3
### joinSelect (property)
**Signature**
Expand Down Expand Up @@ -177,6 +205,32 @@ joinSelect: <
Added in v0.0.0
### commaJoinStringifiedSelect (property)
**Signature**
```ts
commaJoinStringifiedSelect: <
Alias1 extends string,
Selection2 extends string,
Alias2 extends string
>(
thisCompoundAlias: Alias1,
selectAlias: Alias2,
select: StringifiedSelectStatement<Selection2>
) =>
Joined<
| Exclude<Selection, Selection2>
| Exclude<Selection2, Selection>
| `${Alias2}.${Selection2}`
| `${Alias1}.${Selection}`,
Alias1 | Alias2,
Extract<Selection2, Selection>
>;
```
Added in v0.0.3
### commaJoinSelect (property)
**Signature**
Expand Down
42 changes: 42 additions & 0 deletions docs/api/classes/joined.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ joinTable: <Selection2 extends string, Alias2 extends string>(
Added in v0.0.0
### commaJoinStringifiedSelect (property)
**Signature**
```ts
commaJoinStringifiedSelect: <Selection2 extends string, Alias2 extends string>(
alias: Alias2,
select: StringifiedSelectStatement<Selection2>
) =>
Joined<
| Exclude<Selection, Selection2>
| Exclude<Exclude<Selection2, Selection>, Ambiguous>
| `${Alias2}.${Selection2}`,
Aliases | Alias2,
Ambiguous | Extract<Selection2, Selection>
>;
```
Added in v0.0.3
### commaJoinSelect (property)
**Signature**
Expand All @@ -147,6 +167,28 @@ commaJoinSelect: <
Added in v0.0.0
### joinStringifiedSelect (property)
**Signature**
```ts
joinStringifiedSelect: <Selection2 extends string, Alias2 extends string>(
operator: string,
alias: Alias2,
table: StringifiedSelectStatement<Selection2>
) =>
JoinedFactory<
| Exclude<Selection, Selection2>
| Exclude<Exclude<Selection2, Selection>, Ambiguous>
| `${Alias2}.${Selection2}`,
Aliases | Alias2,
Ambiguous | Extract<Selection2, Selection>,
Extract<Selection2, Selection>
>;
```
Added in v0.0.3
### joinSelect (property)
**Signature**
Expand Down
54 changes: 54 additions & 0 deletions docs/api/classes/select-statement.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,32 @@ joinTable: <
Added in v0.0.0
### commaJoinStringifiedSelect (property)
**Signature**
```ts
commaJoinStringifiedSelect: <
Alias1 extends string,
Selection2 extends string,
Alias2 extends string
>(
thisSelectAlias: Alias1,
selectAlias: Alias2,
select: StringifiedSelectStatement<Selection2>
) =>
Joined<
| Exclude<Selection, Selection2>
| Exclude<Selection2, Selection>
| `${Alias2}.${Selection2}`
| `${Alias1}.${Selection}`,
Alias1 | Alias2,
Extract<Selection2, Selection>
>;
```
Added in v0.0.3
### commaJoinSelect (property)
**Signature**
Expand Down Expand Up @@ -278,6 +304,34 @@ commaJoinSelect: <
Added in v0.0.0
### joinStringifiedSelect (property)
**Signature**
```ts
joinStringifiedSelect: <
Alias1 extends string,
Selection2 extends string,
Alias2 extends string
>(
thisSelectAlias: Alias1,
operator: string,
selectAlias: Alias2,
select: StringifiedSelectStatement<Selection2>
) =>
JoinedFactory<
| Exclude<Selection, Selection2>
| Exclude<Selection2, Selection>
| `${Alias2}.${Selection2}`
| `${Alias1}.${Selection}`,
Alias1 | Alias2,
Extract<Selection2, Selection>,
Extract<Selection2, Selection>
>;
```
Added in v0.0.3
### joinSelect (property)
**Signature**
Expand Down
Loading

0 comments on commit 2b4226a

Please sign in to comment.