Fix remaining issues from bug report
- Rename static-validation to static-check - Fix upsert_stmt undefined when no database feature enabled - Fix bind_all_values lifetime to use explicit 'q instead of '_ Decimal support requires enabling the 'decimal' feature flag. Manual UpdateForm implementations need to add _exprs field. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
0913091b67
commit
3815913821
|
|
@ -5,7 +5,7 @@ edition.workspace = true
|
|||
description = "Entity CRUD and change tracking for SQL databases with SQLx"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.3.4"
|
||||
version = "0.3.5"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
@ -28,7 +28,7 @@ members = [
|
|||
[features]
|
||||
default = []
|
||||
derive = ["dep:sqlx-record-derive"]
|
||||
static-validation = ["sqlx-record-derive?/static-validation"]
|
||||
static-check = ["sqlx-record-derive?/static-check"]
|
||||
decimal = ["dep:rust_decimal", "sqlx/rust_decimal"]
|
||||
|
||||
# Database backends - user must enable at least one
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ futures = "0.3"
|
|||
|
||||
[features]
|
||||
default = []
|
||||
static-validation = []
|
||||
static-check = []
|
||||
mysql = []
|
||||
postgres = []
|
||||
sqlite = []
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ fn table_quote() -> &'static str {
|
|||
{ "`" }
|
||||
}
|
||||
|
||||
/// Get compile-time placeholder for static-validation SQL
|
||||
/// Get compile-time placeholder for static-check SQL
|
||||
fn static_placeholder(index: usize) -> String {
|
||||
#[cfg(feature = "postgres")]
|
||||
{ format!("${}", index) }
|
||||
|
|
@ -414,6 +414,22 @@ fn generate_insert_impl(
|
|||
)
|
||||
};
|
||||
|
||||
#[cfg(not(any(feature = "mysql", feature = "postgres", feature = "sqlite")))]
|
||||
let upsert_stmt = {
|
||||
// Fallback to MySQL syntax
|
||||
let update_clause = non_pk_fields.iter()
|
||||
.map(|f| format!("{} = VALUES({})", f, f))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
format!(
|
||||
"INSERT INTO {}{}{} ({}) VALUES ({}) ON DUPLICATE KEY UPDATE {}",
|
||||
#tq, #table_name, #tq,
|
||||
vec![#(#db_names),*].join(", "),
|
||||
placeholders,
|
||||
update_clause
|
||||
)
|
||||
};
|
||||
|
||||
sqlx::query(&upsert_stmt)
|
||||
#(.bind(#bindings))*
|
||||
.execute(executor)
|
||||
|
|
@ -573,8 +589,8 @@ fn generate_get_impl(
|
|||
|
||||
let field_list = fields.iter().map(|f| f.db_name.clone()).collect::<Vec<_>>();
|
||||
|
||||
// Check if static-validation feature is enabled at macro expansion time
|
||||
let use_static_validation = cfg!(feature = "static-validation");
|
||||
// Check if static-check feature is enabled at macro expansion time
|
||||
let use_static_validation = cfg!(feature = "static-check");
|
||||
|
||||
let get_by_impl = if use_static_validation {
|
||||
// Static validation: use sqlx::query_as! with compile-time checked SQL
|
||||
|
|
@ -1169,8 +1185,8 @@ fn generate_update_impl(
|
|||
|
||||
/// Bind all form values to query in correct order.
|
||||
/// Handles both simple values and expression values, respecting expression precedence.
|
||||
pub fn bind_all_values(&self, mut query: sqlx::query::Query<'_, #db, #db_args>)
|
||||
-> sqlx::query::Query<'_, #db, #db_args>
|
||||
pub fn bind_all_values<'q>(&'q self, mut query: sqlx::query::Query<'q, #db, #db_args>)
|
||||
-> sqlx::query::Query<'q, #db, #db_args>
|
||||
{
|
||||
#(
|
||||
// Expression takes precedence over simple value
|
||||
|
|
|
|||
Loading…
Reference in New Issue