首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ecto查询不适用于Absinthe分辨率

Ecto查询不适用于Absinthe分辨率
EN

Stack Overflow用户
提问于 2018-01-08 22:05:23
回答 1查看 181关注 0票数 0

我正在尝试使用Absinthe#Batch进行一个简单的查询,但是执行Ecto查询的函数不会返回任何结果。

我添加了一些跟踪来计算数据库上的记录。预期总是返回1,但不返回

救世主:

代码语言:javascript
复制
def get_cards_for_stage(stage, _args, _ctx) do
  IO.puts "Before batch: #{OfferSid.Repo.aggregate(from(p in "pipeline_cards"), :count, :id)}"

  batch({__MODULE__, :pipeline_cards_by_stage_ids}, stage.id, fn batch_results ->

  IO.puts "Inside batch: #{OfferSid.Repo.aggregate(from(p in "pipeline_cards"), :count, :id)}"
    {:ok, Map.get(batch_results, stage.id)}
  end)
end

帮助方法:

代码语言:javascript
复制
def pipeline_cards_by_stage_ids(_args, stages_ids) do
  IO.puts "On the helper method: #{OfferSid.Repo.aggregate(Ecto.Query.from(p in "pipeline_cards"), :count, :id)}"

  cards = OfferSid.pipeline_cards_by_stage_ids(stages_ids)
  Map.new(cards, fn s -> {s.pipeline_stage_id, s} end)
end

一些追踪:

代码语言:javascript
复制
  # Before batch: 1
  # Before batch: 1
  # Before batch: 1
  # On the helper method: 0
  # Inside batch: 1
  # Inside batch: 1
  # Inside batch: 1
EN

回答 1

Stack Overflow用户

发布于 2018-01-09 18:27:50

正如benwilson512提到的这里,问题在于db连接不是共享

所以,我修正了它,并补充道:

代码语言:javascript
复制
before do
  Ecto.Adapters.SQL.Sandbox.mode(Repo, {:shared, self()})
end
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48158729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档