github rbatis/rbatis v1.8.47

latest releases: v4.5.22, v4.5.21, v4.5.20...
3 years ago

v1.8.47

  • fix #59 #61
  • add #[crud_enable(formats_pg: column:format_data)] macro for #59 . so you can format any table column for mysql,pg,sqlite,mssql....(also include Wrapper support format)
    for example( ‘id:{}::uuid’ That means by column format to 'id_value::uuid' ):
    #[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;
    }

exec result log

2020-12-14 14:26:58.072638 +08:00    INFO rbatis::plugin::log - [rbatis] [] Exec  ==> CREATE TABLE biz_uuid( id uuid, name VARCHAR, PRIMARY KEY(id));
2020-12-14 14:26:58.084423 +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 14:26:58.092696 +08:00    INFO rbatis::plugin::log - [rbatis] [] RowsAffected <== Ok(
    DBExecResult {
        rows_affected: 1,
        last_insert_id: None,
    },
)
2020-12-14 14:26:58.093312 +08:00    INFO rbatis::plugin::log - [rbatis] [] Exec  ==> UPDATE biz_uuid SET  name = $1 WHERE id = $2::uuid
                                                                [rbatis] [] Args  ==> ["test_updated","df07fea2-b819-4e05-b86d-dfc15a5f52a9"]
2020-12-14 14:26:58.103709 +08:00    INFO rbatis::plugin::log - [rbatis] [] RowsAffected <== Ok(
    DBExecResult {
        rows_affected: 1,
        last_insert_id: None,
    },
)
2020-12-14 14:26:58.103995 +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 14:26:58.125231 +08:00    INFO rbatis::plugin::log - [rbatis] [] ReturnRows <== 1
2020-12-14 14:26:58.125965 +08:00    INFO rbatis::plugin::log - [rbatis] [] Exec  ==> DELETE FROM biz_uuid WHERE id = $1::uuid
                                                                [rbatis] [] Args  ==> ["df07fea2-b819-4e05-b86d-dfc15a5f52a9"]
BizUuid { id: Some(df07fea2-b819-4e05-b86d-dfc15a5f52a9), name: Some("test_updated") }

Don't miss a new rbatis release

NewReleases is sending notifications on new releases.