Is it possible to define multiple selects on the same view table?

No, currently each view is defined by a single select. See below for an example of three views that contain events from a single event-sourced entity.

File: customer-views.proto

syntax = "proto3";

package io.example;

import "akkaserverless/annotations.proto";
import "customer-domain.proto";

service CustomerByName {
  rpc UpdateCustomer(Customer) returns (Customer) {
    option (akkaserverless.method).eventing.in = {
      value_entity: "customers"
    };
    option (akkaserverless.method).view.update = {
      table: "customers"
      transform_updates: true
    };
  }

  rpc GetCustomers(ByNameRequest) returns (stream Customer) {
    option (akkaserverless.method).view.query = {
      query: "SELECT * FROM customers WHERE name = :customer_name"
    };
  }
}

service CustomerByEmail {
  rpc UpdateCustomer(Customer) returns (Customer) {
    option (akkaserverless.method).eventing.in = {
      value_entity: "customers"
    };
    option (akkaserverless.method).view.update = {
      table: "customers"
      transform_updates: true
    };
  }

  rpc GetCustomerByEmail(ByEmailRequest) returns (Customer) {
    option (akkaserverless.method).view.query = {
      query: "SELECT * FROM customers WHERE email = :email"
    };
  }
}

service CustomerByCity {
  rpc UpdateCustomer(Customer) returns (Customer) {
    option (akkaserverless.method).eventing.in = {
      value_entity: "customers"
    };
    option (akkaserverless.method).view.update = {
      table: "customers"
      transform_updates: true
    };
  }

  rpc GetCustomerByCity(ByCityRequest) returns (stream Customer) {
    option (akkaserverless.method).view.query = {
      query: "SELECT * FROM customers WHERE address.city = :city"
    };
  }
}

message ByNameRequest {
  string customer_name = 1;
}

message ByEmailRequest {
  string email = 1;
}

message ByCityRequest {
  string city = 1;
}

1 Like

From my understanding there should only be one query per view’s protobuf service definition.
One AkkaServerless service can have multiple views but that means that you need to have multiple view’s protobuf definitions (each per view/query).