commit c08891446f9ee8b2531125fc16b37f240cac426f
parent 25882cfd0eed622a25e28ed9cb41a988af511d00
Author: triesap <tyson@radroots.org>
Date: Fri, 6 Mar 2026 23:30:30 +0000
sql-core: add reference executor forwarding coverage
- add sqlexecutor impl for &t to allow forwarding through borrowed executors
- forward exec query begin commit and rollback directly to the inner executor
- add coverage test that invokes all forwarded methods via ufcs on &mockexecutor
- verify crate gates with cargo check cargo test and xtask coverage 100/100/100/100
Diffstat:
2 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/crates/sql-core/src/lib.rs b/crates/sql-core/src/lib.rs
@@ -48,3 +48,28 @@ pub trait SqlExecutor: Send + Sync {
fn commit(&self) -> Result<(), SqlError>;
fn rollback(&self) -> Result<(), SqlError>;
}
+
+impl<T> SqlExecutor for &T
+where
+ T: SqlExecutor + ?Sized,
+{
+ fn exec(&self, sql: &str, params_json: &str) -> Result<ExecOutcome, SqlError> {
+ (**self).exec(sql, params_json)
+ }
+
+ fn query_raw(&self, sql: &str, params_json: &str) -> Result<String, SqlError> {
+ (**self).query_raw(sql, params_json)
+ }
+
+ fn begin(&self) -> Result<(), SqlError> {
+ (**self).begin()
+ }
+
+ fn commit(&self) -> Result<(), SqlError> {
+ (**self).commit()
+ }
+
+ fn rollback(&self) -> Result<(), SqlError> {
+ (**self).rollback()
+ }
+}
diff --git a/crates/sql-core/tests/coverage.rs b/crates/sql-core/tests/coverage.rs
@@ -165,6 +165,30 @@ impl SqlExecutor for MockExecutor {
}
}
+#[test]
+fn sql_executor_reference_impl_forwards_all_methods() {
+ let exec = MockExecutor::new();
+ let exec_ref = &exec;
+
+ let exec_result = <&MockExecutor as SqlExecutor>::exec(&exec_ref, "select 1", "[]")
+ .expect("reference exec should forward");
+ assert_eq!(exec_result.changes, 1);
+
+ let query_result = <&MockExecutor as SqlExecutor>::query_raw(&exec_ref, "select 1", "[]")
+ .expect("reference query should forward");
+ assert_eq!(query_result, String::new());
+
+ <&MockExecutor as SqlExecutor>::begin(&exec_ref).expect("reference begin should forward");
+ <&MockExecutor as SqlExecutor>::commit(&exec_ref).expect("reference commit should forward");
+ <&MockExecutor as SqlExecutor>::rollback(&exec_ref).expect("reference rollback should forward");
+
+ let snapshot = exec.snapshot();
+ assert_eq!(snapshot.begin_count, 1);
+ assert_eq!(snapshot.commit_count, 1);
+ assert_eq!(snapshot.rollback_count, 1);
+ assert!(snapshot.exec_sql.iter().any(|sql| sql == "select 1"));
+}
+
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Payload {
id: String,