3

I have a Postgres table having three fields id which is a bigserial, meta a jsonb field and a uuid UUID field.

pub struct MetaLogs {

    pub id:i64,
    pub uuid: <what type should I give here > 
    pub meta: < What type should I give here > 
}

I am using sqlx ORM for Rust. Although I understood that I have to add

features = [ "runtime-tokio", "macros" ,"postgres","json","uuid"]

I was unable to figure it out how to proceed after that

Sebastián Palma
  • 32,692
  • 6
  • 40
  • 59
Asnim P Ansari
  • 1,932
  • 1
  • 18
  • 41

1 Answers1

6

sqlx provides both Json and Uuid type implementations for PostgreSQL. See uuid.rs and json.rs.

Note the Json type will resolve to jsonb internally which is as you'd expect.

Sample:

use sqlx::{types::Uuid, types::Json};
pub struct MetaLogs {
    pub id: i64,
    pub uuid: Uuid, 
    pub meta: Json,
}
pretzelhammer
  • 13,874
  • 15
  • 47
  • 98
w08r
  • 1,639
  • 13
  • 14