Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions example/src/books.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use serde::{Serialize, Deserialize};

#[mybatis_plus]
#[derive(Debug, Serialize, Deserialize)]
pub struct Books {
pub id: Option<String>,
pub name: Option<String>,
pub types: Option<String>
}


#[cfg(test)]
mod tests {
use super::*;
use mybatis::mybatis::Mybatis;
use mybatis::snowflake::SNOWFLAKE;
use mybatis::plus::Mapping;

#[tokio::test]
async fn save_books() {
let mybatis = Mybatis::new();

mybatis.link("mysql://root:passw0rd@localhost:3306/test").await.unwrap();

let id = SNOWFLAKE.generate();
let cat = Books {
id: Some(id.to_string()),
name: Some("《Daughter of the sea》".to_string()),
types: Some("Fairy Tales".to_string()),
};

mybatis.save(&cat,&[]).await;
}
}
2 changes: 1 addition & 1 deletion example/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use mybatis::crud::CRUD;
use mybatis::plus::Mapping;
use mybatis::mybatis::Mybatis;


Expand Down
1 change: 1 addition & 0 deletions example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extern crate mybatis;

mod pets;
mod books;
mod connection;
mod plugin_page_test;
mod snowflake_test;
Expand Down
30 changes: 23 additions & 7 deletions example/src/pets.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
use mybatis::{mybatis_sql::string_util::to_snake_name};
use mybatis::mybatis::Mybatis;
use mybatis::crud::CRUDTable;
use mybatis::plus::MybatisPlus;
use mybatis::snowflake::SNOWFLAKE;
use serde::{Serialize, Deserialize};


#[mybatis_plus]
#[derive(Debug, Serialize, Deserialize)]
pub struct Pets {
pub id: Option<String>,
pub name: Option<String>,
pub birthday: Option<mybatis::DateTimeNative>,
pub delete_flag: Option<i32>,
pub id: Option<String>,
pub name: Option<String>,
pub birthday: Option<mybatis::DateTimeNative>,
pub delete_flag: Option<i32>,
}

impl MybatisPlus for Pets {

fn table_name() -> String {
let type_name = std::any::type_name::<Self>();
let mut name = type_name.to_string();
let names: Vec<&str> = name.split("::").collect();
name = names.get(names.len() - 1).unwrap_or(&"").to_string();

to_snake_name(&name)
}

fn table_columns() -> String {
String::from("id,name,birthday,delete_flag")
}

}

#[cfg(test)]
mod tests {
use mybatis::crud::{Skip, CRUD};
use mybatis::plus::{Skip, Mapping};

use super::*;

Expand Down
4 changes: 2 additions & 2 deletions mybatis-macro/src/macros/mybatis_html_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) fn impl_macro_mybatis_html(target_fn: &ItemFn, args: &AttributeArgs)
let is_async = target_fn.sig.asyncness.is_some();
if !is_async {
panic!(
"[rbaits] #[crud_table] 'fn {}({})' must be async fn! ",
"[mybatis] #[mybatis_plus] 'fn {}({})' must be async fn! ",
func_name_ident, func_args_stream
);
}
Expand All @@ -67,7 +67,7 @@ pub(crate) fn impl_macro_mybatis_html(target_fn: &ItemFn, args: &AttributeArgs)
{
let page_ident = get_page_req_ident(target_fn, &func_name_ident.to_string());
call_method = quote! {
use mybatis::crud::{CRUD,CRUDMut};
use mybatis::plus::{Mapping,MappingMut};
#mybatis_ident.fetch_page(&sql,rb_args,#page_ident).await
};
println!("gen return");
Expand Down
4 changes: 2 additions & 2 deletions mybatis-macro/src/macros/mybatis_plus_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub(crate) fn impl_mybatis_plus_driver(


let gen = quote! {
impl mybatis::crud::CRUDTable for #name {
impl mybatis::plus::MybatisPlus for #name {

fn get(&self, column: &str) -> rbson::Bson {
#get_matchs
Expand Down Expand Up @@ -286,7 +286,7 @@ pub struct CrudEnableConfig {
pub formats: HashMap<String, String>,
}

/// impl the crud macro
/// impl the plus macro
pub(crate) fn impl_mybatis_plus(args: TokenStream, input: TokenStream) -> TokenStream {
let arg_str = args.to_string();
let config = read_config(&arg_str);
Expand Down
2 changes: 1 addition & 1 deletion mybatis-macro/src/macros/mybatis_sql_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub(crate) fn impl_macro_mybatis_sql(target_fn: &ItemFn, args: &AttributeArgs) -
let is_async = target_fn.sig.asyncness.is_some();
if !is_async {
panic!(
"[rbaits] #[crud_table] 'fn {}({})' must be async fn! ",
"[mybatis] #[mybatis_plus] 'fn {}({})' must be async fn! ",
func_name_ident, func_args_stream
);
}
Expand Down
2 changes: 1 addition & 1 deletion mybatis-macro/src/macros/py_sql_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub(crate) fn impl_macro_py_sql(target_fn: &ItemFn, args: &AttributeArgs) -> Tok
{
let page_ident = get_page_req_ident(target_fn, &func_name_ident.to_string());
call_method = quote! {
use mybatis::crud::{CRUD,CRUDMut};
use mybatis::plus::{Mapping, MappingMut};
#mybatis_ident.fetch_page(&sql,mybatis_args,#page_ident).await
};
println!("gen return");
Expand Down
2 changes: 1 addition & 1 deletion mybatis/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::de::DeserializeOwned;
use serde::{Serialize, Serializer};
use mybatis_core::db::{DBPool, DBPoolConn, DBQuery, DBTx};
use mybatis_core::Error;
use crate::crud::{CRUD, CRUDMut};
use crate::plus::{Mapping, MappingMut};
use crate::DriverType;
use crate::page::{IPageRequest, Page};
use crate::mybatis::Mybatis;
Expand Down
2 changes: 1 addition & 1 deletion mybatis/src/intercept.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use mybatis_core::convert::StmtConvert;

use crate::crud::CRUDTable;
use crate::plus::MybatisPlus;
use crate::mybatis::Mybatis;
use mybatis_core::db::DriverType;
use mybatis_core::Error;
Expand Down
2 changes: 1 addition & 1 deletion mybatis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use crate::mybatis::AsSqlTag;
#[macro_use]
pub mod mybatis;

pub mod crud;
pub mod plus;
pub mod wrapper;
pub mod executor;
pub mod intercept;
Expand Down
2 changes: 1 addition & 1 deletion mybatis/src/logic_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use mybatis_core::db::DriverType;
use mybatis_core::Error;
use mybatis_sql::TEMPLATE;
use mybatis_sql::rule::SqlRule;
use crate::crud::{CRUDTable, Skip};
use crate::plus::{MybatisPlus, Skip};
use std::ops::{Deref, DerefMut};
use std::collections::HashMap;
use serde::{Serialize, Deserialize, Serializer, Deserializer};
Expand Down
4 changes: 2 additions & 2 deletions mybatis/src/mybatis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use uuid::Uuid;

use mybatis_core::db::{DBExecResult, DBPool, DBPoolConn, DBPoolOptions, DBQuery, DBTx, DriverType};
use mybatis_core::Error;
use crate::crud::CRUDTable;
use crate::plus::MybatisPlus;
use crate::executor::{MyBatisConnExecutor, MyBatisTxExecutor, MyBatisExecutor};
use crate::intercept::SqlIntercept;
use crate::log::{LogPlugin, MyBatisLogPlugin};
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Mybatis {
/// try return an new wrapper and set table formats,if not call the link() method,it will be panic!
pub fn new_wrapper_table<T>(&self) -> Wrapper
where
T: CRUDTable,
T: MybatisPlus,
{
let mut w = self.new_wrapper();
let formats = T::formats(self.driver_type().unwrap());
Expand Down
Loading