TriPSs/nestjs-query

GroupBy `WEEK`, `MONTH` and `YEAR` doesn't work for postgres.

Closed this issue · 2 comments

Is your feature request related to a problem? Please describe.
Currently grouping by week, month or year only works for MySQL, could we also get this to work for postgres as well?

Have you read the Contributing Guidelines?

No

Describe the solution you'd like
It'd be nice if group by time periods also worked for postgres as well.

Describe alternatives you've considered
None. Looks like I'll need to create a resolver.

Additional context

                if (aggregatedField.args.by === nestjs_query_core_1.GroupBy.YEAR) {
                    query = `DATE(DATE_FORMAT(${col}, '%Y-01-01'))`;
                }
                else if (aggregatedField.args.by === nestjs_query_core_1.GroupBy.MONTH) {
                    query = `DATE(DATE_FORMAT(${col}, '%Y-%m-01'))`;
                }
                else if (aggregatedField.args.by === nestjs_query_core_1.GroupBy.WEEK) {
                    query = `STR_TO_DATE(DATE_FORMAT(${col}, '%X-%V-01'), '%X-%V-%w')`;
                }

Currently that's what the code looks like today, all functions afaik, are MySQL specific.

TriPSs commented

Thanks for posting, I created a PR (#165) that contains a test case for this (which fails now on postgres) will try to check this out when I have some time.

Awesome! thanks for the work :D