-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data insertion in postgres UUID column fails. Add support for rust native uuid::Uuid data type #59
Comments
Tested with |
i try fix this issues, you can see rbatis example(https://rbatis.github.io/rbatis.io/#/README_EN?id=database-column-formatting-macro): #[async_std::test]
pub async fn test_postgres_uuid() {
fast_log::init_log("requests.log", 1000, log::Level::Info, None, true);
let rb = Rbatis::new();
rb.link("postgres://postgres:123456@localhost:5432/postgres").await.unwrap();
//'formats_pg' use postgres format
//'id' -> table column 'id'
//'{}::uuid' -> format data str
#[crud_enable(formats_pg:id:{}::uuid)]
#[derive(Clone, Debug)]
pub struct BizUuid {
pub id: Option<Uuid>,
pub name: Option<String>,
}
let uuid = Uuid::from_str("df07fea2-b819-4e05-b86d-dfc15a5f52a9").unwrap();
//create table
rb.exec("", "CREATE TABLE biz_uuid( id uuid, name VARCHAR, PRIMARY KEY(id));").await;
//insert table
rb.save("", &BizUuid { id: Some(uuid), name: Some("test".to_string()) }).await;
//update table
rb.update_by_id("",&BizUuid{ id: Some(uuid.clone()), name: Some("test_updated".to_string()) }).await;
//query table
let data: BizUuid = rb.fetch_by_id("", &uuid).await.unwrap();
println!("{:?}", data);
//delete table
rb.remove_by_id::<BizUuid>("",&uuid).await;
}
2020-12-14 00:53:57.009017800 +08:00 INFO rbatis::plugin::log - [rbatis] [] Exec ==> CREATE TABLE biz_uuid( id uuid, name VARCHAR, PRIMARY KEY(id));
2020-12-14 00:53:57.016153600 +08:00 INFO rbatis::plugin::log - [rbatis] [] Exec ==> INSERT INTO biz_uuid (id,name) VALUES ($1::uuid,$2)
[rbatis] [] Args ==> ["df07fea2-b819-4e05-b86d-dfc15a5f52a9","test"]
2020-12-14 00:53:57.019584500 +08:00 INFO rbatis::plugin::log - [rbatis] [] RowsAffected <== 0
2020-12-14 00:53:57.019803300 +08:00 INFO rbatis::plugin::log - [rbatis] [] Query ==> SELECT id,name FROM biz_uuid WHERE id = $1::uuid
[rbatis] [] Args ==> ["df07fea2-b819-4e05-b86d-dfc15a5f52a9"]
2020-12-14 00:53:57.023173600 +08:00 INFO rbatis::plugin::log - [rbatis] [] ReturnRows <== 1
2020-12-14 00:53:57.023376700 +08:00 INFO rbatis::plugin::log - [rbatis] [] Exec ==> DELETE FROM biz_uuid WHERE id = $1::uuid
[rbatis] [] Args ==> ["df07fea2-b819-4e05-b86d-dfc15a5f52a9"]
2020-12-14 00:53:57.029783900 +08:00 INFO rbatis::plugin::log - [rbatis] [] RowsAffected <== Ok(
DBExecResult {
rows_affected: 1,
last_insert_id: None,
},
)
BizUuid { id: Some(df07fea2-b819-4e05-b86d-dfc15a5f52a9), name: Some("test") } |
fix in rbatis v1.8.47 |
When struct field has type
uuid::Uuid
it doesn't correctly translate to native postgres uuid type.uuid data type is represented as string instead.
See the following error from database:
Additionally add support for CRUDEnable IdType = uuid::Uuid.
The text was updated successfully, but these errors were encountered: