Skip to content

Commit

Permalink
Fix regression on selectStarOfAliases and clickhouse replace (#71)
Browse files Browse the repository at this point in the history
* Fix regression on selectStarOfAlias and clickhouse replace

* update docs
  • Loading branch information
lucasavila00 authored Aug 1, 2022
1 parent baec361 commit 629b3e0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
7 changes: 5 additions & 2 deletions docs/api/classes/select-statement.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,11 @@ clickhouse: {
| readonly (Selection | FlatScope)[]
| ((fields: Record<Selection | FlatScope, SafeString>) => ReadonlyArray<SafeString> | SafeString)
) => SelectStatement<Selection, Alias, Scope, FlatScope>
replace: (_: (f: Record<Selection | FlatScope, SafeString> & NoSelectFieldsCompileError) => ReplaceT<Selection>) =>
SelectStatement<Selection, Alias, Scope, FlatScope>
replace: (
_: (
f: Record<Selection | FlatScope, SafeString> & SelectionOfScope<Scope> & NoSelectFieldsCompileError
) => ReplaceT<Selection>
) => SelectStatement<Selection, Alias, Scope, FlatScope>
}
```
Expand Down
2 changes: 1 addition & 1 deletion src/classes/joined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class Joined<
SelectStatement.__fromTableOrSubqueryAndSelectionArray(
this,
[StarOfAliasesSymbol(aliases as any)],
{},
this.__props.scope,
undefined
) as any;
/**
Expand Down
6 changes: 5 additions & 1 deletion src/classes/select-statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,16 @@ export class SelectStatement<
replace: (
_: (
f: Record<Selection | FlatScope, SafeString> &
SelectionOfScope<Scope> &
NoSelectFieldsCompileError
) => ReplaceT<Selection>
): SelectStatement<Selection, Alias, Scope, FlatScope> =>
this.copy().setReplace([
...this.__props.replace,
...(consumeReplaceCallback(_, this.__props.scope) as any),
...(consumeReplaceCallback(
_ as any,
this.__props.scope
) as any),
]),
};

Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ export type SelectionArrayCallbackShape =
) => SafeString | ReadonlyArray<SafeString>);

export type SelectionReplaceCallbackShape = (
f: Record<string, SafeString> & NoSelectFieldsCompileError
f: Record<string, SafeString> &
SelectionOfScope<ScopeShape> &
NoSelectFieldsCompileError
) => ReadonlyArray<readonly [string, SafeString | number]>;

export type SelectionWrapperTypes = ReadonlyArray<
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/regression.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { dsql, table } from "../../src";

test("selectStarOfAliases", () => {
const cols = ["a", "b"] as const;
const q = table(cols, "t")
.select((_f) => ({ a: dsql(1) }))
.as("m")
.join("LEFT", table(cols, "t").selectStar().as("a2"))
.noConstraint()
.selectStarOfAliases(["a2"])
.clickhouse.replace((f) => [["a", f.a2.a]]);

expect(q.stringify()).toMatchInlineSnapshot(
`"SELECT a2.* REPLACE (\`a2\`.\`a\` AS \`a\`) FROM (SELECT 1 AS \`a\` FROM \`t\`) AS \`m\` LEFT JOIN (SELECT * FROM \`t\`) AS \`a2\`"`
);
});

0 comments on commit 629b3e0

Please sign in to comment.