Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: view auto update from other tables #3958

Open
2 tasks done
agufagit opened this issue Apr 28, 2024 · 0 comments
Open
2 tasks done

Feature: view auto update from other tables #3958

agufagit opened this issue Apr 28, 2024 · 0 comments
Labels
feature New feature or request triage This issue is new

Comments

@agufagit
Copy link

agufagit commented Apr 28, 2024

Is your feature request related to a problem?

a way to auto update view from other tables

DEFINE TABLE aggregated_view AS
	SELECT id,
        (SELECT in, created_at FROM <-like ORDER BY created_at) as likes
        FROM posts
;

this view doesn't auot update when like relation table changes

Describe the solution

a clause to identity related tables to trigger auto update on row level WITH AUTOUPDATE ON like(out, post_id), comment(out, post_id), out is the field that matches with post_id field of view, whenever like or comment table is updated/inserted/deleted, corresponding row in materialized view is also updated, so it's something like update aggregated_view as select ... from like.out where post_id=like.out

DEFINE TABLE aggregated_view AS
	SELECT id as post_id,
        (SELECT in, created_at FROM <-like ORDER BY created_at) as likes
        FROM posts
        WITH AUTOUPDATE ON like(out, post_id), comment(out, post_id)
;

Alternative methods

manually update the view using ON UPDATE trigger on like relation table

SurrealDB version

surreal 1.4.0

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@agufagit agufagit added feature New feature or request triage This issue is new labels Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request triage This issue is new
Projects
None yet
Development

No branches or pull requests

1 participant