Hi,
I was wondering if there is any way to track the number of "views" of a record. Like every time a specific query is executed and returns a record, we would increment the number of views of that record.
SQL views and functions cannot update the table, triggers cannot be set for a select query, presets are not expressive enough to "+1" a column, and permissions do not support math operators under $ceq (to restrict to +1 update only e.g.).
So far, my workaround is to post a mutation that increment the "view" column and return the data that I want, but the endpoint is neither restricted to _inc operations, nor to a value of 1 :\ .
Any idea?
As described here:
The only way to audit SELECT in PostgreSQL is via the system logs
You have to make some workarounds, similar to what you are doing already. You can perhaps use our upcoming Actions feature to derive from the update_table field to create your own API, that only has the where clause and internally does a _inc: 1.
Thanks for reverting. Any good place to read about the upcoming actions feature?
It will be out in few days but you can check the preview docs here: https://deploy-preview-3252--hasura-docs.netlify.com/graphql/manual/actions/getting-started.html
Thanks for the link.
Actions look really cool, it鈥檚 kind of adaptors to non graphql services (as long as they respect the req/res interface) if I get it right? That鈥檚 a super powerful addition to remote schemas 馃コ.
Do you see a possibility to add SQL (or native?) Actions at some point? It would be similar in I/O definition but instead of giving the url of a function I鈥檇 give the SQL request I want to execute. It would be an escape path to the fact that SQL functions cannot update the tables. The point being to keep things blazing fast as long as I鈥檓 just touch the db. Maybe that鈥檚 already possible and I missed it?
Cheers!
@tibotiber Yes! Soon after the first release, you will also have the ability to create action handlers which are postgres functions.
Would that include mutable functions?
That鈥檚 really cool. Super impressed with Hasura already and the stuff you have in the works is amazing. You guys are on fire!
@tibotiber Yes.
Neat! Thanks for the details @tirumaraiselvan :). Looking forward to this feature. Feel free to close this.
Thank you for your kind words @tibotiber .