@@ -104,7 +104,7 @@ pub use json::{Json, JsonRawValue, JsonValue};
104
104
///
105
105
/// ### Transparent
106
106
///
107
- /// Rust-only domain or wrappers around SQL types. The generated implementations directly delegate
107
+ /// Rust-only domain wrappers around SQL types. The generated implementations directly delegate
108
108
/// to the implementation of the inner type.
109
109
///
110
110
/// ```rust,ignore
@@ -113,6 +113,35 @@ pub use json::{Json, JsonRawValue, JsonValue};
113
113
/// struct UserId(i64);
114
114
/// ```
115
115
///
116
+ /// ##### Note: `PgHasArrayType`
117
+ /// If you have the `postgres` feature enabled, this derive also generates a `PgHasArrayType` impl
118
+ /// so that you may use it with `Vec` and other types that decode from an array in Postgres:
119
+ ///
120
+ /// ```rust,ignore
121
+ /// let user_ids: Vec<UserId> = sqlx::query_scalar("select '{ 123, 456 }'::int8[]")
122
+ /// .fetch(&mut pg_connection)
123
+ /// .await?;
124
+ /// ```
125
+ ///
126
+ /// However, if you are wrapping a type that does not implement `PgHasArrayType`
127
+ /// (e.g. `Vec` itself, because we don't currently support multidimensional arrays),
128
+ /// you may receive an error:
129
+ ///
130
+ /// ```rust,ignore
131
+ /// #[derive(sqlx::Type)] // ERROR: `Vec<i64>` does not implement `PgHasArrayType`
132
+ /// #[sqlx(transparent)]
133
+ /// struct UserIds(Vec<i64>);
134
+ /// ```
135
+ ///
136
+ /// To remedy this, add `#[sqlx(no_pg_array)]`, which disables the generation
137
+ /// of the `PgHasArrayType` impl:
138
+ ///
139
+ /// ```rust,ignore
140
+ /// #[derive(sqlx::Type)]
141
+ /// #[sqlx(transparent, no_pg_array)]
142
+ /// struct UserIds(Vec<i64>);
143
+ /// ```
144
+ ///
116
145
/// ##### Attributes
117
146
///
118
147
/// * `#[sqlx(type_name = "<SQL type name>")]` on struct definition: instead of inferring the SQL
@@ -121,6 +150,7 @@ pub use json::{Json, JsonRawValue, JsonValue};
121
150
/// given type is different than that of the inferred type (e.g. if you rename the above to
122
151
/// `VARCHAR`). Affects Postgres only.
123
152
/// * `#[sqlx(rename_all = "<strategy>")]` on struct definition: See [`derive docs in FromRow`](crate::from_row::FromRow#rename_all)
153
+ /// * `#[sqlx(no_pg_array)]`: do not emit a `PgHasArrayType` impl (see above).
124
154
///
125
155
/// ### Enumeration
126
156
///
0 commit comments