这是indexloc提供的服务,不要输入任何密码
Skip to content

accessing session variables in function via computed field  #3846

@sincraianul

Description

@sincraianul

It would be really cool to be able to define a function like

CREATE OR REPLACE FUNCTION article_liked(article_row article, hasura_session json)
RETURNS boolean AS $$
  SELECT EXISTS (
    SELECT 1
    FROM liked_article A
    WHERE A.user_id = hasura_session ->> 'x-hasura-user-id' AND A.article_id = article_row.id
  );
$$ LANGUAGE sql STABLE;

and use it via a computed field without any args.

I know that in order to get hasura_session injected the function needs to be tracked, but tracked functions only support SETOF return types.

I can dive in a try to do a PR if there's interest in this kind of functionality.

Metadata

Metadata

Assignees

Labels

c/serverRelated to serverk/enhancementNew feature or improve an existing featurep/highcandidate for being included in the upcoming sprint

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions