From 6c9d543c9f532f9e7920238ac786edde1964c5e8 Mon Sep 17 00:00:00 2001 From: jaeyson Date: Tue, 11 Jul 2023 23:54:30 +0800 Subject: [PATCH] Add function clause for accepting struct args --- CHANGELOG.md | 4 ++++ lib/ex_typesense/document.ex | 7 ++++++- mix.exs | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cba716..d120b71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.3.3 (2023.07.11) + +* Add index_multiple_documents/1 clause for accepting struct args + ## 0.3.2 (2023.07.11) * Maps struct pk to document's id diff --git a/lib/ex_typesense/document.ex b/lib/ex_typesense/document.ex index 45ffc5c..08635e8 100644 --- a/lib/ex_typesense/document.ex +++ b/lib/ex_typesense/document.ex @@ -137,7 +137,12 @@ defmodule ExTypesense.Document do {:ok, [%{"success" => true}, %{"success" => true}]} """ @doc since: "0.3.0" - @spec update_multiple_documents(map()) :: response() + @spec update_multiple_documents(list(struct()) | map()) :: response() + def update_multiple_documents([struct | _] = list_of_structs) when is_struct(struct) do + collection_name = struct.__struct__.__schema__(:source) + do_index_multiple_documents(collection_name, "update", list_of_structs) + end + def update_multiple_documents(%{collection_name: collection_name, documents: documents} = map) when is_map(map) do do_index_multiple_documents(collection_name, "update", documents) diff --git a/mix.exs b/mix.exs index 7ca5122..9b31fe9 100644 --- a/mix.exs +++ b/mix.exs @@ -2,7 +2,7 @@ defmodule ExTypesense.MixProject do use Mix.Project @source_url "https://github.com/jaeyson/ex_typesense" - @version "0.3.2" + @version "0.3.3" def project do [