Commit Graph

14 Commits

Author SHA1 Message Date
Michael Netshipise 6ed2401be1 fix: use Value-based binding in UpdateForm for proper Option<T> handling
When UpdateForm wraps fields that are already Option<T>, it creates
nested Options (Option<Option<T>>). The old bind_form_values method
bound these directly as &Option<T>, which caused MySQL "malform packet"
errors for Uuid -> BINARY(16) conversions.

Now both bind_form_values and bind_all_values use update_stmt_with_values()
which properly converts values through the Value enum:
- Some(None) -> Value::Null
- Some(Some(v)) -> Value::T(v)

This preserves the three-state semantics:
- None: don't include field in UPDATE
- Some(None): SET column = NULL
- Some(Some(v)): SET column = value

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 18:13:07 +02:00
Michael Netshipise a1464d3f7c Add update_by_filter for bulk updates by filter conditions
Usage:
  User::update_by_filter(&pool, filters![("status", "pending")], form).await?;

- Requires at least one filter to prevent accidental table-wide updates
- Returns number of affected rows
- Binds form values first, then filter values

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 20:55:10 +02:00
Michael Netshipise 3815913821 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>
2026-01-28 21:18:13 +02:00
Michael Netshipise 0913091b67 Fix static-validation to use correct database placeholders
- Add static_placeholder() function that uses $1 for postgres, ? for mysql/sqlite
- Restore static-validation feature with proper database-specific SQL
- cfg!(feature = "static-validation") now works correctly with query_as! macro

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 21:07:49 +02:00
Michael Netshipise 3c0ae1983f Fix MySQL placeholder issue and add missing Value types
- Remove broken static-validation feature (hardcoded $1 placeholders)
- Add Value::Null variant for Option<T> support
- Add From<Option<T>> impl for all Value types
- Add f32, f64, NaiveTime, serde_json::Value support
- Add optional decimal feature for rust_decimal::Decimal
- All database backends now use runtime placeholder() function

Fixes issues:
- MySQL getting PostgreSQL $1 placeholders
- Missing From<Option<T>> implementations
- Missing base types (Decimal, JsonValue, NaiveTime, floats)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 21:01:31 +02:00
Michael Netshipise ceeecf2e5c Bump version to 0.3.2
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 17:23:39 +02:00
Michael Netshipise 6c56231003 Use workspace version, add clap CLI to MCP server
- Define version in workspace.package, inherit in all crates
- Rename MCP binary from sqlx-record-expert to sqlx-record-mcp
- Add clap for --version and --help support

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 17:19:14 +02:00
Michael Netshipise 44ac78d67e Update docs, MCP server, and skills for v0.3.0 features
- Add skill docs for batch ops, pagination, soft delete, transactions
- Update sqlx-entity.md with new attributes and methods
- Update sqlx-record.md with quick reference for all features
- Update MCP server with new feature documentation resources
- Fix .gitignore paths for renamed directories

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 16:44:57 +02:00
Michael Netshipise f785bb1bf6 Release v0.3.0 with soft deletes, timestamps, batch ops, pagination, transactions
New features:
- #[soft_delete] attribute with delete/restore/hard_delete methods
- #[created_at] auto-set on insert (milliseconds timestamp)
- #[updated_at] auto-set on every update (milliseconds timestamp)
- insert_many(&pool, &[entities]) for batch inserts
- upsert(&pool) / insert_or_update(&pool) for ON CONFLICT handling
- Page<T> struct with paginate() method for pagination
- find_partial() for selecting specific columns
- transaction! macro for ergonomic transaction handling
- PageRequest struct with offset/limit helpers

Technical changes:
- Added pagination.rs and transaction.rs modules
- Extended EntityField with is_soft_delete, is_created_at, is_updated_at
- Added generate_soft_delete_impl for delete/restore/hard_delete methods
- Upsert uses ON DUPLICATE KEY UPDATE (MySQL), ON CONFLICT DO UPDATE (Postgres/SQLite)
- Index hints supported in pagination and find_partial (MySQL)

All three database backends (MySQL, PostgreSQL, SQLite) tested and working.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 16:36:24 +02:00
Michael Netshipise b1052ac271 Release v0.2.0 with UpdateExpr, ConnProvider, MCP server, and skills
New features:
- UpdateExpr: Advanced updates with column arithmetic (Add, Sub, Mul, Div, Mod),
  CASE/WHEN conditionals, AddIf/SubIf, Coalesce, Greatest, Least, and raw SQL
- ConnProvider: Flexible borrowed/owned connection management
- lookup_table! and lookup_options! macros for type-safe lookup tables
- new_uuid() for time-ordered UUIDs with better database indexing
- MCP server (sqlx-record-expert) with documentation tools and resources
- Claude Code skills for all features

Improvements:
- Fixed Postgres/SQLite unsigned integer binding (cast to signed)
- Added From implementations for all integer types to Value
- Added param_count() to Filter for expression parameter counting
- Added bind_all_values() for proper expression binding order

All three database backends (MySQL, PostgreSQL, SQLite) build and work correctly.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 16:21:14 +02:00
Michael Netshipise e89041b9c6 Enhance CLAUDE.md with comprehensive project documentation
- Added repository URL
- Documented all derive macro attributes and generated methods
- Added Filter API usage examples
- Documented database differences table
- Added Value types reference
- Added EntityChange audit trail schema
- Included important usage notes

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 15:34:07 +02:00
Michael Netshipise aba05b2b52 Rename to sqlx-record with multi-database support
- Renamed project from entity-changes to sqlx-record
- Renamed derive crate from entity-update_derive to sqlx-record-derive
- Renamed CLI tool from entity-changes-ctl to sqlx-record-ctl
- Renamed Condition to Filter (condition.rs -> filter.rs)
- Renamed condition_or/condition_and/conditions macros to filter_or/filter_and/filters
- Added multi-database support via feature flags:
  - mysql: MySQL support
  - postgres: PostgreSQL support (with $1, $2 placeholders)
  - sqlite: SQLite support
- Updated query generation for database-specific syntax:
  - Placeholder styles (? vs $1)
  - Table quoting (` vs ")
  - COUNT expressions
  - ILIKE handling
  - Version increment (IF vs CASE WHEN)
- Updated CLI tool for all three databases
- Updated documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 15:31:24 +02:00
Michael Netshipise e9079834c7 Import entity-changes project
Initial import of the entity-changes codebase as starting point for sqlx-record.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-28 15:19:38 +02:00
Michael Netshipise 92d559574e first commit 2026-01-28 15:19:28 +02:00