Get subquery columns in a way similar to `getTableColumns`
Keeping track manually of all subquery fields can quickly become annoying, and I'm looking for a simple helper to allow specifying fields with a pattern similar to what
getTableColumns
enables. Has anyone implemented a small helper that's somewhat "battle-tested"? Here's what I have at the moment, but I'm not trusting it that much due to how naive it is and due to the necessary typecasting.
8 Replies
interesting
What is
SubqueryConfig
?
I see, you imported it from drizzle. That's smart. This should work no problem.
But could you please add a issue for this in GH? to add this helper function to drizzle: getSubqueryColumns
GitHub
[FEATURE]: Add
getSubqueryFields
helper to goodies · Issue #1459 ...Describe what you want The getTableColumns helper is really useful, but an equivalent lacks for subqueries. This can easily be implemented in userland, although it feels like the kind of helper tha...
Thank you, this could be a pretty easy PR
I have this one too. Does the same :p
Personally my vote goes to striving for making things less specific and providing a single helper. This PR should answer most use case: https://github.com/drizzle-team/drizzle-orm/pull/1789
GitHub
Feat: add
getColumns
function to utils by Angelelz · Pull Request...close #1459
Added new getColumns function that accepts Table | View | Subquery and returns the columns (selected fields).
Added deprecation note to getTableColumns.
Added tests for all 3 dialects.
Sure, I've dropped a like on the PR!
Hey @iolyd, I've seen that you've played with this. I haven't have time to add anything else to this PR. Do we still need to add the type for a subquery without the alias?
Good question, I personally didn't end up having cases where I had to use it, but I still think it could be useful for others.