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

groupBy datetime #204

Closed
Locke opened this issue Jun 20, 2013 · 9 comments
Closed

groupBy datetime #204

Locke opened this issue Jun 20, 2013 · 9 comments

Comments

@Locke
Copy link

Locke commented Jun 20, 2013

Depending on dresende/node-sql-query#10 I want to group by a DATETIME field and want to pass the format string to be able to group by a day, year or even an hour.

@dresende
Copy link
Owner

Can you show me an sql example?

dresende added a commit that referenced this issue Jun 20, 2013
@dresende
Copy link
Owner

ORM still does not support it, I have to think how to do it. If you have any idea of how this could be done please post an example.

@Locke
Copy link
Author

Locke commented Jun 20, 2013

If I see it correct ORM does not use the .fun(..) method from node-sql-query, does it?

I'm thinking about either a general support for the fun method or a special implementation with strftime.

@dresende
Copy link
Owner

Yes, it doesn't use it but maybe it should, or... the drivers should. Or at least expose it.

@Locke
Copy link
Author

Locke commented Jun 21, 2013

In Locke/node-orm2 and Locke/node-sql-query I simply added strftime to the aggregation functions and can now group via:

Model.aggregate().count().strftime([ query.Text('%Y-%m-%d'), 'date' ]).groupBy('strftime_date').get(...)

I don't know if it's compatible with all drivers, therefore I updated only the sqlite driver.

As this is a lot of typing I could imagine adding wrappers like .groupByDay('myDateField') in the AggregateFunctions proto.

@dresende
Copy link
Owner

I just don't want to add strftime directly, I want to expose the generic function call. And have also to expose the query part.

@dresende
Copy link
Owner

I would expose strftime if it was generic or have the same function across drivers (even if it had different names).

dresende added a commit that referenced this issue Jul 5, 2013
@dresende
Copy link
Owner

dresende commented Jul 5, 2013

You can now call any supported function like this:

Person.aggregate().call("strftime", [ orm.Text('%Y-%m-%d'), 'date' ]).as('dt').groupBy('dt').get(function () {
    console.log(arguments);
});

The .as() is optional and it's just an alias that can for example be used in .groupBy.

Please try the latest commit and see if it works for you.

@Locke
Copy link
Author

Locke commented Jul 6, 2013

Great, in my testcase that works fine. I still need to deploy that into my
productive environment, but I don't expect any complications. I'll close
this issue if it works.
Am 06.07.2013 01:03 schrieb "Diogo Resende" [email protected]:

You can now call any supported function like this:

Person.aggregate().call("strftime", [ orm.Text('%Y-%m-%d'), 'date' ]).as('dt').groupBy('dt').get(function () {
console.log(arguments);});

The .as() is optional and it's just an alias that can for example be used
in .groupBy.

Please try the latest commit and see if it works for you.


Reply to this email directly or view it on GitHubhttps://github.com//issues/204#issuecomment-20543222
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants