Skip to content

groupBy datetime #204

Closed
Closed

Description

@Locke

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.

Activity

  1. dresende commented on Jun 20, 2013

    @dresende
    Owner

    Can you show me an sql example?

  2. added a commit that references this issue on Jun 20, 2013
  3. dresende commented on Jun 20, 2013

    @dresende
    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.

  4. Locke commented on Jun 20, 2013

    @Locke
    Author

    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.

  5. dresende commented on Jun 20, 2013

    @dresende
    Owner

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

  6. Locke commented on Jun 21, 2013

    @Locke
    Author

    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.

  7. dresende commented on Jun 21, 2013

    @dresende
    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.

  8. dresende commented on Jun 21, 2013

    @dresende
    Owner

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

  9. dresende commented on Jul 5, 2013

    @dresende
    Owner

    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.

  10. Locke commented on Jul 6, 2013

    @Locke
    Author

    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" notifications@github.com:

    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions