Skip to content

Commit

Permalink
fix sqlx offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
olback committed Aug 22, 2023
1 parent 0432163 commit 2733043
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 85 deletions.
1 change: 1 addition & 0 deletions examples/databases/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.db

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 0 additions & 81 deletions examples/databases/sqlx-data.json

This file was deleted.

8 changes: 4 additions & 4 deletions examples/databases/src/sqlx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Post {
async fn create(mut db: Connection<Db>, post: Json<Post>) -> Result<Created<Json<Post>>> {
// There is no support for `RETURNING`.
sqlx::query!("INSERT INTO posts (title, text) VALUES (?, ?)", post.title, post.text)
.execute(&mut *db)
.execute(&mut **db)
.await?;

Ok(Created::new("/").body(post))
Expand All @@ -35,7 +35,7 @@ async fn create(mut db: Connection<Db>, post: Json<Post>) -> Result<Created<Json
#[get("/")]
async fn list(mut db: Connection<Db>) -> Result<Json<Vec<i64>>> {
let ids = sqlx::query!("SELECT id FROM posts")
.fetch(&mut *db)
.fetch(&mut **db)
.map_ok(|record| record.id)
.try_collect::<Vec<_>>()
.await?;
Expand All @@ -55,15 +55,15 @@ async fn read(mut db: Connection<Db>, id: i64) -> Option<Json<Post>> {
#[delete("/<id>")]
async fn delete(mut db: Connection<Db>, id: i64) -> Result<Option<()>> {
let result = sqlx::query!("DELETE FROM posts WHERE id = ?", id)
.execute(&mut *db)
.execute(&mut **db)
.await?;

Ok((result.rows_affected() == 1).then(|| ()))
}

#[delete("/")]
async fn destroy(mut db: Connection<Db>) -> Result<()> {
sqlx::query!("DELETE FROM posts").execute(&mut *db).await?;
sqlx::query!("DELETE FROM posts").execute(&mut **db).await?;

Ok(())
}
Expand Down

0 comments on commit 2733043

Please sign in to comment.