-
Notifications
You must be signed in to change notification settings - Fork 36
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
Potential integration with Ecto? #7
Comments
elixir-ecto/ecto#2594 I can open a PR with a potential patch if you want. |
Hi @cblage! This feature is actually on my roadmap from the beginning. I haven’t implemented yet for two reasons:
As you’ve just stated, they continue to debate and things seem to move very slowly, so why not implementing something here. A few reflectionsEdge casesYou example is quite straightforward: each Ecto type can be mapped to a nullable typespec and other “hidden” fields can be added. However, how would you handle associations? Maybe there are other corner cases too, we must think about them. Design
If you do a PR (on Last but not least: thank you for helping! ❤️ |
Well, I have actually decided to make my domain-specific models separate from my DB Schema "models", and so my immediate need for this is no longer there, but I'll still try and see if I could make the PR because it sounds fun to do |
@cblage No problem! And yeah, Elixir macros are fun to play with :) |
I'd like to know if there is still interest. I think integrating with Ecto is a whole new thing. This is because there are a lot of ecto-specific things. I have also changed some of the logic for enforcing/default/etc. My problem was that I may want to enforce but still enable people to set it to nil. |
Hi @bamorim ! Yes, I am still interested in this actually. I have uncommitted code locally about a plugin system you could build upon (see #9, API not contractual), but I am rather slow to work on it for a few months now since I am on other subjects in the mean time—will be on a scientific base with low internet access in Kerguelen Islands from next November, so lots of things to get done before. TypedStruct 0.2.0 with plugins is my the pipeline. The code I have seems to be functional (I’ve tried it briefly with a Lens integration) and really flexible (more than the current state in the |
@ejpcmac after going through integrating with Ecto (I'm almost finished). I don't think it is possible to create a one-size-fits-all solution. The reason is that this lib defines it's own DSL while when integrating with ecto, ideally, I just want to add some syntax sugar on top of Ecto's own DSL. The way I solved this was creating a "struct type builder" that is called by my macro. defmodule MyStruct do
StructTypeBuilder.__init__()
StructTypeBuilder.__add_field__(:field_name, String.t(), enforce: true, null: false)
@enforce_keys StructTypeBuilder.__enforced_fields__()
defstruct StructTypeBuilder.__fields__()
StructTypeBuilder.__define_type__()
end Where in Ecto, instead of calling defstruct, I'd just call Ecto's However, I think there is one "core" component to be reused between my Ecto Implementation and a general struct implementation. That being said, I think the best is for me to create a new lib focused on Ecto and later we try to see how to fit things together. What do you say? Have any idea? |
Also, since
field(:my_field, :string, [])
__add_field__(:my_field, :string, []) (Of course, with more stuff and options) |
@ejpcmac after going through integrating with Ecto (I'm almost
finished). I don't think it is possible to create a one-size-fits-all
solution.
The reason is that this lib defines it's own DSL while when
integrating with ecto, ideally, I just want to add some syntax sugar
on top of Ecto's own DSL.
You’re right. Ideally a common solution would use the TypedStruct DSL
for raw structs, and the Ecto one for Ecto schemas. Don’t know if we can
do this properly ATM.
That being said, I think the best is for me to create a new lib
focused on Ecto and later we try to see how to fit things together.
What do you say?
Let’s try this in a second time, once both TypedStruct 0.2.0 and your
library are live. I don’t have any more bandwidth to allow on new
projects before November.
|
Just FYI, I released the lib: |
Today I needed to use |
I think it would be great if we could use the
typedstruct
macro in conjunction with Ecto. Right now Ecto does not create@type t
for the struct, but it defines other struct-related things which collde withtypedstruct
.So maybe add a
typedschema
macro to integrate with Ecto? Right now, one declares Ecto schemas like this:I suggest supporting something like:
What do you think?
The text was updated successfully, but these errors were encountered: