Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: Count & Spread #2296

Closed
michealroberts opened this issue May 10, 2024 · 6 comments
Closed

[FEATURE]: Count & Spread #2296

michealroberts opened this issue May 10, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@michealroberts
Copy link

Describe what you want

Count and spread it, please. Like this:

const results = db
    .select({ count: count(), ...users._.config.columns })
    .from(users)

But more like this:

const results = db
    .select({ count: count(), ...users.columns() })
    .from(users)
@michealroberts michealroberts added the enhancement New feature or request label May 10, 2024
@denis-ilchishin
Copy link

There's a helper fn getTableColumns in drizzle-orm package. You can use it like ...getTableColumns(users)

@michealroberts
Copy link
Author

@denis-ilchishin What is the full API? Do I pass it through db.select() ...

@denis-ilchishin
Copy link

@michealroberts You can do

const results = db
    .select({ count: count(), ...getTableColumns(users) })
    .from(users)

@michealroberts
Copy link
Author

@denis-ilchishin Hmmm, but this just gives me one record ... the first?

@denis-ilchishin
Copy link

denis-ilchishin commented May 31, 2024

@denis-ilchishin Hmmm, but this just gives me one record ... the first?

I'm not sure about exact query you're trying to execute, and I just showed how to replace ...users._.config.columns.
But I suppose the query above should fail, because of count function, which requires aggregation with group by. So basically this is how sql works, and nothing to do with drizzle

@michealroberts
Copy link
Author

Yeh dumb question, realised that it will aggregate to the count functionality will collapse the query.

I wonder if we could have lazy queries, so being able to call count() just before we apply pagination.

Essentially, the count provides the ability to give us record total.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants