我如何使用柴油在 sqlite 中更新插入?

我正在将 Rust 应用程序从 Postgres 迁移到 Sqlite。但是我遇到了 upsert 的问题

以下代码

diesel::insert_into(dialogs_table)
            .values(dialog)
            .on_conflict(user_id_column)

给我这个:

error[E0599]: no method named `on_conflict` found for struct InsertStatement in the current scope

我觉得这很奇怪,因为它适用于 Postgres。在这里使用 upsert 的可能解决方案是什么?

pqyhitler 回答:我如何使用柴油在 sqlite 中更新插入?

在这里使用 upsert 的可能解决方案是什么?

对 sqlite upserts 的支持已合并 in early 2020(经过一个非常漫长且相当艰苦的 PR 过程),但它显然包括重大更改,所以我的理解是它只会在 Diesel 2.0 中可用。

因此您可能的解决方案是:

  1. 不要使用更新插入

  2. perform your query by hand

  3. use git diesel

本文链接:https://www.f2er.com/435.html

大家都在问