Coder Social home page Coder Social logo

Support sum() as a GROQ function about groq HOT 7 CLOSED

sanity-io avatar sanity-io commented on May 19, 2024 11
Support sum() as a GROQ function

from groq.

Comments (7)

atombender avatar atombender commented on May 19, 2024 2

Hi everyone!

We have now launched this functionality as math::sum(), along with a bunch more stuff.

We have also launched a new GROQ spec, which you can read about in our blog: Content is Queryable: (Re)Introducing GROQ.

from groq.

judofyr avatar judofyr commented on May 19, 2024 1

any alternatives for the mean time? or do I really need to handle this JS side for now?

We definitely want to add this in the future, but at the moment we don't have a timeline for when it will be available. For now you need to handle this in JS.

from groq.

coreyward avatar coreyward commented on May 19, 2024

Any word on this? Would be super useful for something I'm working on.

from groq.

kmelve avatar kmelve commented on May 19, 2024

I don't think it should be too hard to do, but I'll leave it to @judofyr to triage it.

from groq.

paul-vd avatar paul-vd commented on May 19, 2024

I would also love to see this. Here is an example usecase

Example dataset

{
    "_type":"invoice",
    "request":{
        "_ref":"...",
        "_type:":"reference"
    },
    "items":[
        {
            "itemId":1,
            "price":1000
        },
        {
            "itemId":2,
            "price":2000
        },
        {
            "itemId":3,
            "price":3000
        }
    ]
}

An example query where this would be super usefull

*[_type=="request" && _id == $id]{
    invoices: *[_type=="invoice" && reference(^._id)]{
        "totalPrice": sum(items[].price), // shows the total price of all the items eg; 6000
        items
    }
}[0]

from groq.

KenEucker avatar KenEucker commented on May 19, 2024

Echoing this, it would be nice to be able to add the up the size fields from the media in order to determine the size of a given group of media:

*[ _type in ["sanity.imageAsset", "sanity.fileAsset"] ]{"totalSize": sum(items[].size)}

from groq.

yob-yob avatar yob-yob commented on May 19, 2024

any alternatives for the mean time? or do I really need to handle this JS side for now?

from groq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.