0

I am making Task List using Go, gRPC-Web and Postgres.

How can I fetch the data with server streaming after updating exist data?

With the following data,

  • Post data with Task{ id: 1, name: 'abc1' }
  • Post data with Task{ id: 2, name: 'abc2' }
  • Post data with Task{ id: 3, name: 'abc3' }

when I call GetTasks, I get the 3 data. However, if Task{ id: 2, name: 'abc2' } is updated as Task{ id: 2, name: 'new abc2' } by UpdateTask, how can I get the new data?

Does GetTasks fetch this automatically? or Do I need to do something to get the updated data?

syntax = "proto3";

package tasklist;

import "google/protobuf/empty.proto";

service TodoList {
  rpc GetTasks(google.protobuf.Empty) returns (stream GetTasksResponse) {}
  rpc PostTask(PostTaskRequest) returns (PostTaskRequest) {}
  rpc UpdateTask(PostTaskmRequest) returns (PostTaskRequest) {}
}


message Task {
  int64 id = 1;
  string name = 2;
}

message GetTasksResponse {
  Task task = 1;
}

message PostTaskRequest {
  Task Task = 1;
}

message PostTaskResponse {
  bool result = 1;
}

message UpdateTaskRequest {
  Task Task = 1;
}

message UpdateTaskResponse {
  bool result = 1;
}
Pytan
  • 1,138
  • 11
  • 28
  • Your gRPC service will need to handle this. If the gRPC interface is the only way data will be updated then you could have the `Post`/`Update` functions notify any active streams of the change; alternatively you could [watch for changes](https://stackoverflow.com/a/46905334/11810946) on the db tables and send an update to the stream. – Brits Jan 25 '23 at 21:30

0 Answers0