Group By in Cloud Code

4 posts, 0 answers
  1. EM-Software
    EM-Software avatar
    75 posts
    Member since:
    Feb 2010

    Posted 10 Dec 2014 Link to this post

    Hi,

    I am trying to do same approach as MsSql in the cloud code:

    SELECT item_ID, COUNT(download_ID) AS count_downloads
    FROM downloads
    GROUP BY item_ID

    But i can't find anything from the documentations.
    Is there a way to do this query?

    I have tried to select all records and filter it by item_ID but it will be slow because the table is very large.

    You an idea?
  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 10 Dec 2014 Link to this post

    Hi,

    Currently the only approach would be to get the count of the items by filter on item_id and group them programmatically with additional code. Unfortunately, at the current stage the API does not expose an aggregation/grouping utility. 

    We do have a feature request for this in our Feedback Portal. We'd love to hear any suggestions about this matter in this forum thread or at the page of the feature request.

    Let me know if you have any questions.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  3. EM-Software
    EM-Software avatar
    75 posts
    Member since:
    Feb 2010

    Posted 11 Dec 2014 in reply to Anton Dobrev Link to this post

    Hmm, this is not really a way to do this.

    A alternative way: 
    Create a count column in the items table.
    On each download is performed, add a download record to the downloads table and add one hit to the count column in items table. 
    We will do this way until group feature is added.

    Thanks for your help.
  4. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 11 Dec 2014 Link to this post

    Hello,

    Thank you for your reply.

    Yes, you are right, the proposed by you approach would be a more elegant solution. Here you can find a sample about updating a number field from the Cloud Code (if applicable).

    Let me know if you have further questions or suggestions.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
Back to Top