From e75c1778781b44abfee1de66436e2fca51260191 Mon Sep 17 00:00:00 2001 From: Josef Galea Date: Wed, 20 Mar 2019 16:58:04 +0100 Subject: [PATCH 1/3] Fix spec for Entity.upsert/1 --- lib/diplomat/entity.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/diplomat/entity.ex b/lib/diplomat/entity.ex index ba96f15..ac9f3a0 100644 --- a/lib/diplomat/entity.ex +++ b/lib/diplomat/entity.ex @@ -172,7 +172,7 @@ defmodule Diplomat.Entity do end # at some point we should validate the entity keys - @spec upsert([t] | t) :: {:ok, CommitResponse.t()} | Client.error() + @spec upsert([t] | t) :: CommitResponse.t() | Client.error() def upsert(%Entity{} = entity), do: upsert([entity]) def upsert(entities) when is_list(entities) do From 31a3509c948acde50ef6fdbb31637c44a7aedf34 Mon Sep 17 00:00:00 2001 From: David Leonhartsberger Date: Thu, 28 Mar 2019 17:29:58 +0100 Subject: [PATCH 2/3] Support for executing Query in Transaction --- lib/diplomat/transaction.ex | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/diplomat/transaction.ex b/lib/diplomat/transaction.ex index 1bfe306..48c1f87 100644 --- a/lib/diplomat/transaction.ex +++ b/lib/diplomat/transaction.ex @@ -29,10 +29,12 @@ defmodule Diplomat.Transaction do RollbackRequest, RollbackResponse, LookupRequest, - ReadOptions + ReadOptions, + RunQueryRequest, + PartitionId } - alias Diplomat.{Transaction, Entity, Key, Client} + alias Diplomat.{Transaction, Entity, Key, Client, Query} @type t :: %__MODULE__{ id: integer, @@ -108,6 +110,18 @@ defmodule Diplomat.Transaction do find(transaction, [key]) end + @spec execute(Transaction.t(), Query.t(), String.t() | nil) :: list(Entity.t()) | Client.error() + def execute(%Transaction{id: id}, %Query{} = q, namespace \\ nil) do + {:ok, project} = Goth.Config.get(:project_id) + + RunQueryRequest.new( + query_type: {:gql_query, q |> Query.proto()}, + partition_id: %PartitionId{namespace_id: namespace, project_id: project}, + read_options: %ReadOptions{consistency_type: {:transaction, id}} + ) + |> Diplomat.Client.run_query() + end + # we could clean this up with some macros @spec insert(t, Entity.t() | [Entity.t()]) :: t def insert(%Transaction{} = t, %Entity{} = e), do: insert(t, [e]) From 8ee9525e4c1ec85ee3a20ec83f346c0607f6e929 Mon Sep 17 00:00:00 2001 From: David Leonhartsberger Date: Thu, 28 Mar 2019 17:30:22 +0100 Subject: [PATCH 3/3] Fixed construction of PartitionId --- lib/diplomat/query.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/diplomat/query.ex b/lib/diplomat/query.ex index 76adc11..6667005 100644 --- a/lib/diplomat/query.ex +++ b/lib/diplomat/query.ex @@ -47,7 +47,7 @@ defmodule Diplomat.Query do RunQueryRequest.new( query_type: {:gql_query, q |> Query.proto()}, - partition_id: PartitionId.new(namespace_id: namespace, proejct_id: project) + partition_id: %PartitionId{namespace_id: namespace, project_id: project} ) |> Diplomat.Client.run_query() end