phoenix-framework

Add interval to timestamp using Ecto Fragments

倖福魔咒の 提交于 2020-12-23 14:20:49
问题 I want to write the following query in a phoenix application using Ecto fragments: select * from ( select id, inserted_at + interval '1 day' * expiry as deadline from friend_referral_code ) t where localtimestamp at time zone 'UTC' > deadline The value of expiry is an integer value that represents number of days. What I've got so far is something like this: query = from frc in FriendReferralCode, where: fragment("localtimestamp at time zone 'UTC'") > fragment("? + INTERVAL '1' * ?", frc

How to retrieve id from previous inserted table key by Ecto Multi

扶醉桌前 提交于 2020-11-29 19:21:27
问题 I would like to retrieve id from previous inserted table primary key by Ecto Multi. At first, I insert to A main table. then B details table needs A.id. I tried following code. Multi.new() |> Multi.insert(:insert, main) |> Multi.insert_all(:insert_all, B, details) |> Repo.transaction() However I have no idea how to retrieve A.id for insert table B. What I should do for it? 回答1: You can do something like the following example which creates a new User record and a new Email record (where the

How to retrieve id from previous inserted table key by Ecto Multi

走远了吗. 提交于 2020-11-29 19:20:16
问题 I would like to retrieve id from previous inserted table primary key by Ecto Multi. At first, I insert to A main table. then B details table needs A.id. I tried following code. Multi.new() |> Multi.insert(:insert, main) |> Multi.insert_all(:insert_all, B, details) |> Repo.transaction() However I have no idea how to retrieve A.id for insert table B. What I should do for it? 回答1: You can do something like the following example which creates a new User record and a new Email record (where the

How to do HTTPS request from Phoenix and ignore the CA error

a 夏天 提交于 2020-08-04 05:09:31
问题 I'm trying to call a dev environment REST service from my phoenix server, but I don't want to whitelist the CA. For the record, I don't even know how to add the CA key to Phoenix's whitelist. How to do https request from phoenix while also ignoring the SSL's CA error? 回答1: Using HTTPoison, you need to pass the :insecure hackney option. HTTPoison.get! url, [], hackney: [:insecure] 来源: https://stackoverflow.com/questions/32767162/how-to-do-https-request-from-phoenix-and-ignore-the-ca-error

How can I make Elixir mix test output more verbose?

醉酒当歌 提交于 2020-07-18 08:42:22
问题 In my Elixir/Phoenix app, when I run mix test I get output like: $ mix test .... Finished in 0.09 seconds 4 tests, 0 failures with dots for each test that succeeded. How do I output the names of the tests that succeed instead? In Rails with rspec I used to do this with a .rspec file in the directory that looked like: $ cat .rspec --color -fd --tty Is there an equivalent in Elixir? 回答1: To print the names of the passing tests, you can pass --trace argument to mix test . For example, here's the

How can I make Elixir mix test output more verbose?

情到浓时终转凉″ 提交于 2020-07-18 08:41:01
问题 In my Elixir/Phoenix app, when I run mix test I get output like: $ mix test .... Finished in 0.09 seconds 4 tests, 0 failures with dots for each test that succeeded. How do I output the names of the tests that succeed instead? In Rails with rspec I used to do this with a .rspec file in the directory that looked like: $ cat .rspec --color -fd --tty Is there an equivalent in Elixir? 回答1: To print the names of the passing tests, you can pass --trace argument to mix test . For example, here's the

Is there a way to have a Phoenix Plug just for one route?

∥☆過路亽.° 提交于 2020-05-15 08:11:44
问题 In Phoenix I have my routes as follow : scope "/", ManaWeb do pipe_through [:browser, :auth] get "/register", RegistrationController, :new post "/register", RegistrationController, :register end However I would like to set a Plug for the last route (POST). How would I go about that with current tools ? 回答1: As it is stated in the documentation for Phoenix.Router.pipeline/2 Every time pipe_through/1 is called, the new pipelines are appended to the ones previously given. That said, this would