Function rbatis::plugin::table_sync::sync
source · pub fn sync<'a>(
executor: &'a dyn Executor,
mapper: &'a dyn ColumMapper,
table: Value,
table_name: &str
) -> BoxFuture<'a, Result<(), Error>>
Expand description
create table if not exists, add column if not exists
use rbatis::executor::{Executor, RBatisConnExecutor};
use rbatis::RBatis;
use rbatis::table_sync::{MysqlTableMapper, SqliteTableMapper, sync};
use rbs::to_value;
/// let rb = RBatis::new();
/// let conn = rb.acquire().await;
pub async fn do_sync_table(conn: &dyn Executor){
let map = rbs::to_value!{
"id":"TEXT",
"name":"TEXT",
};
let _ = sync(conn, &SqliteTableMapper{},map,"user").await;
}
sync table struct
use rbatis::executor::{Executor, RBatisConnExecutor};
use rbatis::RBatis;
use rbatis::table_sync::{MysqlTableMapper, SqliteTableMapper, sync};
use rbs::to_value;
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct User{
pub id:String,
pub name: Option<String>
}
/// let rb = RBatis::new();
/// let conn = rb.acquire().await;
pub async fn do_sync_table(conn: &dyn Executor){
let table = User{id: "".to_string(), name: Some("".to_string())};
let _ = sync(conn, &SqliteTableMapper{},to_value!(table),"user").await;
}
sync table struct (custom string column type)
use rbatis::executor::Executor;
use rbatis::RBatis;
use rbatis::table_sync::{MysqlTableMapper, sync};
use rbs::to_value;
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct User{
pub id:String,
pub name: Option<String>
}
pub async fn do_sync_table_mysql(conn: &dyn Executor){
let table = User{id: "".to_string(), name: Some("VARCHAR(50)".to_string())};
let _ = sync(conn, &MysqlTableMapper{},to_value!(table),"user").await;
}