scottming
A new validation library, looking for suggestions
Hello everyone, I have written a library about validation joi, which I think is suitable for use in CQRS projects where there are many data structures defined. I’m about to release version 0.2.0, currently in the develop branch. Do you have any suggestions for the API, or for the code, or for testing
Most Liked
stefanchrobot
When I looked at the example on GitHub:
iex> schema = %{a: [:integer]}
%{a: [:integer]}
iex> data1 = %{a: 1}
%{a: 1}
iex> Joi.validate(data1, schema)
{:ok, %{a: 1}}
iex> data2 = %{a: <<123>>}
iex> Joi.validate(data2, schema)
{:error,
[
%Joi.Error{
context: %{key: :a, value: "{"},
message: "a must be a integer",
path: [:a],
type: "integer.base"
}
]}
the same - or at least similar - thing can be achieved using schemaless changesets with Ecto:
iex> types = %{a: :integer}
iex> data = %{a: "hello"}
iex> changeset = {%{}, types} |> Ecto.Changeset.cast(data, Map.keys(types))
#Ecto.Changeset<
action: nil,
changes: %{},
errors: [a: {"is invalid", [type: :integer, validation: :cast]}],
data: %{},
valid?: false
>
So the question is whether the functionality you’re building can be written as an extension to Ecto, which is I think is very commonly used. In one of the previous projects, I had a microservice that didn’t have it’s own storage, but I still used Ecto to validate the schema of the incoming requests.
4
stefanchrobot
Popular in Discussions
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
Following https://github.com/tbrand/which_is_the_fastest |>
https://raw.githubusercontent.com/tbrand/which_is_the_fastest/master/imgs...
New
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them?
Feel free to be as concise or in-depth as you li...
New
I’ve been hearing much about the new formatter and it’s something I have been keen to try.
I find examples buy far the most illuminating...
New
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
New
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help.
Where are they similar?
Where do they differ the m...
New
Other popular topics
Hello, how can I check the Phoenix version ?
Thanks !
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
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 wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
Chat & Discussions>Discussions
Latest on Elixir Forum
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









