scottming

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

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.

stefanchrobot

stefanchrobot

Hi, would it be possible to build this library on top of Ecto’s schemaless changesets?

Where Next?

Popular in Discussions Top

PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
New
thojanssens1
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.: redirect "/", UserController, ...
New
pillaiindu
In django there is a cache framework backed by memcached. Rails also puts a lot of emphasis on caching, and even the idea of russian-doll...
New
Qqwy
Looking at the stacks that existing large companies have used, WhatsApp internally uses Mnesia to store the messages, while Discord uses ...
New
WildYorkies
It seems that the more I read, the more I find Elixir users speaking about all the ways that Elixir is not good for x, y, and z use cases...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
AstonJ
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
New
paulanthonywilson
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things. But I don’t think this is ...
New

Other popular topics Top

New
albydarned
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
lanycrost
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

We're in Beta

About us Mission Statement