kysely-org / kysely

A type-safe typescript SQL query builder
https://kysely.dev
MIT License
9.9k stars 249 forks source link

Added `clearGroupBy()` #921

Closed dswbx closed 3 months ago

dswbx commented 3 months ago

Adds the option to remove group by clause from SelectQueryBuilder using clearGroupBy() (as discussed in https://discord.com/channels/890118421587578920/1073948476590792786/threads/1221117943081996429)

I've only added a single node test, should I add additional ones for other environments?


Unrelated to this PR in particular: I had some issues making tests for mssql work. After following https://github.com/kysely-org/kysely/issues/906 it worked. Maybe we should add this to the Contribution Guidelines? Additionally I've had issues with prettier modifying indentation and tsc complaining about Duplicate identifier 'Prepend' – I had to manually disable lib checks. I'm running on node v20.8.0 and npm 10.1.0

vercel[bot] commented 3 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 24, 2024 0:42am
koskimas commented 3 months ago

Thank you!

Additionally I've had issues with prettier modifying indentation

What do you mean by this? That's one of the things it's supposed to do, isn't it?

tsc complaining about Duplicate identifier 'Prepend'

I haven't experienced this one. Can you paste the whole error?

Maybe we should add this to the Contribution Guidelines

Good idea!

dswbx commented 3 months ago

@koskimas regarding the type issue I was referring to, it's a bit embarrassing. Found out that a few directories up, I ran pnpm install and so that's where it came from. After removing it, the type issues are gone – sorry!

Regarding prettier, yes it's supposed to format the code, but it changed indentation within select-query-builder.ts I haven't modified. Here is an example running the prettier command on a clean repo:

$ git reset --hard origin/master
$ npm ci

added 416 packages, and audited 417 packages in 3s

100 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
$ npm run prettier

> kysely@0.27.3 prettier
> prettier --write 'src/**/*.ts' 'test/**/*.ts'

[...]

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   src/operation-node/output-node.ts
        modified:   src/operation-node/select-query-node.ts
        modified:   src/parser/select-parser.ts
        modified:   src/parser/value-parser.ts
        modified:   src/query-builder/delete-query-builder.ts
        modified:   src/query-builder/insert-query-builder.ts
        modified:   src/query-builder/select-query-builder.ts
        modified:   src/query-builder/update-query-builder.ts
        modified:   src/schema/column-definition-builder.ts
        modified:   src/util/type-utils.ts
        modified:   test/node/src/introspect.test.ts
        modified:   test/node/src/test-setup.ts
        modified:   test/typings/test-d/insert.test-d.ts

no changes added to commit (use "git add" and/or "git commit -a")

$ npm ls prettier
kysely@0.27.3 /Users/dennis/Projects/tmp/repos/kysely
└── prettier@3.2.5
$ git diff src/query-builder/select-query-builder.ts
diff --git a/src/query-builder/select-query-builder.ts b/src/query-builder/select-query-builder.ts
index dcdbe5c7..901db04f 100644
--- a/src/query-builder/select-query-builder.ts
+++ b/src/query-builder/select-query-builder.ts
@@ -2477,12 +2477,12 @@ export type SelectQueryBuilderWithInnerJoin<
     ? InnerJoinedBuilder<DB, TB, O, A, DB[T]>
     : never
   : TE extends keyof DB
-  ? SelectQueryBuilder<DB, TB | TE, O>
-  : TE extends AliasedExpression<infer QO, infer QA>
-  ? InnerJoinedBuilder<DB, TB, O, QA, QO>
-  : TE extends (qb: any) => AliasedExpression<infer QO, infer QA>
-  ? InnerJoinedBuilder<DB, TB, O, QA, QO>
-  : never
+    ? SelectQueryBuilder<DB, TB | TE, O>
+    : TE extends AliasedExpression<infer QO, infer QA>
+      ? InnerJoinedBuilder<DB, TB, O, QA, QO>
+      : TE extends (qb: any) => AliasedExpression<infer QO, infer QA>
+        ? InnerJoinedBuilder<DB, TB, O, QA, QO>
+        : never

[...]

Could be also an issue on my end, like with the typing issue.

koskimas commented 3 months ago

Oh, yeah. We don't have anything that automatically runs prettier. This happens when we update prettier to a newer version and forget to run prettier for all files. You can either discard those changes or just add them to the PR.