-
Notifications
You must be signed in to change notification settings - Fork 1
fix: address high and medium priority code review issues #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
devin-ai-integration
wants to merge
12
commits into
main
Choose a base branch
from
devin/1772088419-fix-high-medium-issues
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
609f329
fix: address high and medium priority code review issues
devin-ai-integration[bot] ae32a82
fix: use chrono wrapper types in bind.rs for gcloud-spanner ToKind co…
devin-ai-integration[bot] c16e886
fix: use clone instead of double-deref for boxed chrono types in bind.rs
devin-ai-integration[bot] c517d2a
fix: use as_ref() to properly deref boxed chrono types in bind.rs
devin-ai-integration[bot] 813b808
fix: use operator deref (**v) for Copy chrono types in bind.rs
devin-ai-integration[bot] 78b68de
fix: use original chrono handling (and_utc/as_ref/to_utc) in bind.rs
devin-ai-integration[bot] 7b20453
fix: use chrono wrapper types with auto-deref method calls in bind.rs
devin-ai-integration[bot] 1ae00e3
fix: disambiguate String::as_ref() type in bind.rs
devin-ai-integration[bot] 9048084
fix: properly disambiguate String::as_ref() with typed let binding
devin-ai-integration[bot] 1e50455
fix: disambiguate Vec<u8>::as_ref() for Bytes type in bind.rs
devin-ai-integration[bot] 835c82b
Merge branch 'main' into devin/1772088419-fix-high-medium-issues
devin-ai-integration[bot] f51d456
fix: register orphaned modules in lib.rs and update to current gcloud…
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| use { | ||
| crate::error::SpannerDbErr, | ||
| gcloud_spanner::statement::Statement as SpannerStatement, | ||
| sea_orm::{DbErr, Statement}, | ||
| }; | ||
|
|
||
| /// Convert a SeaORM Statement into a Spanner Statement with bound parameters. | ||
| pub(crate) fn convert_statement(stmt: &Statement) -> Result<SpannerStatement, DbErr> { | ||
| let sql = &stmt.sql; | ||
| let mut spanner_stmt = SpannerStatement::new(sql); | ||
|
|
||
| if let Some(values) = &stmt.values { | ||
| for (idx, value) in values.0.iter().enumerate() { | ||
| let param_name = format!("p{}", idx + 1); | ||
| bind_value(&mut spanner_stmt, ¶m_name, value)?; | ||
| } | ||
| } | ||
|
|
||
| Ok(spanner_stmt) | ||
| } | ||
|
|
||
| /// Bind a sea_orm::Value to a Spanner Statement parameter. | ||
| /// | ||
| /// This is the shared implementation used by SpannerExecutor, SpannerReadWriteTransaction, | ||
| /// and SpannerReadOnlyTransaction. The proxy path (SpannerProxy) has its own implementation | ||
| /// that uses custom wrapper types for Spanner-specific type handling. | ||
| pub(crate) fn bind_value( | ||
| stmt: &mut SpannerStatement, | ||
| param_name: &str, | ||
| value: &sea_orm::Value, | ||
| ) -> Result<(), DbErr> { | ||
| use sea_orm::Value; | ||
|
|
||
| match value { | ||
| Value::Bool(Some(v)) => stmt.add_param(param_name, v), | ||
| Value::Bool(None) => stmt.add_param(param_name, &Option::<bool>::None), | ||
| Value::TinyInt(Some(v)) => stmt.add_param(param_name, &(*v as i64)), | ||
| Value::TinyInt(None) => stmt.add_param(param_name, &Option::<i64>::None), | ||
| Value::SmallInt(Some(v)) => stmt.add_param(param_name, &(*v as i64)), | ||
| Value::SmallInt(None) => stmt.add_param(param_name, &Option::<i64>::None), | ||
| Value::Int(Some(v)) => stmt.add_param(param_name, &(*v as i64)), | ||
| Value::Int(None) => stmt.add_param(param_name, &Option::<i64>::None), | ||
| Value::BigInt(Some(v)) => stmt.add_param(param_name, v), | ||
| Value::BigInt(None) => stmt.add_param(param_name, &Option::<i64>::None), | ||
| Value::TinyUnsigned(Some(v)) => stmt.add_param(param_name, &(*v as i64)), | ||
| Value::TinyUnsigned(None) => stmt.add_param(param_name, &Option::<i64>::None), | ||
| Value::SmallUnsigned(Some(v)) => stmt.add_param(param_name, &(*v as i64)), | ||
| Value::SmallUnsigned(None) => stmt.add_param(param_name, &Option::<i64>::None), | ||
| Value::Unsigned(Some(v)) => stmt.add_param(param_name, &(*v as i64)), | ||
| Value::Unsigned(None) => stmt.add_param(param_name, &Option::<i64>::None), | ||
| Value::BigUnsigned(Some(v)) => { | ||
| let i = i64::try_from(*v).map_err(|_| SpannerDbErr::TypeConversion { | ||
| column: param_name.to_string(), | ||
| expected: "i64".to_string(), | ||
| got: format!("u64 value {} overflows i64", v), | ||
| })?; | ||
| stmt.add_param(param_name, &i); | ||
| } | ||
| Value::BigUnsigned(None) => stmt.add_param(param_name, &Option::<i64>::None), | ||
| Value::Float(Some(v)) => stmt.add_param(param_name, &(*v as f64)), | ||
| Value::Float(None) => stmt.add_param(param_name, &Option::<f64>::None), | ||
| Value::Double(Some(v)) => stmt.add_param(param_name, v), | ||
| Value::Double(None) => stmt.add_param(param_name, &Option::<f64>::None), | ||
| Value::String(Some(v)) => { | ||
| let s: &str = v.as_ref(); | ||
| stmt.add_param(param_name, &s) | ||
| } | ||
| Value::String(None) => stmt.add_param(param_name, &Option::<String>::None), | ||
| Value::Char(Some(v)) => stmt.add_param(param_name, &v.to_string()), | ||
| Value::Char(None) => stmt.add_param(param_name, &Option::<String>::None), | ||
| Value::Bytes(Some(v)) => { | ||
| let b: &[u8] = v.as_ref(); | ||
| stmt.add_param(param_name, &b) | ||
| } | ||
| Value::Bytes(None) => stmt.add_param(param_name, &Option::<Vec<u8>>::None), | ||
|
|
||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDate(Some(v)) => stmt.add_param(param_name, &v.format("%Y-%m-%d").to_string()), | ||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDate(None) => stmt.add_param(param_name, &Option::<String>::None), | ||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoTime(Some(v)) => { | ||
| stmt.add_param(param_name, &v.format("%H:%M:%S%.f").to_string()) | ||
| } | ||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoTime(None) => stmt.add_param(param_name, &Option::<String>::None), | ||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDateTime(Some(v)) => stmt.add_param( | ||
| param_name, | ||
| &crate::chrono_support::SpannerTimestamp::new(v.and_utc()), | ||
| ), | ||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDateTime(None) => stmt.add_param( | ||
| param_name, | ||
| &crate::chrono_support::SpannerOptionalTimestamp::none(), | ||
| ), | ||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDateTimeUtc(Some(v)) => stmt.add_param( | ||
| param_name, | ||
| &crate::chrono_support::SpannerTimestamp::new(v.to_utc()), | ||
| ), | ||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDateTimeUtc(None) => stmt.add_param( | ||
| param_name, | ||
| &crate::chrono_support::SpannerOptionalTimestamp::none(), | ||
| ), | ||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDateTimeLocal(Some(v)) => stmt.add_param( | ||
| param_name, | ||
| &crate::chrono_support::SpannerTimestamp::new(v.to_utc()), | ||
| ), | ||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDateTimeLocal(None) => stmt.add_param( | ||
| param_name, | ||
| &crate::chrono_support::SpannerOptionalTimestamp::none(), | ||
| ), | ||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDateTimeWithTimeZone(Some(v)) => stmt.add_param( | ||
| param_name, | ||
| &crate::chrono_support::SpannerTimestamp::new(v.to_utc()), | ||
| ), | ||
| #[cfg(feature = "with-chrono")] | ||
| Value::ChronoDateTimeWithTimeZone(None) => stmt.add_param( | ||
| param_name, | ||
| &crate::chrono_support::SpannerOptionalTimestamp::none(), | ||
| ), | ||
|
|
||
| #[cfg(feature = "with-uuid")] | ||
| Value::Uuid(Some(v)) => stmt.add_param(param_name, &v.to_string()), | ||
| #[cfg(feature = "with-uuid")] | ||
| Value::Uuid(None) => stmt.add_param(param_name, &Option::<String>::None), | ||
|
|
||
| #[cfg(feature = "with-json")] | ||
| Value::Json(Some(v)) => stmt.add_param( | ||
| param_name, | ||
| &crate::json_support::SpannerOptionalJson::some(v.as_ref().clone()), | ||
| ), | ||
| #[cfg(feature = "with-json")] | ||
| Value::Json(None) => stmt.add_param( | ||
| param_name, | ||
| &crate::json_support::SpannerOptionalJson::none(), | ||
| ), | ||
|
|
||
| #[cfg(feature = "with-rust_decimal")] | ||
| Value::Decimal(Some(v)) => stmt.add_param(param_name, &v.to_string()), | ||
| #[cfg(feature = "with-rust_decimal")] | ||
| Value::Decimal(None) => stmt.add_param(param_name, &Option::<String>::None), | ||
|
|
||
| #[allow(unreachable_patterns)] | ||
| _ => { | ||
| return Err(SpannerDbErr::TypeConversion { | ||
| column: param_name.to_string(), | ||
| expected: "supported type".to_string(), | ||
| got: format!("{:?}", value), | ||
| } | ||
| .into()); | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpannerConnection::close(self)will panic at runtime if theArc<Client>has been cloned anywhere else (Arc::try_unwrap(...).expect(...)). SinceSpannerConnectionisCloneand now publicly exported, this is easy to trigger unintentionally and would crash consumer applications. Consider returning aResult<(), DbErr>(or logging and returning) whentry_unwrapfails instead of panicking, or provide a separate infallibleclose_if_unique(self)helper if you want to preserve strict behavior.