Skip to content

Commit

Permalink
fix: fix example code of query_as (#3558)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
xuehaonan27 authored Nov 27, 2024
1 parent e3ef8ba commit 5c6623d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sqlx-core/src/query_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ where
/// let mut conn: PgConnection = PgConnection::connect("<Database URL>").await?;
///
/// sqlx::raw_sql(
/// "CREATE TABLE users(id INTEGER PRIMARY KEY, username TEXT UNIQUE, created_at TIMESTAMP DEFAULT (now())"
/// "CREATE TABLE users(id INTEGER PRIMARY KEY, username TEXT UNIQUE, created_at TIMESTAMPTZ DEFAULT (now()))"
/// )
/// .execute(&mut conn)
/// .await?;
Expand All @@ -238,7 +238,7 @@ where
///
/// // Get the first row of the result (note the `LIMIT 1` for efficiency)
/// // This assumes the `time` feature of SQLx is enabled.
/// let oldest_user: (i64, String, time::OffsetDateTime) = sqlx::query_as(
/// let oldest_user: (i32, String, time::OffsetDateTime) = sqlx::query_as(
/// "SELECT id, username, created_at FROM users ORDER BY created_at LIMIT 1"
/// )
/// .fetch_one(&mut conn)
Expand All @@ -248,7 +248,7 @@ where
/// assert_eq!(oldest_user.1, "alice");
///
/// // Get at most one row
/// let maybe_charlie: Option<(i64, String, time::OffsetDateTime)> = sqlx::query_as(
/// let maybe_charlie: Option<(i32, String, time::OffsetDateTime)> = sqlx::query_as(
/// "SELECT id, username, created_at FROM users WHERE username = 'charlie'"
/// )
/// .fetch_optional(&mut conn)
Expand All @@ -257,7 +257,7 @@ where
/// assert_eq!(maybe_charlie, None);
///
/// // Get all rows in result (Beware of the size of the result set! Consider using `LIMIT`)
/// let users: Vec<(i64, String, time::OffsetDateTime)> = sqlx::query_as(
/// let users: Vec<(i32, String, time::OffsetDateTime)> = sqlx::query_as(
/// "SELECT id, username, created_at FROM users ORDER BY id"
/// )
/// .fetch_all(&mut conn)
Expand Down

0 comments on commit 5c6623d

Please sign in to comment.