elixir

Cross DB Ecto config failing

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 10:28:26
问题 In config/dev.exs : config :drupex, Drupex.Repo, adapter: Ecto.Adapters.Postgres, -- username, password, database, hostname, pool_size omitted -- config :drupex, Drupex.DrupalRepo, adapter: Ecto.Adapters.Mysql, -- username, password, database, hostname omitted -- In mix.exs under defp deps do I added {:mariaex, "~> 0.8.2"}, just after {:postgrex, ">= 0.0.0"} . Finally in lib/drupex/repo.ex I added defmodule Drupex.DrupalRepo do use Ecto.Repo, otp_app: :drupex end I ran mix deps.get , mix deps

how can i using mix(Elixir) install package install to system?

会有一股神秘感。 提交于 2019-12-13 09:42:35
问题 I just want run IEx to require this package, I do not want create a mix project and into the deps. For example, gem install bundle How do I do this? 回答1: As I understood, mix archive.install is useful to install archives that will provide mix tasks. What you could do is to put all the .beam files in a repository that will be specified at iex/elixir startup (with the -pa $CUSTOMPATH option). This will load the .beam files during elixir startup. For instance, in the elixir shell script, there

Erlang ssh connection error: Unable to connect using the available authentication methods

孤者浪人 提交于 2019-12-13 08:11:02
问题 When doing an ssh connection in Elixir, I got this error: :ssh.shell('host address', port_number, user: 'user_name') {:error, 'Unable to connect using the available authentication methods'} 回答1: The answer was in a comment left by @svarlet on this question. If your ssh key has a pass-phrase, you need to specify it in the options to the Erlang ssh connect command. :ssh.shell('host address', port_number, user: 'user_name', rsa_pass_phrase: 'ssh_key_passphrase') 来源: https://stackoverflow.com

How to select data from two tables in Ecto

瘦欲@ 提交于 2019-12-13 07:25:55
问题 I trying to write Ecto query which will be select data from two tables at the same time. Like Select t1.*,t2.* from table1 t1,table2 t2 where t1.id=1 and t2.id=2 I can't find solution, found only way to write raw SQL and it's looks like not good. Like variant -using preload, but it's spawn additional query. comments_query = from c in Comment, order_by: c.published_at Repo.all from p in Post, preload: [comments: ^comments_query] Thanks for any ideas 回答1: Try this from Ecto.Query https:/

Elixir, Ecto pattern matching conditional with db query not behaving as expected

情到浓时终转凉″ 提交于 2019-12-13 06:17:29
问题 If the record does not exist, I would expect this conditional to create it, but it does not.... nil is returned. case Repo.get_by(User, %{email: "hulk@hogan.com"}) do struct -> struct nil -> params = Map.merge(%{email: "hulk@hogan.com"}, %{password: "password"}) Repo.insert!(User.changeset(User.__struct__, params)) end # returns nil.... huwutt??? However, if I change the ordering of the condition, it works. What am I missing here? case Repo.get_by(User, %{email: "hulk@hogan.com"}) do nil ->

Using `cast_assoc` to associate records on different schemas

蹲街弑〆低调 提交于 2019-12-13 03:45:58
问题 I'm trying to use cast_assoc to associate records that exist on different schemas. In the code below, Organization exists in a tenant schema (e.g. "tenant_2837.organizations"), whereas Workspace exists on the public schema (e.g. "public.workspaces"). When the code runs, Ecto tries to create the Workspace under the tenant schema. %Organization{} |> Organization.create_organization_changeset(attrs) |> cast_assoc(:workspace, with: &Workspace.changeset/2) |> Repo.insert(prefix: TenantActions

Convert a Base64 string into a map in Elixir

寵の児 提交于 2019-12-13 01:34:22
问题 I am using Elixir to decode a Base64 string which contains a JSON. I use the following function: Base.url_decode64(string) However, this function returns a string. In particular: "{\"algorithm\":\"HMAC-SHA256\",\"app_data\":\"1\",\"issued_at\":1452249105,\"page\":{\"id\":\"1051194981579510\",\"admin\":true},\"user\":{\"country\":\"se\",\"locale\":\"en_GB\",\"age\":{\"min\":21}}}" The problem is that this structure should be a map instead of a string because otherwise I can't access the JSON

(FunctionClauseError) no function clause matching in Access.get/3

落花浮王杯 提交于 2019-12-13 00:27:23
问题 I am new to Elixir and currently making a transaction from Ruby. I am struggling to get around an error I am getting and because Elixir does not have object.class , I am struggling to understand what data type am I returning back and how to troubleshoot it. Anyway I am trying to seed a database from a CSV but getting the error Below is my code File.stream!('users_departs.csv') |> Stream.drop(1) |> CSV.decode(headers: [:name, :title, :departments]) |> Enum.take(10 |> Enum.each( fn(x) -> IO

How do you run iex from Emacs?

久未见 提交于 2019-12-12 20:53:20
问题 I keep on getting this warning when I run iex using elixir-mode-iex from Emacs: Warning: could not run smart terminal, falling back to dumb one I think that this just means that I don't get tab completion, which I'm fine with. But I'd like a smart terminal if it's possible with elixir-mode in Emacs. 回答1: elixir-mode-iex uses the comint-mode major mode to interactive with iex . That also means that it's acting just like a dumb terminal (doesn't have the ability to process special escape

Get rid of scientific notation

只愿长相守 提交于 2019-12-12 20:07:48
问题 I need to do some calculations but I'm getting a problem with values which are very low, for example, I need to get the 2.7% of 0.005 and I end up with 1.3500000000000003e-4 which is not what I'm looking for, I just need to know how can I get an accurate percetage of those values, what I'm doing right now is <value> * 2.7 / 100 which works great for integers or floats greater than 0.05. For example, the one that I need which is 2.7% of 0.005 needs to be shown as 0.000135. 回答1: First,