Skip to content

Commit

Permalink
Update documentation. #6
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Mar 23, 2022
1 parent c916e1e commit d0b568d
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 89 deletions.
4 changes: 2 additions & 2 deletions examples/todos/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl TodoApi {
// curl -X POST "http://127.0.0.1:8089/todo" \
// -H "Accept: application/json" \
// -H "Content-Type: application/json" \
// -H "Tardis-Context: eyJhcHBfY29kZSI6ICIiLCJ0ZW5hbnRfY29kZSI6ICIiLCJhayI6ICIiLCJhY2NvdW50X2NvZGUiOiAiIiwidG9rZW4iOiAiIiwidG9rZW5fa2luZCI6ICIiLCJyb2xlcyI6IFtdLCJncm91cHMiOiBbXX0=" \
// -H "Tardis-Context: eyJzY29wZV9pZHMiOiAiIjogIiIsImFrIjogIiIsImFjY291bnRfaWQiOiAiIiwidG9rZW4iOiAiIiwidG9rZW5fa2luZCI6ICIiLCJyb2xlcyI6IFtdLCJncm91cHMiOiBbXX0=" \
// -d '{"code":" 测试2 ","description":"AA","done":false}'
#[oai(path = "/", method = "post")]
async fn add(&self, todo_add_req: Json<TodoAddReq>, cxt: TardisContextExtractor) -> TardisApiResult<i32> {
Expand Down Expand Up @@ -107,7 +107,7 @@ impl TodoApi {

// curl -X PUT "http://localhost:8089/todo/1" \
// -H "Accept: application/json" \
// -H "Tardis-Context: eyJhcHBfY29kZSI6ICIiLCJ0ZW5hbnRfY29kZSI6ICIiLCJhayI6ICIiLCJhY2NvdW50X2NvZGUiOiAiIiwidG9rZW4iOiAiIiwidG9rZW5fa2luZCI6ICIiLCJyb2xlcyI6IFtdLCJncm91cHMiOiBbXX0=" \
// -H "Tardis-Context: eyJzY29wZV9pZHMiOiAiIjogIiIsImFrIjogIiIsImFjY291bnRfaWQiOiAiIiwidG9rZW4iOiAiIiwidG9rZW5fa2luZCI6ICIiLCJyb2xlcyI6IFtdLCJncm91cHMiOiBbXX0=" \
// -H "Content-Type: application/json" \
// -d '{"description":"AAAAAAAA","done":false}'
#[oai(path = "/:id", method = "put")]
Expand Down
15 changes: 6 additions & 9 deletions src/basic/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ use crate::serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(default)]
pub struct TardisContext {
/// The requested application Code / 请求的应用编码
pub app_code: String,
/// The requested tenant Code / 请求的租户编码
pub tenant_code: String,
/// The requested scope ids / 请求的作用域Ids
pub scope_ids: String,
/// The requested Ak / 请求的Ak
pub ak: String,
/// The requested account code / 请求的账号编码
pub account_code: String,
/// The requested account id / 请求的账号Id
pub account_id: String,
/// The requested Token / 请求的Token
pub token: String,
/// The requested Token type / 请求的Token类型
Expand All @@ -34,10 +32,9 @@ pub struct TardisContext {
impl Default for TardisContext {
fn default() -> Self {
TardisContext {
app_code: "".to_string(),
tenant_code: "".to_string(),
scope_ids: "".to_string(),
ak: "".to_string(),
account_code: "".to_string(),
account_id: "".to_string(),
token: "".to_string(),
token_kind: "".to_string(),
roles: vec![],
Expand Down
14 changes: 7 additions & 7 deletions src/basic/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::serde_json::Value;
/// Json handle / Json处理
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// let test_config = TestConfig {
/// project_name: "测试".to_string(),
Expand Down Expand Up @@ -48,7 +48,7 @@ impl TardisJson {
/// * `str` - Json string / Json字符串
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// TardisFuns::json.str_to_obj::<TestConfig<DatabaseConfig>>(&json_str);
/// ```
Expand All @@ -67,7 +67,7 @@ impl TardisJson {
/// * `str` - Json string / Json字符串
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// TardisFuns::json.str_to_json(&json_str);
/// ```
Expand All @@ -86,7 +86,7 @@ impl TardisJson {
/// * `value` - Json object / Json对象
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// TardisFuns::json.json_to_obj::<TestConfig<DatabaseConfig>>(json_value);
/// ```
Expand All @@ -105,7 +105,7 @@ impl TardisJson {
/// * `obj` - Rust object / Rust对象
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// TardisFuns::json.obj_to_string(&rust_obj);
/// ```
Expand All @@ -124,7 +124,7 @@ impl TardisJson {
/// * `obj` - Rust object / Rust对象
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// TardisFuns::json.obj_to_json(&rust_obj);
/// ```
Expand All @@ -143,7 +143,7 @@ impl TardisJson {
/// * `value` - Json object / Json对象
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// TardisFuns::json.json_to_string(json_value);
/// ```
Expand Down
2 changes: 1 addition & 1 deletion src/cache/cache_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::log::info;
/// 1. Create the cache configuration / 创建缓存配置, @see [CacheConfig](crate::basic::config::CacheConfig)
///
/// 4. Use `TardisCacheClient` to operate cache / 使用 `TardisCacheClient` 操作缓存, E.g:
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// assert_eq!(TardisFuns::cache().get("test_key").await.unwrap(), None);
/// client.set("test_key", "测试").await.unwrap();
Expand Down
9 changes: 1 addition & 8 deletions src/db/domain/tardis_db_del_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::db::reldb_client::TardisActiveModel;
use crate::db::sea_orm::entity::prelude::*;
use crate::db::sea_orm::ActiveValue::Set;
use crate::db::sea_orm::{ActiveModelBehavior, DbBackend};
use crate::db::sea_query::{ColumnDef, Index, IndexCreateStatement, Table, TableCreateStatement};
use crate::db::sea_query::{ColumnDef, Table, TableCreateStatement};
use crate::TardisFuns;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
Expand Down Expand Up @@ -36,13 +36,6 @@ impl TardisActiveModel for ActiveModel {
.col(ColumnDef::new(Column::CreateTime).extra("DEFAULT CURRENT_TIMESTAMP".to_string()).date_time())
.to_owned()
}

fn create_index_statement() -> Vec<IndexCreateStatement> {
vec![
Index::create().name(&format!("idx-{}-{}", Entity.table_name(), Column::EntityName.to_string())).table(Entity).col(Column::EntityName).to_owned(),
Index::create().name(&format!("idx-{}-{}", Entity.table_name(), Column::RecordId.to_string())).table(Entity).col(Column::RecordId).to_owned(),
]
}
}

impl ActiveModelBehavior for ActiveModel {
Expand Down
56 changes: 28 additions & 28 deletions src/db/reldb_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::{FrameworkConfig, TardisFuns};
/// 1. Create the database configuration / 创建数据库配置, @see [DBConfig](crate::basic::config::DBConfig)
///
/// 2. Create the `domain` object / 创建 `domain` 对象, E.g:
/// ```rust
/// ```no_run
/// use sea_orm::{DeriveRelation, EnumIter};
/// mod tardis_db_config{
/// use tardis::db::sea_orm::*;
Expand Down Expand Up @@ -97,7 +97,7 @@ use crate::{FrameworkConfig, TardisFuns};
/// 3. Create TardisContext / 创建TardisContext [TardisContext](crate::basic::dto::TardisContext)
///
/// 4. Use `TardisRelDBClient` to operate database / 使用 `TardisRelDBClient` 操作数据库, E.g:
/// ```rust
/// ```no_run
/// use std::process::id;
/// use tardis::basic::dto::TardisContext;
/// use tardis::db::domain::tardis_db_config;
Expand Down Expand Up @@ -189,8 +189,8 @@ impl TardisRelDBClient {
/// Initialize basic tables / 初始化基础表
async fn init_basic_tables(&self) -> TardisResult<()> {
let tx = self.con.begin().await?;
let config_create_table_statement = tardis_db_config::ActiveModel::create_table_statement(self.con.get_database_backend());
TardisRelDBClient::create_table_inner(&config_create_table_statement, &tx).await?;
let config_create_table_statements = tardis_db_config::ActiveModel::create_table_and_index_statement(self.con.get_database_backend());
TardisRelDBClient::create_table_and_index_inner(&config_create_table_statements, &tx).await?;
let del_record_create_statements = tardis_db_del_record::ActiveModel::create_table_and_index_statement(self.con.get_database_backend());
TardisRelDBClient::create_table_and_index_inner(&del_record_create_statements, &tx).await?;
tx.commit().await?;
Expand Down Expand Up @@ -384,7 +384,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// Get original connection (generally not recommended) / 获取原始连接(一般不推荐使用)
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// let raw_conn = TardisFuns::reldb().conn().raw_conn();
/// ```
Expand All @@ -395,7 +395,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// Get original transaction (if a transaction exists for the current object) (generally not recommended) / 获取原始事务(如果当前对象存在事务的话)(一般不推荐使用)
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// let raw_tx = TardisFuns::reldb().conn().raw_tx().unwrap();
/// ```
Expand All @@ -410,7 +410,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// Open a transaction / 开启一个事务
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// let mut conn = TardisFuns::reldb().conn();
/// let tx = conn.begin().await.unwrap();
Expand All @@ -423,7 +423,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// Commit current transaction / 提交当前事务
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// let mut conn = TardisFuns::reldb().conn();
/// let tx = conn.begin().await.unwrap();
Expand All @@ -439,7 +439,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// Rollback current transaction / 回滚当前事务
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::TardisFuns;
/// let mut conn = TardisFuns::reldb().conn();
/// let tx = conn.begin().await.unwrap();
Expand All @@ -459,7 +459,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `entity` - entity / 实体
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::domain::tardis_db_config;
/// use tardis::TardisFuns;
/// let mut conn = TardisFuns::reldb().conn();
Expand All @@ -483,7 +483,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `statements` - Statement for creating table and creating index / 创建表和创建索引的Statement
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::domain::tardis_db_config;
/// use tardis::db::reldb_client::TardisActiveModel;
/// use tardis::TardisFuns;
Expand All @@ -502,7 +502,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `statement` - Statement for creating a table / 创建表的Statement
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::domain::tardis_db_config;
/// use tardis::db::reldb_client::TardisActiveModel;
/// use tardis::TardisFuns;
Expand All @@ -524,7 +524,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `statement` - Statement for creating index / 创建索引的Statement
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::domain::tardis_db_config;
/// use tardis::db::reldb_client::TardisActiveModel;
/// use tardis::TardisFuns;
Expand All @@ -546,7 +546,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `select_statement` - Statement of the query / 查询的Statement
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::sea_query::*;
/// use tardis::db::domain::tardis_db_config;
/// use tardis::db::reldb_client::TardisActiveModel;
Expand Down Expand Up @@ -577,7 +577,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `select_statement` - Statement of the query / 查询的Statement
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::sea_query::*;
/// use tardis::db::domain::tardis_db_config;
/// use tardis::db::reldb_client::TardisActiveModel;
Expand Down Expand Up @@ -609,7 +609,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `page_size` - Number of records per page / 每页记录数
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::sea_query::*;
/// use tardis::db::domain::tardis_db_config;
/// use tardis::db::reldb_client::TardisActiveModel;
Expand Down Expand Up @@ -640,7 +640,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `select_statement` - Statement of the query / 查询的Statement
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::sea_query::*;
/// use tardis::db::domain::tardis_db_config;
/// use tardis::db::reldb_client::TardisActiveModel;
Expand Down Expand Up @@ -682,7 +682,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `cxt` - TardisContext
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::sea_orm::*;
/// use tardis::db::sea_query::*;
/// use tardis::db::domain::tardis_db_config;
Expand Down Expand Up @@ -714,7 +714,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `cxt` - TardisContext
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::sea_orm::*;
/// use tardis::db::sea_query::*;
/// use tardis::db::domain::tardis_db_config;
Expand Down Expand Up @@ -748,7 +748,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `cxt` - TardisContext
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::sea_orm::*;
/// use tardis::db::sea_query::*;
/// use tardis::db::domain::tardis_db_config;
Expand Down Expand Up @@ -780,7 +780,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `update_statement` - Statement to be updated / 要更新的Statement
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::sea_orm::*;
/// use tardis::db::sea_query::*;
/// use tardis::db::domain::tardis_db_config;
Expand Down Expand Up @@ -810,7 +810,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `delete_user` - Delete user / 删除人
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::sea_orm::*;
/// use tardis::db::sea_query::*;
/// use tardis::db::domain::tardis_db_config;
Expand Down Expand Up @@ -839,7 +839,7 @@ impl<'a> TardisRelDBlConnection<'a> {
/// * `delete_user` - Delete user / 删除人
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::sea_orm::*;
/// use tardis::db::sea_query::*;
/// use tardis::db::domain::tardis_db_config;
Expand Down Expand Up @@ -969,7 +969,7 @@ pub trait TardisActiveModel: ActiveModelBehavior {
/// * `is_insert` - whether to insert the operation / 是否插入操作
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::basic::dto::TardisContext;
/// use tardis::db::sea_orm::*;
///
Expand All @@ -989,7 +989,7 @@ pub trait TardisActiveModel: ActiveModelBehavior {
/// * `db` - database instance type / 数据库实例类型
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::sea_orm::*;
/// use tardis::db::sea_query::*;
/// use tardis::basic::dto::TardisContext;
Expand All @@ -1008,7 +1008,7 @@ pub trait TardisActiveModel: ActiveModelBehavior {
/// * `db` - database instance type / 数据库实例类型
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::domain::tardis_db_config;
/// use tardis::db::sea_orm::*;
/// use tardis::db::sea_query::*;
Expand Down Expand Up @@ -1055,7 +1055,7 @@ pub trait TardisActiveModel: ActiveModelBehavior {
/// Create index / 创建索引
///
/// # Examples
/// ```rust
/// ```no_run
/// use tardis::db::domain::tardis_db_config;
/// use tardis::db::sea_orm::*;
/// use tardis::db::sea_query::*;
Expand All @@ -1069,7 +1069,7 @@ pub trait TardisActiveModel: ActiveModelBehavior {
/// ]
/// }
fn create_index_statement() -> Vec<IndexCreateStatement> {
vec![IndexCreateStatement::new()]
vec![]
}
}

Expand Down
Loading

0 comments on commit d0b568d

Please sign in to comment.