[英]how to implement a less than query when using rust diesel
I am using rust diesel to query the PostgreSQL 13 database,now I want to do a query like this:我正在使用 rust 柴油查询 PostgreSQL 13 数据库,现在我想做这样的查询:
select *
from fav
where playlist_id = 1
and play_count < 100
what I am doing using diesel rust code like this:我在做什么使用柴油 rust 代码,如下所示:
let playlist_records = favorites.filter(source_id.eq(req_song_id))
.filter(play_count<100)
.limit(1)
.load::<QueryFavorites>(&connection)
.expect("Error loading favorite");
seems did not work as expect, I read the diesel document but did not found the less than query demo, what should I do to implement an less than query using rust diesel?似乎没有按预期工作,我阅读了柴油文档但没有找到小于查询演示,我应该怎么做才能使用 rust 柴油实现小于查询?
you need to use diesel's methods for comparison within the filter call.您需要在过滤器调用中使用柴油的方法进行比较。
I just quickly googled "rust diesel filter" to check the official documentation, and there I found the le
method: https://docs.diesel.rs/diesel/expression_methods/trait.ExpressionMethods.html#method.lt我只是快速搜索“锈柴油过滤器”以查看官方文档,并在那里找到了le
方法: https://docs.diesel.rs/diesel/expression_methods/trait.ExpressionMethods.html#method.lt
Their example:他们的例子:
let data = users
.select(name)
.filter(id.lt(2))
.first::<String>(&connection)?;
This filters for everything where id < 2
.这会过滤id < 2
的所有内容。
So in your case, just write .filter(play_count.lt(100))
I think.所以在你的情况下,我想只写.filter(play_count.lt(100))
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.