Skip to content

support keyword distinct #123

Closed
Closed

Description

@huangyingjie

hello,
Here is another request:

      select distinct country from person;

How to get it?
And Can I execute any sql like hsql in hibernate?

Activity

  1. dresende commented on Apr 15, 2013

    @dresende
    Owner

    There isn't. I started the project as a way for people to completely avoid using sql but now I'm thinking about having that possibility (with a warning about compatibility if switching to other dbms).

  2. dresende commented on Apr 15, 2013

    @dresende
    Owner

    About the distinct, that's the query you want to do (in your example) or a more complex one? I was thinking about the aggregation functions..

  3. huangyingjie commented on Apr 16, 2013

    @huangyingjie
    Author

    just the distinct. Using sql while some functions have not been developped.

  4. dresende commented on Apr 16, 2013

    @dresende
    Owner

    This is probably going to appear a little odd, perhaps we can shorten the code in the future. I added DISTINCT to sql-query dependency and updated ORM. Also, added .as() to add aliases to functions instead of the auto-generated (if needed). Here's an example:

    Person.aggregate().distinct('country').as('country').groupBy('country').get(function (err, countries) {
        // groupBy is needed or else it will return only the first one
    });

    As you can see, .groupBy shouldn't be needed since the query with or without it should return the same thing, but ORM returns only one row for aggregate functions when not using .groupBy.

  5. dresende commented on Apr 16, 2013

    @dresende
    Owner

    This is because DISTINCT is not actually an aggregate function (I think!) but it works well with them.

  6. huangyingjie commented on Apr 17, 2013

    @huangyingjie
    Author

    Acturally it is a bit odd, we use it temporarily.

  7. dresende commented on Apr 17, 2013

    @dresende
    Owner

    You should now be able to do:

    Person.aggregate().distinct('country').get(function (err, countries) {
        // countries should be an Array like [ 'country1', 'country2', ... ]
    });
  8. dresende commented on Apr 17, 2013

    @dresende
    Owner

    If you have a more complex query please post it, I'm not sure how it handles it using more functions.

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