jaeyson / ex_typesense

Typesense client for Elixir with support for importing your Ecto schemas.
https://hexdocs.pm/ex_typesense
MIT License
25 stars 7 forks source link

Change struct to map in order to make dynamic connections (including tests) #30

Closed jaeyson closed 2 weeks ago

jaeyson commented 2 weeks ago

Fixes #26

Problem

Setting the credentials dynamically won't work since the Connection module by default is a struct (hence, compile time).

This also affects the test files of the library, since it relies on explicit connection string. Leaving it blank will throw an error.

To reproduce:

  1. open shell in test env: MIX_ENV=test iex -S mix
  2. put env in application:
    Application.put_all_env(
    ex_typesense: [
    api_key: "xyz",
    host: "localhost",
    port: 8108,
    scheme: "http"
    ]
    )
  3. run ExTypesense.Connection.new
  4. The Connection struct field values returns nil.

Workaround

Since the problem came from making the connection a struct, it defeats the purpose of making it dynamic (runtime). So we have to change it from struct to map.