postgresql 如何将Postgres类型转换为Rust原生类型

b1zrtrql  于 11个月前  发布在  PostgreSQL
关注(0)|答案(1)|浏览(108)

下面是我的SQL结构:

CREATE TABLE IF NOT EXISTS passwords 
(
    id SERIAL PRIMARY KEY,
    title TEXT NOT NULL,
    username TEXT NOT NULL,
    password TEXT NOT NULL
);

字符串
当我运行以下代码时:

struct Password {
   id: u32,
   title: String,
   username: String,
   password: String,
}
let items = self.client.query("SELECT * FROM passwords", &[]).unwrap().iter().map(|row| {
            let password = Password::new_with_id(
                row.get("id"),
                row.get("title"),
                row.get("username"),
                row.get("password"),
            );
            password
        }).collect();


我得到以下错误:

thread 'main' panicked at C:\Users\k\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-postgres-0.7.10\src\row.rs:151:25:
error retrieving column id: error deserializing column 0: cannot convert between the Rust type `u32` and the Postgres type `int4`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\PaTUI.exe` (exit code: 101)


如何在Posterre类型int4和Rust类型u32之间成功转换?

zvokhttg

zvokhttg1#

tokio_postgres使用postgres_types,它将int4定义为i32

相关问题