I am new to the elixir and phoenix world. I used to make my own framework for golang and before that used PHP.
I love the idea of elixir, and I have to say, with my limited skill in it, I already love the language. It is legitimately a joy to write. (There are a few things that annoy me, like I want to include functions in guards) But on those things I do not mind because I am really enjoying myself on the elixir front.
I cannot say the same thing for the phoenix front however. And I am legitimately annoyed with myself.
I am slowly getting better at understanding the logic behind the structure → But for the life of me the ecto situation is really confusing for me.
What I am trying to do is create a separate ecto repo for specific use with the Auth system (I am trying to rebuild some functionality in my own Golang framework that uses distributed databases).
So right now I just really want to keep it simple, I simply want to have 2 databases, and then when I do mix phx.gen.auth I want to be able to target one of these repo’s.
Is this possible.
I saw there was a -r flag on some of the commands for targeting repo’s but I couldn’t find the same thing for gen.auth
EDIT: Right now I am just using gen.auth then moving the migration over to the other folder based on my limited knowledge this should be okay (I just need to hook up the model to use this repo → as the way I understand it (please correct me if I am wrong) the auth is not upgraded on a new version but instead the changes are up to the individual developer
I am slowly making my way through → Are there any resources you all suggest → I am just using the docs for now and then just making changes, breaking it and trying again.
Since you are generating code, you can simply go over those 5 files phoenix generates and modify the repo yourself, depending on your needs. Same goes for migrations, just make sure they are in the correct folder.
If you want to keep modifications to a minimum of the files you generated, you can use alias as: option:
alias MyApp.AuthRepo, as: Repo
Not entirely sure what you mean by this, but you must have in your application 2 repo modules (one for each database connection). Each repo module has the required functions to do database calls to the database you configured:
# Calling the default repo
MyApp.Repo.all(%User{})
# Calling a custom repo (make sure it was created and started by application supervisor)
MyApp.MyCustomRepo.all(%User{})
Oh this is very good advice → Thank you I am still stumbling my way through elixir and I must say I find it really enjoyable to write… It really tickles a different part of my mind compared to golang. (I still very much like go but for different reasons)
That is such a interesting and very readable way to write that.
Oh my this is magical! I will have to read a lot more into ecto by the looks of it.
I think that is where a lot of my challenges are coming from → Since phoenix is a lot of these packages, and each of these packages have their own elements.
Which packages would you suggest are the most important to learn?
right now Ecto, Liveview where the ones I was going to focus on.
Give it a few months until you will get used to writing functional declarative code and you won’t want to go back to golang.
Phoenix includes them in the generator by default, but they are in no way part of phoenix, you can check the phx.new options, you can opt-out pretty much of any non-phoenix packages. For some phoenix includes integrations, such as ecto.
Depends on what you do. If we talk about your classical crud web applications, then ecto and phoenix (and liveview) will be the ones that will take time to get used to as they have a huge amount of features and a steep learning curve. It’s also worth mentioning that when you inevitably will have to run background jobs, you will start using Oban which is a extremely powerful and polished library to orchestrate workflows.
Very much. I’ve been in projects where we had 7 separate static repos and then we added and removed others dynamically as the app was running. If you need some examples, you can look around, it’s not at all difficult. Doing use Ecto.Repo, ... is injecting code in a module that you are dedicating to being an, you know, Ecto.Repo. You can have as many as you like.