Skip to content
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

[FEATURE] Integration with Ecto #3

Open
zoedsoupe opened this issue Jul 6, 2024 · 3 comments
Open

[FEATURE] Integration with Ecto #3

zoedsoupe opened this issue Jul 6, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@zoedsoupe
Copy link
Owner

Description
Peri schemas should be parseable as Ecto.Changesets and vice versa. This allows the Peri library to be as extensive as possible while providing seemanless integration and retrocompatibility with ecto schemas.

Motivation
ecto syntax for define deeply nested schemas and more complex validation lack the simplicity of Peri, however not interfacing with ecto schemas seems to be a block to the library usage in some use cases.

Alternatives

  • maybe a function to convert peri schema definition to a changeset?
  • maybe define ecto schemas on the defschema/2 macro? (should be optional, will relay on macros and code generation)
  • maybe convert ecto changesets to Peri schemas?

Additional Context
N/A

@zoedsoupe zoedsoupe added the enhancement New feature or request label Jul 6, 2024
@zoedsoupe zoedsoupe self-assigned this Jul 6, 2024
@joeljuca
Copy link

How do you imagine it being implemented? Some function, eg.: to_changeset() or smt like that?

@zoedsoupe
Copy link
Owner Author

yeah, exactly something like that. i don't want to build ecto schemas (aka structs) because peri already handle the schema definition. so the idea was to target schemaless changesets...

there are some considerations though, like peri can be used on raw data structures and types, and support various kinds of validations that ecto doesn't, so some schemas would be "truncated"

@joeljuca
Copy link

joeljuca commented Aug 2, 2024

The issue I can see right away is that Peri does not have a data structure to represent a pipeline of validations (smt like %Ecto.Changeset{} that encapsulates the struct, the param map/keyword list with changes being applied to it, the validation status, and a list of errors that can be appended with more errors, etc.). IIUC, Peri's validation pipeline relies on tuple-wrapped returns with :ok/:error prefixes.

It seems that some state is being lost through the pipeline, so it might require quite a bit of rewrite – but I might not be seeing the whole thing through. How do you imagine implementing it? Could you draft a quick-and-dirty description of how it could bew implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants