tanweerdev
Ecto jsonb postgres issue
I want to store jsonb both array and map. structure is very dynamic and its coming from Government sites and if we update front-end its a lot of work to convert/adjust to maps only. Is there a way/workaround that I can use, store and retrieve both json/map and array types which are valid for jsonb postgres type. I have tried to use source and copy to array type sourced field before calling cast pipeline if I get array in params(condition: Map.has_key?(params, "value") && is_list(value)). I am successfully able to save data but when retrieving from db I am getting cast error
field(:value, :map)
field(:value_array, {:array, :integer}, source: :value)
Note: Ecto version > 3 and postgres 10
Marked As Solved
idi527
![]()
You can probably create a custom ecto type which would accept and load both arrays and maps.
defmodule IsItMapIsItArrayWhoKnowsEctoDoes do
@behaviour Ecto.Type
# ... other callbacks ...
@impl true
def load(value) when is_list(value) or is_map(value) do
{:ok, value}
end
end
I haven’t tried it though.
3
Last Post!
tanweerdev
Popular in Questions
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









