Since I am learning Elixir and phoenix, I thought tinker with my web app I already had up with Nodejs. I used Sequelize with nodejs and my table had column names as camelCase. But Ecto, by default follows the snake_case convention. But Integrating was quite easy and painless.
I generated Account models with mix
phx.gen.html Accounts User users email f_id g_id
deleted the migration file generated.
And updated the schema as follows:
schema "users" do field :email, :string field :fb_id, :string field :g_id, :string field :name, :string field :inserted_at, :utc_datetime, source: :createdAt field :updated_at, :utc_datetime, source: :updatedAt# timestamps()end
I had problem with timestamps. as my legacy database had two field createdAt
and updatedAt
, But Ecto looks for inserted_at
and updated_at
So I commented the time stamp and added two field :inserted_at
and :updated_at
and use source
to tell ecto which field name to look for in database.
And thats all I needed to do. I can use Iex
shell to querry for the users
now.