在 Elixir Ecto 中加入属于两个数据库的两个表

Join two tables belong to two database in Elixir Ecto

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

此查询中有两个数据库,分别为 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 table 中的数据。反之亦然

参考:

MySQL -- join between tables in 2 different databases?

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