在Elixir中,使用Ecto,是否可以连接属于不同数据库的两个不同表(在同一主机中)
在这个查询中有两个名为cloud
和cloud_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。如果你想试一试,我已经把它修好了。:)