Skip to content

Commit 5c6623d

Browse files
authored
fix: fix example code of query_as (#3558)
query_as.rs: 230 mismatched bracket. query_as.rs: 230 move TIMESTAMP to TIMESTAMPTZ to match type time::OffsetDateTime. query_as.rs: 241, 251, 260 move i64 to i32 to match postgres type `INT4`.
1 parent e3ef8ba commit 5c6623d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sqlx-core/src/query_as.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ where
227227
/// let mut conn: PgConnection = PgConnection::connect("<Database URL>").await?;
228228
///
229229
/// sqlx::raw_sql(
230-
/// "CREATE TABLE users(id INTEGER PRIMARY KEY, username TEXT UNIQUE, created_at TIMESTAMP DEFAULT (now())"
230+
/// "CREATE TABLE users(id INTEGER PRIMARY KEY, username TEXT UNIQUE, created_at TIMESTAMPTZ DEFAULT (now()))"
231231
/// )
232232
/// .execute(&mut conn)
233233
/// .await?;
@@ -238,7 +238,7 @@ where
238238
///
239239
/// // Get the first row of the result (note the `LIMIT 1` for efficiency)
240240
/// // This assumes the `time` feature of SQLx is enabled.
241-
/// let oldest_user: (i64, String, time::OffsetDateTime) = sqlx::query_as(
241+
/// let oldest_user: (i32, String, time::OffsetDateTime) = sqlx::query_as(
242242
/// "SELECT id, username, created_at FROM users ORDER BY created_at LIMIT 1"
243243
/// )
244244
/// .fetch_one(&mut conn)
@@ -248,7 +248,7 @@ where
248248
/// assert_eq!(oldest_user.1, "alice");
249249
///
250250
/// // Get at most one row
251-
/// let maybe_charlie: Option<(i64, String, time::OffsetDateTime)> = sqlx::query_as(
251+
/// let maybe_charlie: Option<(i32, String, time::OffsetDateTime)> = sqlx::query_as(
252252
/// "SELECT id, username, created_at FROM users WHERE username = 'charlie'"
253253
/// )
254254
/// .fetch_optional(&mut conn)
@@ -257,7 +257,7 @@ where
257257
/// assert_eq!(maybe_charlie, None);
258258
///
259259
/// // Get all rows in result (Beware of the size of the result set! Consider using `LIMIT`)
260-
/// let users: Vec<(i64, String, time::OffsetDateTime)> = sqlx::query_as(
260+
/// let users: Vec<(i32, String, time::OffsetDateTime)> = sqlx::query_as(
261261
/// "SELECT id, username, created_at FROM users ORDER BY id"
262262
/// )
263263
/// .fetch_all(&mut conn)

0 commit comments

Comments
 (0)