连接Elixir Ecto中属于两个数据库的两个表



在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——连接两个不同数据库的表?

你的代码很完美。这是Ecto中的一个bug。如果你想试一试,我已经把它修好了。:)

最新更新