Skip to content

Commit

Permalink
Update expand implementation that improves the insert performances
Browse files Browse the repository at this point in the history
  • Loading branch information
dlachaume committed May 3, 2024
1 parent 5710dee commit 7981e0c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions internal/mithril-persistence/src/sqlite/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,21 @@ impl WhereCondition {

/// Turn the condition into a SQL string representation.
pub fn expand(self) -> (String, Vec<Value>) {
let mut expression = self.condition.expand();
let expression = self.condition.expand();
let parameters = self.parameters;
let mut param_index = 1;
//
// Replace parameters placeholders by numerated parameters.
loop {
if !expression.contains("?*") {
break;
}
expression = expression.replacen("?*", &format!("?{param_index}"), 1);
let mut final_expression = "".to_string();
let mut value = "".to_string();
let mut param_index = 0;
for sql_part in expression.split("?*") {
final_expression.push_str(&value);
final_expression.push_str(sql_part);
param_index += 1;
value = format!("?{}", param_index);
}

(expression, parameters)
(final_expression.to_string(), parameters)
}

/// Instanciate a condition with a `IN` statement.
Expand Down

0 comments on commit 7981e0c

Please sign in to comment.