Skip to content

Commit

Permalink
fix(docs): example code for sqlx::test
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkoooo authored and abonander committed Mar 2, 2023
1 parent 1fb1945 commit 291e79a
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/macros/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ To limit disk space usage, any previously created test databases will be deleted
```rust,no_run
# #[cfg(all(feature = "migrate", feature = "postgres"))]
# mod example {
use sqlx::PgPool;
use sqlx::{PgPool, Row};
#[sqlx::test]
async fn basic_test(pool: PgPool) -> sqlx::Result<()> {
let mut conn = pool.acquire().await?;
sqlx::query("SELECT * FROM foo")
let foo = sqlx::query("SELECT * FROM foo")
.fetch_one(&mut conn)
.await?;
assert_eq!(foo.get::<String>("bar"), "foobar!");
assert_eq!(foo.get::<String, _>("bar"), "foobar!");
Ok(())
}
Expand All @@ -96,17 +96,17 @@ supported):
```rust,ignore
# #[cfg(all(feature = "migrate", feature = "postgres"))]
# mod example {
use sqlx::PgPool;
use sqlx::{PgPool, Row};
#[sqlx::test(migrations = "foo_migrations")]
async fn basic_test(pool: PgPool) -> sqlx::Result<()> {
let mut conn = pool.acquire().await?;
sqlx::query("SELECT * FROM foo")
let foo = sqlx::query("SELECT * FROM foo")
.fetch_one(&mut conn)
.await?;
assert_eq!(foo.get::<String>("bar"), "foobar!");
assert_eq!(foo.get::<String, _>("bar"), "foobar!");
Ok(())
}
Expand All @@ -124,7 +124,7 @@ pub static MIGRATOR: sqlx::migrate::Migrator = sqlx::migrate!("foo_migrations");
```rust,no_run
# #[cfg(all(feature = "migrate", feature = "postgres"))]
# mod example {
use sqlx::PgPool;
use sqlx::{PgPool, Row};
# // This is standing in for the main crate since doc examples don't support multiple crates.
# mod foo_crate {
Expand All @@ -141,11 +141,11 @@ use sqlx::PgPool;
async fn basic_test(pool: PgPool) -> sqlx::Result<()> {
let mut conn = pool.acquire().await?;
sqlx::query("SELECT * FROM foo")
let foo = sqlx::query("SELECT * FROM foo")
.fetch_one(&mut conn)
.await?;
assert_eq!(foo.get::<String>("bar"), "foobar!");
assert_eq!(foo.get::<String, _>("bar"), "foobar!");
Ok(())
}
Expand All @@ -157,19 +157,19 @@ Or disable migrations processing entirely:
```rust,no_run
# #[cfg(all(feature = "migrate", feature = "postgres"))]
# mod example {
use sqlx::PgPool;
use sqlx::{PgPool, Row};
#[sqlx::test(migrations = false)]
async fn basic_test(pool: PgPool) -> sqlx::Result<()> {
let mut conn = pool.acquire().await?;
conn.execute("CREATE TABLE foo(bar text)").await?;
sqlx::query("SELECT * FROM foo")
let foo = sqlx::query("SELECT * FROM foo")
.fetch_one(&mut conn)
.await?;
assert_eq!(foo.get::<String>("bar"), "foobar!");
assert_eq!(foo.get::<String, _>("bar"), "foobar!");
Ok(())
}
Expand Down

0 comments on commit 291e79a

Please sign in to comment.