cannot use ^xxx outside of match clauses
This is most usually a sign that you haven’t imported appropriate macros from Ecto.Query.
This is most usually a sign that you haven’t imported appropriate macros from Ecto.Query.
A Little follow up on Patrick’s answer Using only create unique_index on your model will ultimately throw an exception instead of giving you an error. To get an error add a constraint on your changeset but as a paremeter you can give the index name created by unique_index. So in your migration file : create … Read more
You can use Ecto.Adapters.SQL.to_sql/3: iex> Ecto.Adapters.SQL.to_sql(:all, Repo, Post) {“SELECT p.id, p.title, p.inserted_at, p.created_at FROM posts as p”, []} This function is also available under the repository with name to_sql if you’re using a SQL based adapter: iex> Repo.to_sql(:all, Post) {“SELECT p.id, p.title, p.inserted_at, p.created_at FROM posts as p”, []} The query can be any struct … Read more
You can access the test database by using MIX_ENV=test followed by a command such as mix do ecto.drop, mix ecto.reset or mix ecto.rollback. In this particular case, I used: MIX_ENV=test mix ecto.reset If your application has multiple repos (DBs), you’ll want to specify a specific repo to avoid applying the operation to all repos. For … Read more
On Ecto 2.0 (beta) with Postgres, you can use Ecto.Adapters.SQL.query() (current docs, 2.0-beta2 docs) to execute arbitrary SQL; in addition to a list of the rows themselves (“rows“), it happens to return a list of column names (“columns“). In the below example, I run a custom query with no parameters, convert the result’s column names … Read more
I found the answer in the list of primitive types for Ecto.Schema here: Ecto.Schema The answer is to define the type like this: schema “my_model” do field :my_array, {:array, :float} timestamps end
You can now do that with Ecto.Migration.rename/3: rename table(:posts), :title, to: :summary
I think I found a way to do the formatting, but it’s not ideal because I’m writing the formatting myself. Here is a potential solution: SELECT to_char (now()::timestamp at time zone ‘UTC’, ‘YYYY-MM-DD”T”HH24:MI:SS”Z”‘)
You can run iex -S mix to run iex with the dependencies in your current mix project included.. You can read about this at http://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html From there you can execute Ecto queries: iex> MyApp.Repo.all(MyApp.User) Running iex -S mix phx.server will also start the phoenix server.