【发布时间】:2018-05-07 16:08:31
【问题描述】:
我正在尝试使用Postgrex 提供的tsvector 扩展。但是我如何在我的 Phoeinx 项目中实际使用它呢?这是我在 dev.exs 中的设置
config :project, Project.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "project_dev",
hostname: "localhost",
pool_size: 10,
extensions: [{Postgrex.Extensions.TSVector}]
这是架构
schema "branches" do
field :address, :string
field :tags, {:array, :string}
field :document, Postgrex.Extensions.TSVector
belongs_to :bank, Bank
timestamps()
end
这不应该给我一个新的类型TSVector吗?我收到以下错误
** (ArgumentError) invalid or unknown type Postgrex.Extensions.TSVector for field :document
更新
我尝试将架构设置为以下
field :document, {:array, Postgrex.Lexeme}
在从数据库中检索值时,我收到以下错误
** (UndefinedFunctionError) function Postgrex.Lexeme.type/0 is undefined or private
【问题讨论】:
-
请显示您的架构。我希望你有像
field :document, TSVector这样的东西,而它应该是完全合格的field :document, Postgrex.Extensions.TSVector。 -
@mudasobwa 添加
-
您是否介意尝试将
:tsvector作为字段类型(正好在您的迁移中)。 -
根据Ecto Postgres docs,应该是
field :document, {:array, Postgrex.Lexeme}。 -
使用上面的,现在得到
** (UndefinedFunctionError) function Postgrex.Lexeme.type/0 is undefined or private
标签: elixir phoenix-framework ecto