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`.
This commit is contained in:
XueHaonan 2024-11-28 05:51:52 +08:00 committed by GitHub
parent e3ef8baf23
commit 5c6623dee2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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?;
@ -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)
@ -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)
@ -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)