【问题标题】:Join two tables belong to two database in Elixir Ecto在 Elixir Ecto 中加入两个表属于两个数据库
【发布时间】:2015-08-08 22:13:41
【问题描述】:

在 Elixir 中,使用 Ecto 是否可以连接属于不同两个数据库的两个不同表(在同一主机中)。

此查询中有两个数据库,分别称为 cloudcloud_usage

当我执行查询时,我应该使用哪个 Repo?

Billing.CloudUsage.Repo.all(query)

Billing.Cloud.Repo.all(query)

    query = from cucu in "cloud_usage.cloud_usage",
        inner_join: cv in "cloud.volumes", on: cucu.usage_id == cv.id,
          where: cucu.account_id == ^account_id,
          where: cucu.usage_id == 6,
          where: like(cucu.description, ^vol_description),
          where: cucu.start_date >= ^start_datetime,
          where: cucu.start_date <= ^end_datetime,
       group_by: cucu.usage_id,
       group_by: cucu.zone_id,
         select: {cucu.usage_id, cucu.zone_id, cucu.size, sum(cucu.raw_usage)}
   result  = Billing.CloudUsage.Repo.all(query)

当我调用函数时出现错误

** (Mariaex.Error) (1146): Table 'cloud_usage.cloud_usage.cloud_usage' doesn't exist

我知道为什么会这样。但是如果我使用 Billing.Cloud.Repo.all(query) ,我想我很难检索到 cloud_usage.cloud_usage 表中的数据。反之亦然

参考:

MySQL -- join between tables in 2 different databases?

【问题讨论】:

  • 请包含您遇到的具体错误。
  • 与论坛网站不同,我们不使用“谢谢”、“感谢任何帮助”或Stack Overflow 上的签名。请参阅“Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?。顺便说一句,这是“提前致谢”,而不是“在先致谢”。
  • 请包括您遇到的错误和 Ecto 版本。另请注意,您的查询中有错字。它应该是, on: cucu 而不是, on cucu
  • 请不要发布屏幕截图,而是将代码粘贴到您的问题中,并使用编辑器中的{} 按钮正确格式化。您应该只发布代码的相关部分,而不是不必要的 cmets。如果你想得到好的答案,你应该让读者尽可能容易。

标签: elixir ecto


【解决方案1】:

你的代码很完美。这是 Ecto 中的一个错误。如果您想尝试一下,我已经在 master 中修复了它。 :)

【讨论】:

  • 何塞,成功了!!真的很感谢你的工作!为了尝试主 ecto,我需要更改 mix.exs 文件。 {:ecto, github: "elixir-lang/ecto"},
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-01
  • 1970-01-01
  • 2016-01-18
  • 2016-07-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多