【发布时间】:2020-09-19 22:11:41
【问题描述】:
我的数据库中有这个:
[
%Element{id: 1, posx: 1, posy: 2, count1: 100, count2: 500, timestamps...},
%Element{id: 2, posx: 2, posy: 2, count1: 150, count2: 450, timestamps...},
%Element{id: 3, posx: 3, posy: 2, count1: 50, count2: 300, timestamps...}
]
现在当我添加新数据时
Repo.insert{posx: 3, posy: 2, count1: 25 count2: 125}
我想更新 posx 和 posy 相同的现有条目并添加两个新的计数值。 所以我的数据库应该是这样的:
[
%Element{id: 1, posx: 1, posy: 2, count1: 100, count2: 500, timestamps...},
%Element{id: 2, posx: 2, posy: 2, count1: 150, count2: 450, timestamps...},
%Element{id: 3, posx: 3, posy: 2, count1: 75, count2: 425, timestamps...}
]
如果不存在 posx 和 posy 相同的条目,我只想在数据库中插入一个新条目。
那么我该如何实现呢?
【问题讨论】:
标签: elixir phoenix-framework ecto