-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Ecto integration #18
Draft
zoedsoupe
wants to merge
14
commits into
main
Choose a base branch
from
feat/ecto-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* 'main' of github.com:zoedsoupe/peri: Update .formatter.exs typo on `locals_without_parens` (#17) Create FUNDING.yml
…o feat/ecto-integration * 'feat/ecto-integration' of github.com:zoedsoupe/peri: feat: add to_changeset!/2 benchs and results fix: handle list composite types
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Provide seamlessly integration with Ecto, providing a new function
to_changeset!/2
that receives aperi
schema and the data to be validated, acting like a commonchangeset/2
function.This function will translate all possible
peri
type definitions to ecto ones, using ecto schemaless changesets and custom ecto types implemented onPeri.Ecto.Type.*
modules, that can be used alone on your other Ecto schemas, for example:Peri.Ecto.Type.Atom
Peri.Ecto.Type.PID
Peri.Ecto.Type.Tuple
Peri.Ecto.Type.Either
Peri.Ecto.Type.OneOf
Also, notice that Ecto doesn't support raw data structures validations, so
to_changeset!/2
only accepts a mapperi
schema, will raise otherwise.It also supports nested schemas, respecting above rules, and also nested composite types, like tuple of maps, or either maps or oneof maps and so on (wip right now).
Related Issues
This PR will close #3
Type of Change
Checklist
Additional Context
Just to track the already supported types implemented on this PR:
:any
:atom
:integer
and all custom validations:eq, :neq, :gt, :gte, :lt, :lte, :range
:float
and all custom validations:eq, :neq, :gt, :gte, :lt, :lte, :range
:map
:boolean
:string
and all those custom validations like:eq, :min, :max, :regex
:date
:time
:datetime
:naive_datetime
:duration
:pid
via custom ecto type{type, {:default, val}}
for setting default values{:enum, choices}
via Ecto.Enum{type, {:transform, mapper}}
viaEcto.Changeset.update_change/3
{:required, type}
viaEcto.Changeset.validate_required/2
{:list, type}
via Ecto{:array, type}
{:tuple, types}
via custom Ecto type{:either, {fat, snd}}
via custom Ecto type{:oneof, types}
via custom Ecto type:oneof
:either
:tuple
{:cond, condition, true, false}
{:dependent, field, condition, type}
{:dependent, condition}
{:dependent, {mod, fun}}
{:custom, callback}
{:custom, {mod, fun}}
{:custom, {mod, fun, args}}