【问题标题】:"the trait `SupportsReturningClause` is not implemented for `Sqlite`"“ `Sqlite` 没有实现特征 `SupportsReturningClause`”
【发布时间】:2022-01-26 05:36:38
【问题描述】:

我正在尝试让柴油板条箱与 SQLite 一起使用,但离开了入门指南,它似乎不适用于 sqlite。

适用于 postgres 但不适用于 sqlite 的代码

  diesel::insert_into(schema::subscriptions::table)
      .values(&new_subscription)
      .get_result(&connection)
      .expect("Error saving new subscription")

错误

error[E0277]: the trait bound `Sqlite: SupportsReturningClause` is not satisfied
  --> src/responder.rs:41:12
   |
41 |           .get_result(&connection)
   |            ^^^^^^^^^^ the trait `SupportsReturningClause` is not implemented for `Sqlite`

我可以在 the documentation 中看到一些关于柴油退货条款的参考资料,但我不完全确定应该将其更改为什么才能使其正常工作。

【问题讨论】:

  • 正如链接文档所述,sqlite 后端不支持 RETURNING 子句。您可能必须将 get_results 替换为 execute 才能执行 INSERT,然后发出查询以检索插入的记录。
  • 是的,这似乎是解决方案
  • 你看过示例代码的SQLite version吗?
  • 是的,我找到了解决方案。认为为其他人发布帖子仍然有用,因为确切的错误消息并没有真正显示在 google 上(此帖子是现在搜索时的第二个结果)。
  • @Qwertie ,它确实对我有用,我想对其他人也有用:),也许你可以为你的问题添加一个答案。

标签: sqlite rust rust-diesel


【解决方案1】:

使用 execute 而不是 get_results 适用于 SQLite。这不会返回查询结果,因此必须运行第二个查询以获取更新的值。

【讨论】:

    猜你喜欢
    • 2021-07-18
    • 2021-04-25
    • 1970-01-01
    • 1970-01-01
    • 2019-12-08
    • 2023-04-04
    • 2019-09-10
    • 2021-06-23
    • 1970-01-01
    相关资源
    最近更新 更多