问题描述
我有一个包含三个字段的Postgres表
id
,是bigserial
,meta
是jsonb
字段,是uuid UUID
字段。
pub struct MetaLogs {
pub id:i64,pub uuid: <what type should I give here >
pub meta: < What type should I give here >
}
我在sqlx
中使用Rust
ORM。
虽然我知道我必须添加
features = [ "runtime-tokio","macros","postgres","json","uuid"]
在那之后我无法弄清楚如何进行
解决方法
sqlx
为PostgreSQL提供了Json
和Uuid
类型的实现。参见:
和
请注意,Json类型将在内部解析为jsonb,这与您期望的一样。
示例:
use sqlx::{types::Uuid,types::Json};
pub struct MetaLogs {
pub id:i64,pub uuid: Uuid,pub meta: Json,}