在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)
Run Code Online (Sandbox Code Playgroud)
当我调用该函数时,我收到了错误
** (Mariaex.Error) (1146): Table 'cloud_usage.cloud_usage.cloud_usage' doesn't exist
Run Code Online (Sandbox Code Playgroud)
我知道为什么会这样.但如果我使用Billing.Cloud.Repo.all(query),我想我几乎无法检索cloud_usage.cloud_usage表中的数据.反之亦然
参考:
| 归档时间: |
|
| 查看次数: |
1298 次 |
| 最近记录: |