Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: Enhance piping different actions #18

Open
brunoocasali opened this issue Aug 15, 2023 · 1 comment
Open

Idea: Enhance piping different actions #18

brunoocasali opened this issue Aug 15, 2023 · 1 comment

Comments

@brunoocasali
Copy link
Contributor

Hi! I'm using the library in a personal project, and I kind of missed the ability to use it like this:

 :meili 
    |> Meilisearch.client()
    |> Meilisearch.Index.create(%{uid: @index, primaryKey: "uuid"})
    |> Meilisearch.Settings.update(
      @index,
      %{
        searchableAttributes: ["name", "category", "short_name"],
        displayedAttributes: ["name", "category", "popular", "image", "popular", "price", "uuid"],
        filterableAttributes: ["category"],
        sortableAttributes: ["popular", "name"],
        synonyms: synonyms()
      }
    )
    |> Meilisearch.Document.create_or_replace(@index, data)

Instead, I have to call each action as a different line client + create, client + settings, client + document.

I don't know what I could suggest to make it work, but I just wanted to know if I'm thinking in the right way!

@BlitzBanana
Copy link
Member

We could achieve this behaviour by changing the API from this:

defmodule Meilisearch.Settings do
    def update(client, index, settings), do: {:ok, result}
end

to this:

defmodule Meilisearch.Settings do
    def update({:ok, _, client}, index, settings), do: update(client, index, settings)
    def update(client, index, settings) when is_atom(client), do: client |> Meilisearch.client() |> update(index, settings)
    def update(client, index, settings), do: {:ok, result, client}
end

Which would allow usage like this:

 {:ok, sumtask, client} =
    :meili 
        |> Meilisearch.Index.create(%{uid: @index, primaryKey: @primary})
        |> Meilisearch.Settings.update(@index, @settings)
        |> Meilisearch.Document.create_or_replace(@index, documents)

In this case, you cannot access to the result of Index.create/3 and Settings.update/3 calls.

But this is a breaking change as it changes the result tuple. That could break existing matching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants