【发布时间】:2018-01-09 21:38:00
【问题描述】:
我只是想在没有任何 ecto 设置的情况下使用 Postgrex,所以只是文档自述文件中的示例。
这是我的模块的样子:
defmodule Receive do
def start(_type, _args) do
{:ok, pid} = Postgrex.start_link(
hostname: "localhost",
username: "john",
# password: "",
database: "property_actions",
extensions: [{Postgrex.Extensions.JSON}]
)
Postgrex.query!(
pid,
"INSERT INTO actions (search_terms) VALUES ($1)",
[
%{foo: 'bar'}
]
)
end
end
当我运行我得到的代码时
** (RuntimeError) type `json` can not be handled by the types module Postgrex.DefaultTypes, it must define a `:json` library in its options to support JSON types
是不是我设置不正确?根据我在文档中收集的内容,我什至不需要该扩展行,因为默认情况下会处理 json。
【问题讨论】:
-
尝试将此添加到
config/config.exs:config :postgrex, :json_library, Poison。 -
extensions: [{Postgrex.Extensions.JSON}]⇒extensions: [{Postgrex.Extensions.JSON, library: Poison}]应该会有所帮助。 -
旁注:使用@michalmuskala的
Jason