-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path.iex.exs
44 lines (37 loc) · 1023 Bytes
/
.iex.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
defmodule ExTypesense.TestSchema.Catalog do
use Ecto.Schema
@behaviour ExTypesense
@moduledoc false
defimpl Jason.Encoder, for: __MODULE__ do
def encode(value, opts) do
value
|> Map.take([:catalogs_id, :name, :description])
|> Enum.map(fn {key, val} ->
if key === :catalogs_id, do: {key, Map.get(value, :id)}, else: {key, val}
end)
|> Enum.into(%{})
|> Jason.Encode.map(opts)
end
end
schema "catalogs" do
field(:name, :string)
field(:description, :string)
field(:catalogs_id, :integer, virtual: true)
end
@impl ExTypesense
def get_field_types do
name = __MODULE__.__schema__(:source)
primary_field = name <> "_id"
%{
name: name,
default_sorting_field: primary_field,
fields: [
%{name: primary_field, type: "int32"},
%{name: "name", type: "string"},
%{name: "description", type: "string"}
]
}
end
end
import Ecto.Query, warn: false
alias ExTypesense.TestSchema.Catalog