Skip to content

Add sqlx flatten support#43

Open
Vestibule wants to merge 2 commits intohelsing-ai:mainfrom
Vestibule:main
Open

Add sqlx flatten support#43
Vestibule wants to merge 2 commits intohelsing-ai:mainfrom
Vestibule:main

Conversation

@Vestibule
Copy link
Copy Markdown

@Vestibule Vestibule commented Jan 27, 2026

Summary

  • add flatten column expansion + bindings for CRUD
  • add FlattenFields derive + Option support
  • add flatten tests (no prefix/auto/custom)
  • add docs for flatten usage

Testing

  • cargo test -p atmosphere --features postgres --test integration -- flatten

Implementation choices

  • Static expansion: flatten columns are generated at compile time (no runtime reflection).
  • FlattenedColumn: concrete SQL column representation for nested fields, used by SQL generation + Bind.
  • bind_field_optional: clean Option support (binds NULL when the nested value is absent).
  • SELECT aliasing: contact_email AS email so sqlx::FromRow can rebuild the nested struct without prefix
    knowledge.
  • Compile-time validation: assert_unique_table_columns::() checks name collisions including prefixed
    flatten columns.
  • Direct recursion guard: blocks obvious self-recursive flatten types (including Option).
  • sqlx compatibility: injects #[sqlx(flatten)] for FromRow.

Architecture

Resolves #42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add support for sqlx(flatten):

1 participant