Skip to content

Commit b2f0059

Browse files
Fix cargo fmt across workspace
1 parent 92c1c74 commit b2f0059

16 files changed

Lines changed: 410 additions & 159 deletions

File tree

crates/contextdb-cli/src/repl.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ pub(crate) fn handle_meta_command(db: &Database, line: &str) -> bool {
8181
fn print_table_meta(table: &str, meta: &TableMeta) {
8282
println!("CREATE TABLE {table} (");
8383
for (idx, col) in meta.columns.iter().enumerate() {
84-
let comma = if idx + 1 == meta.columns.len() { "" } else { "," };
84+
let comma = if idx + 1 == meta.columns.len() {
85+
""
86+
} else {
87+
","
88+
};
8589
let nullable = if col.nullable { "" } else { " NOT NULL" };
8690
let pk = if col.primary_key { " PRIMARY KEY" } else { "" };
8791
println!(

crates/contextdb-engine/src/database.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,12 @@ impl Database {
163163
execute_plan(self, &plan, params, Some(tx))
164164
}
165165

166-
pub fn insert_row(&self, tx: TxId, table: &str, values: HashMap<ColName, Value>) -> Result<RowId> {
166+
pub fn insert_row(
167+
&self,
168+
tx: TxId,
169+
table: &str,
170+
values: HashMap<ColName, Value>,
171+
) -> Result<RowId> {
167172
self.relational.insert(tx, table, values)
168173
}
169174

@@ -225,7 +230,8 @@ impl Database {
225230
max_depth: u32,
226231
snapshot: SnapshotId,
227232
) -> Result<TraversalResult> {
228-
self.graph.bfs(start, edge_types, direction, 1, max_depth, snapshot)
233+
self.graph
234+
.bfs(start, edge_types, direction, 1, max_depth, snapshot)
229235
}
230236

231237
pub fn insert_vector(&self, tx: TxId, row_id: RowId, vector: Vec<f32>) -> Result<()> {

crates/contextdb-engine/src/executor.rs

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,14 @@ pub(crate) fn execute_plan(
6363
} else {
6464
Some(edge_types.as_slice())
6565
};
66-
let res = db
67-
.graph()
68-
.bfs(
69-
start,
70-
edge_types_ref,
71-
*direction,
72-
*min_depth,
73-
*max_depth,
74-
db.snapshot(),
75-
)?;
66+
let res = db.graph().bfs(
67+
start,
68+
edge_types_ref,
69+
*direction,
70+
*min_depth,
71+
*max_depth,
72+
db.snapshot(),
73+
)?;
7674

7775
Ok(QueryResult {
7876
columns: vec!["id".to_string(), "depth".to_string()],
@@ -114,7 +112,9 @@ pub(crate) fn execute_plan(
114112
columns: vec!["row_id".to_string(), "score".to_string()],
115113
rows: res
116114
.into_iter()
117-
.map(|(rid, score)| vec![Value::Int64(rid as i64), Value::Float64(score as f64)])
115+
.map(|(rid, score)| {
116+
vec![Value::Int64(rid as i64), Value::Float64(score as f64)]
117+
})
118118
.collect(),
119119
rows_affected: 0,
120120
})
@@ -127,7 +127,9 @@ pub(crate) fn execute_plan(
127127
}
128128
Ok(last)
129129
}
130-
_ => Err(Error::PlanError("unsupported plan node in executor".to_string())),
130+
_ => Err(Error::PlanError(
131+
"unsupported plan node in executor".to_string(),
132+
)),
131133
}
132134
}
133135

@@ -159,19 +161,17 @@ fn exec_insert(
159161
};
160162

161163
if p.table == "edges"
162-
&& let (Some(Value::Uuid(source)), Some(Value::Uuid(target)), Some(Value::Text(edge_type))) = (
164+
&& let (
165+
Some(Value::Uuid(source)),
166+
Some(Value::Uuid(target)),
167+
Some(Value::Text(edge_type)),
168+
) = (
163169
values.get("source_id"),
164170
values.get("target_id"),
165171
values.get("edge_type"),
166172
)
167173
{
168-
db.insert_edge(
169-
txid,
170-
*source,
171-
*target,
172-
edge_type.clone(),
173-
HashMap::new(),
174-
)?;
174+
db.insert_edge(txid, *source, *target, edge_type.clone(), HashMap::new())?;
175175
}
176176

177177
if let Some(Value::Vector(v)) = values.get("embedding")
@@ -197,7 +197,11 @@ fn exec_delete(
197197
let rows = db.scan(&p.table, snapshot)?;
198198
let matched: Vec<_> = rows
199199
.into_iter()
200-
.filter(|r| p.where_clause.as_ref().is_none_or(|w| row_matches(r, w, params).unwrap_or(false)))
200+
.filter(|r| {
201+
p.where_clause
202+
.as_ref()
203+
.is_none_or(|w| row_matches(r, w, params).unwrap_or(false))
204+
})
201205
.collect();
202206

203207
for row in &matched {
@@ -218,7 +222,11 @@ fn exec_update(
218222
let rows = db.scan(&p.table, snapshot)?;
219223
let matched: Vec<_> = rows
220224
.into_iter()
221-
.filter(|r| p.where_clause.as_ref().is_none_or(|w| row_matches(r, w, params).unwrap_or(false)))
225+
.filter(|r| {
226+
p.where_clause
227+
.as_ref()
228+
.is_none_or(|w| row_matches(r, w, params).unwrap_or(false))
229+
})
222230
.collect();
223231

224232
for row in &matched {
@@ -286,7 +294,11 @@ fn row_matches(row: &VersionedRow, expr: &Expr, params: &HashMap<String, Value>)
286294
}
287295
}
288296

289-
fn eval_expr_value(row: &VersionedRow, expr: &Expr, params: &HashMap<String, Value>) -> Result<Value> {
297+
fn eval_expr_value(
298+
row: &VersionedRow,
299+
expr: &Expr,
300+
params: &HashMap<String, Value>,
301+
) -> Result<Value> {
290302
match expr {
291303
Expr::Column(c) => Ok(row.values.get(&c.column).cloned().unwrap_or(Value::Null)),
292304
_ => resolve_expr(expr, params),
@@ -317,7 +329,9 @@ fn resolve_uuid(expr: &Expr, params: &HashMap<String, Value>) -> Result<uuid::Uu
317329
Value::Uuid(u) => Ok(u),
318330
Value::Text(t) => uuid::Uuid::parse_str(&t)
319331
.map_err(|e| Error::PlanError(format!("invalid uuid '{}': {}", t, e))),
320-
_ => Err(Error::PlanError("graph start node must be UUID".to_string())),
332+
_ => Err(Error::PlanError(
333+
"graph start node must be UUID".to_string(),
334+
)),
321335
}
322336
}
323337

@@ -328,7 +342,9 @@ fn resolve_vector_from_expr(expr: &Expr, params: &HashMap<String, Value>) -> Res
328342
Some(Value::Vector(v)) => Ok(v.clone()),
329343
_ => Err(Error::PlanError("vector parameter missing".to_string())),
330344
},
331-
_ => Err(Error::PlanError("invalid vector query expression".to_string())),
345+
_ => Err(Error::PlanError(
346+
"invalid vector query expression".to_string(),
347+
)),
332348
}
333349
}
334350

crates/contextdb-engine/src/schema_enforcer.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ pub fn validate_dml(
2121
&& let Some(id_idx) = p.columns.iter().position(|c| c == "id")
2222
{
2323
for row in &p.values {
24-
let id_value = row.get(id_idx).map(|e| resolve_expr(e, params)).transpose()?;
24+
let id_value = row
25+
.get(id_idx)
26+
.map(|e| resolve_expr(e, params))
27+
.transpose()?;
2528
if let Some(v) = id_value {
2629
let lookup = db.point_lookup(&p.table, "id", &v, db.snapshot())?;
2730
if lookup.is_some() {
@@ -59,6 +62,8 @@ fn resolve_expr(expr: &Expr, params: &HashMap<String, Value>) -> Result<Value> {
5962
.cloned()
6063
.ok_or_else(|| Error::NotFound(format!("missing parameter: {}", p))),
6164
Expr::Column(c) => Ok(Value::Text(c.column.clone())),
62-
_ => Err(Error::PlanError("unsupported expression in schema enforcer".to_string())),
65+
_ => Err(Error::PlanError(
66+
"unsupported expression in schema enforcer".to_string(),
67+
)),
6368
}
6469
}

0 commit comments

Comments
 (0)