Skip to content

Add opt-in #[sea_orm(try_getable_array)] to DeriveValueType for Vec<T> query results#3108

Merged
tyt2y3 merged 1 commit into
masterfrom
feat/value-type-array
Jul 2, 2026
Merged

Add opt-in #[sea_orm(try_getable_array)] to DeriveValueType for Vec<T> query results#3108
tyt2y3 merged 1 commit into
masterfrom
feat/value-type-array

Conversation

@tyt2y3

@tyt2y3 tyt2y3 commented Jul 2, 2026

Copy link
Copy Markdown
Member

Closes #2967. Supersedes #2972.

Problem

DeriveValueType wrappers (e.g. struct GoodId(i32)) don't implement TryGetableArray, so they can't be used as Vec<GoodId> in FromQueryResult structs (Postgres arrays):

the trait bound `Vec<GoodId>: TryGetable` is not satisfied

Approach — opt-in, non-disruptive

Per the discussion on #2972, this is opt-in rather than automatic, so default behaviour is unchanged and there's no risk to existing wrappers (including nested Vec<Vec<T>> cases):

#[derive(DeriveValueType)]
#[sea_orm(try_getable_array)]
pub struct GoodId(i32);

#[derive(FromQueryResult)]
struct Row { ids: Vec<GoodId> }   // now works
  • New #[sea_orm(try_getable_array)] flag generates impl TryGetableArray for GoodId, delegating to the inner type's Vec support — so it only compiles when Vec<inner>: TryGetable. Named to match the existing try_from_u64 opt-in flag (both name the trait they generate), and to avoid confusion with array_type.
  • Gated on the postgres-array feature (like the existing NotU8 impl).
  • Verified to compile under postgres-array + with-json (no trait-coherence conflict with the JSON TryGetableArray blanket).

Test

Postgres round-trip in value_type_tests: reads SELECT ARRAY[1,2,3]::int4[] into Vec<GoodId> via FromQueryResult.

Note: sea-orm-sync regenerates from this at release time.

…> query results

Closes #2967. Supersedes #2972.

DeriveValueType wrappers can opt in to a generated TryGetableArray impl so
Vec<Wrapper> is readable from a SQL array column in FromQueryResult structs.
Opt-in and non-disruptive: default behaviour unchanged; the impl delegates to
the inner type's Vec support under the postgres-array feature. Includes a
Postgres round-trip test reading an int[] column into Vec<GoodId>.
@tyt2y3 tyt2y3 force-pushed the feat/value-type-array branch from 0d91654 to 869c8f0 Compare July 2, 2026 11:15
@tyt2y3 tyt2y3 changed the title Add opt-in #[sea_orm(array)] to DeriveValueType for Vec<T> query results Add opt-in #[sea_orm(try_getable_array)] to DeriveValueType for Vec<T> query results Jul 2, 2026
@tyt2y3 tyt2y3 merged commit 5f7eb09 into master Jul 2, 2026
39 checks passed
@tyt2y3 tyt2y3 deleted the feat/value-type-array branch July 2, 2026 12:15
pull Bot pushed a commit to langyo/sea-orm that referenced this pull request Jul 3, 2026
…rm-sync

The mock.rs test module imported `futures_util::TryStreamExt` unconditionally,
but the sync variant has no futures_util dependency (it uses `StreamShim::try_next`
instead, already gated on `feature = "sync"`). A full make-sync regen therefore
didn't compile its lib unit tests. Gate the import on `not(feature = "sync")` to
match the StreamShim pattern.

Also regenerate sea-orm-sync to catch up with recently-merged changes (SeaQL#2940 docs,
SeaQL#3106 sync warning, SeaQL#3108 try_getable_array, non_exhaustive).
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.

DeriveEntityModel types don't implement TryGetable trait when wrapped in a Vec

1 participant