View Source Statestores.Projection.Query.DynamicTableDataHandler (spawn_statestores v2.0.0-RC1)

Module to dynamically insert, update and query data in a PostgreSQL table based on the definition of a Protobuf module.

This module supports:

  • Upsert (insert or update based on conflicts).
  • Direct update of records.
  • Query of records with mapping to Protobuf structures.

Usage Example

iex> DynamicTableDataHandler.upsert(repo, MyProtobufModule, "my_table", %MyProtobufModule{...}) :ok

iex> results = DynamicTableDataHandler.query(repo, "SELECT age, metadata FROM example WHERE id = :id", %{id: "value"}) {:ok, [%{age: 30, metadata: "example data"}]}

Summary

Functions

Performs a raw query and returns the results.

Performs an upsert (insert or update) of data in the table.

Functions

query(repo, protobuf_module, query, params, opts \\ [])

Performs a raw query and returns the results.

Parameters

  • repo: The Ecto repository module.
  • query: The raw SQL query string with named parameters (e.g., :id).
  • params: A map of parameter values.

Returns the result rows as a list of maps.

Examples

iex> results = DynamicTableDataHandler.query(repo, "SELECT age, metadata FROM example WHERE id = :id", %{id: "value"}) {:ok, [%{age: 30, metadata: "example data"}]}

upsert(repo, protobuf_module, table_name, data)

Performs an upsert (insert or update) of data in the table.

Parameters

  • repo: The Ecto repository module.
  • protobuf_module: The Elixir module generated from a Protobuf file.
  • table_name: Name of the table in the database.
  • data: Protobuf structure containing the data to be inserted or updated.

Returns :ok on success.