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"
|
description = "Entity CRUD and change tracking for SQL databases with SQLx"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.3.4"
|
version = "0.3.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
@ -28,7 +28,7 @@ members = [
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
derive = ["dep:sqlx-record-derive"]
|
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"]
|
decimal = ["dep:rust_decimal", "sqlx/rust_decimal"]
|
||||||
|
|
||||||
# Database backends - user must enable at least one
|
# Database backends - user must enable at least one
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ futures = "0.3"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
static-validation = []
|
static-check = []
|
||||||
mysql = []
|
mysql = []
|
||||||
postgres = []
|
postgres = []
|
||||||
sqlite = []
|
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 {
|
fn static_placeholder(index: usize) -> String {
|
||||||
#[cfg(feature = "postgres")]
|
#[cfg(feature = "postgres")]
|
||||||
{ format!("${}", index) }
|
{ 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)
|
sqlx::query(&upsert_stmt)
|
||||||
#(.bind(#bindings))*
|
#(.bind(#bindings))*
|
||||||
.execute(executor)
|
.execute(executor)
|
||||||
|
|
@ -573,8 +589,8 @@ fn generate_get_impl(
|
||||||
|
|
||||||
let field_list = fields.iter().map(|f| f.db_name.clone()).collect::<Vec<_>>();
|
let field_list = fields.iter().map(|f| f.db_name.clone()).collect::<Vec<_>>();
|
||||||
|
|
||||||
// Check if static-validation feature is enabled at macro expansion time
|
// Check if static-check feature is enabled at macro expansion time
|
||||||
let use_static_validation = cfg!(feature = "static-validation");
|
let use_static_validation = cfg!(feature = "static-check");
|
||||||
|
|
||||||
let get_by_impl = if use_static_validation {
|
let get_by_impl = if use_static_validation {
|
||||||
// Static validation: use sqlx::query_as! with compile-time checked SQL
|
// 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.
|
/// Bind all form values to query in correct order.
|
||||||
/// Handles both simple values and expression values, respecting expression precedence.
|
/// Handles both simple values and expression values, respecting expression precedence.
|
||||||
pub fn bind_all_values(&self, mut query: 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<'_, #db, #db_args>
|
-> sqlx::query::Query<'q, #db, #db_args>
|
||||||
{
|
{
|
||||||
#(
|
#(
|
||||||
// Expression takes precedence over simple value
|
// Expression takes precedence over simple value
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue