Skip to content

Type projection and partial RETURNING result shapes #54

Description

@alexeichhorn

Context

This is a lower-priority architectural limitation.

Problem

Projection expressions are not connected to the result model's field types:

#[derive(dbkit::sqlx::FromRow)]
struct ResultRow {
    note: String,
}

let rows: Vec<ResultRow> = NullableRow::query()
    .select_only()
    .column_as(NullableRow::note, "note") // Option<String>
    .into_model()
    .all(&db)
    .await?;

This compiles and fails only if SQLx decodes a NULL value.

Partial mutation results have a related problem. Insert<FullModel> and Update<FullModel> retain Out = FullModel after .returning(vec![...]), even if only one column is returned. Executing the query then attempts to decode a partial row as the complete model.

Desired direction

  • Make selected/returned result shapes explicit in the type system where practical.
  • At minimum, partial RETURNING should not continue to claim that it returns the full model.
  • If arbitrary projections remain an explicit SQLx decoding boundary, make that boundary clear in the API and documentation.
  • Preserve an ergonomic escape hatch for custom FromRow projection types.

The implementation direction needs design work; this issue tracks the contract rather than prescribing a large type-level query builder.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions