rust - 如何通过 Vec> 在 rusqlite 作为查询参数
问题描述
我正在关注来自 rusqlite git hub https://github.com/rusqlite/rusqlite/blob/master/src/vtab/array.rs#L206的示例。我有完全相同的代码,但我得到了编译错误
the trait bound `std::vec::Vec<rusqlite::types::Value>: rusqlite::ToSql` is not satisfied
代码片段如下。ids 是字符串的 Vec
let intValues:Vec<i64> = ids.into_iter().map(|s| s.parse::<i64>().expect("Id Parse error.")).collect();
let values:Vec<rusqlite::types::Value> = intValues.into_iter().map(rusqlite::types::Value::from).collect();
let ptr = std::rc::Rc::new(values);
let mut statement = db_connection
.prepare("select * from item where id in rarray(?);")
.expect("Failed to prepare second query.");
let results = statement
// This is the error line
.query_map(&[&ptr], |row| {
Ok(database::ItemData {
id: row.get(0)?,
name: row.get(1)?,
time_to_prepare: row.get(2)?
})
});
解决方案
我必须在 toml 文件的功能中添加“数组”。
推荐阅读
- activemq - ResourceAdapter 已设置 | 带有活动 MQ 的 JBoss 5.2
- react-native - React Native ScrollView,onEndReached没有触发
- azure - .net core appsettings in azure with objects
- laravel - 在服务器端 Laravel Echo 上检测“离开”频道事件
- visual-studio-code - VSCode problemMatcher $gcc 似乎消失了
- in-app-purchase - 如何实施应用内购买以禁用 TWA 中的广告
- javascript - 当 aot 设置为 true 时,ngClass 和 ngIf 条件编译失败
- macos - 自定义 Mac 终端命令 Control+w
- python - Numpy:了解 Array 的强大功能
- docker - 代理关闭时 ActiveMQ 过时的客户端连接