Skip to content

Commit

Permalink
Improve postgresql operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
gudaoxuri committed Nov 29, 2022
1 parent 08c30e0 commit 0349c48
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tardis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ lazy_static = { version = "1.4" }
rand = { version = "0.8" }
rand_core = { version = "0.6" }
chrono = { version = "0.4" }
env_logger = { version = "0.9" }
env_logger = { version = "0.10" }
config = { version = "0.13" }
regex = { version = "1.5" }
url = { version = "2.2" }
Expand Down Expand Up @@ -84,6 +84,7 @@ async-trait = { version = "0.1", optional = true }
# RelDB
sea-orm = { version = "0.10", features = [
"sqlx-all",
"postgres-array",
"macros",
"runtime-tokio-native-tls",
"debug-print",
Expand Down
24 changes: 21 additions & 3 deletions tardis/src/db/reldb_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,19 @@ impl TardisRelDBClient {
Ok(())
}

pub(self) async fn insert_raw_many_inner<C>(sql: &str, params: Vec<Vec<Value>>, db: &C) -> TardisResult<()>
where
C: ConnectionTrait,
{
trace!("[Tardis.RelDBClient] Inserting many sql {}, some params:{:?}", sql, params[0]);
// TODO Performance Optimization
for param in params {
let execute_stmt = Statement::from_sql_and_values(db.get_database_backend(), sql, param);
Self::execute_inner(execute_stmt, db).await?;
}
Ok(())
}

pub(self) async fn update_one_inner<T, C>(mut model: T, db: &C, ctx: &TardisContext) -> TardisResult<()>
where
C: ConnectionTrait,
Expand Down Expand Up @@ -813,8 +826,6 @@ impl TardisRelDBlConnection {
}

/// Execute SQL operations (provide custom SQL processing capabilities) / 执行SQL操作(提供自定义SQL处理能力)
///
///
pub async fn execute_one(&self, sql: &str, params: Vec<Value>) -> TardisResult<ExecResult> {
if let Some(tx) = &self.tx {
TardisRelDBClient::execute_one_inner(sql, params, tx).await
Expand Down Expand Up @@ -905,6 +916,14 @@ impl TardisRelDBlConnection {
}
}

pub async fn insert_raw_many(&self, sql: &str, params: Vec<Vec<Value>>) -> TardisResult<()> {
if let Some(tx) = &self.tx {
TardisRelDBClient::insert_raw_many_inner(sql, params, tx).await
} else {
TardisRelDBClient::insert_raw_many_inner(sql, params, self.conn.as_ref()).await
}
}

/// Update a record / 更新一条记录
///
/// # Arguments
Expand Down Expand Up @@ -1224,7 +1243,6 @@ pub trait TardisActiveModel: ActiveModelBehavior {
| sea_query::TableRef::DatabaseSchemaTableAlias(_, _, t, _) => t.to_string(),
_ => unimplemented!(),
};
// let df = table_name.;
let create_function_sql = Self::create_function_sqls(db, &table_name, update_time_field);
return (create_table_statement, create_index_statement, create_function_sql);
}
Expand Down

0 comments on commit 0349c48

Please sign in to comment.