gristlabs / grist-core

Grist is the evolution of spreadsheets.
https://www.getgrist.com/
Apache License 2.0
6.9k stars 302 forks source link

[Enhancement] Add API call to evaluate formula(s?) in the context of rows #732

Open inducer opened 9 months ago

inducer commented 9 months ago

Within formulas in rows, I can follow references like $Person.Full_Name, if $Person refers to a reference column. Trying to do the same from within an API client is kind of cumbersome, even with the recently-added SQL API support (thanks btw!). It would be nice if I could just supply a few formulas when requesting records from a table, and the values of the formulas get computed and added as additional columns in the response.

alexmojaki commented 9 months ago

What if you add those formulas as columns to the table?

dsagal commented 9 months ago

I like how Stripe API does this with its expand parameter -- it's not a general formula feature, but specifically a way to replace references to other tables with expanded records: https://stripe.com/docs/api/expanding_objects.

inducer commented 9 months ago

What if you add those formulas as columns to the table?

That wouldn't be my favorite solution, as I think of the formulas as ephemeral. Say, things encountered in an email template. I could programmatically add and then remove them, but... blech.

alexmojaki commented 9 months ago

I think this sounds like a useful feature. It would also pave the way to filtering by formulas, which sounds especially valuable and has been requested:

It also doesn't sound too difficult to implement. The key places to edit are here and here.

expand sounds neat too but also more complicated. It'd probably be most useful for API users with limited access (i.e. where we couldn't allow evaluating arbitrary formulas) but then filtering based on access rules sounds trickier.