grangerelixx

grangerelixx

Seeding a user from terminal input

I am trying to seed a user. I know we can run seeds file by using the following command
mix run priv/repo/seeds.exs

But I would like to pass the following input attrs "first name"this, “last name”, “email” as user input from terminal - like “John”, “Doe”, “john.doe@gmail.com” to

{:ok, user} =
      MyApp.App.register_user%{
        attrs
      })

in seeds.exs.

Any suggestions on how to do this from terminal?

Most Liked

stefanchrobot

stefanchrobot

You can pass command-line arguments to the script:

mix run priv/repo/seeds.exs foo bar baz

and access them with with System.argv. You might find the OptionParser module useful.

Last Post!

stefanchrobot

stefanchrobot

If you’re on PostgreSQL, you can do an upsert with INSERT INTO ... ON CONFLICT ... which is properly supported by Ecto. See the guide in docs.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement