Request-bound SQLx transactions for axum

Overview

axum-sqlx-rx

Request-bound SQLx transactions for axum.

Summary

axum-sqlx-rx provides an axum extractor for obtaining a request-bound transaction. The transaction begins the first time the extractor is used, and is stored with the request for use by other middleware/handlers. The transaction is resolved depending on the status code of the response – successful (2XX) responses will commit the transaction, otherwise it will be rolled back.

See the crate documentation for more information and examples.

Comments
  • trait bound `Postgres: sqlx_core::database::Database` is not satisfied

    trait bound `Postgres: sqlx_core::database::Database` is not satisfied

    When running this repo, I get the following error:

    error[E0277]: the trait bound `Postgres: sqlx_core::database::Database` is not satisfied
      --> src/main.rs:51:13
       |
    51 |     mut tx: Tx<Postgres>,
       |             ^^^^^^^^^^^^ the trait `sqlx_core::database::Database` is not implemented for `Postgres`
       |
       = help: the trait `sqlx_core::database::Database` is implemented for `sqlx_core::postgres::database::Postgres`
    note: required by a bound in `Tx`
      --> /home/nyx/.cargo/registry/src/github.com-1ecc6299db9ec823/axum-sqlx-tx-0.3.0/src/tx.rs:75:19
       |
    75 | pub struct Tx<DB: sqlx::Database, E = Error>(Lease<sqlx::Transaction<'static, DB>>, PhantomData<E>);
       |                   ^^^^^^^^^^^^^^ required by this bound in `Tx`
    

    Is this a bug or something I can solve myself? If the latter, how may I do that?

    opened by PXNX 2
  • Error handling

    Error handling

    • 3d915de feat: add Error generic type to Tx

      This allows callers to choose the error type of the FromRequest implementation, as long as it implements From<Error> + IntoResponse.

    • ea12b73 refactor: move Error from tx to root

      This is in preparation for using Error in Layer.

    • 935c27e refactor!: make Service infallible

      Service's associated Error type is now Infallible, meaning it can be used with axum::Router::layer directly, without any HandleErrorLayer shenanigans.

      This was achieved by using Error to convert any sqlx::Errors on commit into a response. The downside of this is that the error message will be returned to clients, but this will be fixed subsequently.

      BREAKING CHANGE: It's no longer possible to layer axum_sqlx_tx::Layer with HandleErrorLayer, it should be layered on its own instead.

    • 8ace093 refactor: add Error generic type to Layer

      This allows callers to choose the error type that's converted to a response in the event that committing returns an error.

      To maintain backwards compatibility, and ergonomic default usage, a separate Layer::new_with_error function is needed to create a Layer with an error type other than Error.

    • f9f7b1e doc: flesh out error handling documentation

      This includes examples of using the E generic type parameter to control how errors are converted to responses.

    • 0ba85c9 chore: bump version

    opened by connec 0
  • Docs

    Docs

    • e241e9e doc: flesh out the documentation

      All types are now well covered for prose, and there are a few more examples in the docs. Additionally, a full example has been added.

    • 7f9bd79 chore: bump version

    • ce810c1 ci: add cargo doc check to CI

    opened by connec 0
  • Release workflow

    Release workflow

    • be0673a ci: add a simple release workflow

      Currently this just invokes cargo publish when a semver tag is pushed to the repo. Ideally there should be some extra verification and/or automation around the version number, but this gets it off my laptop for now.

    opened by connec 0
  • Mutex

    Mutex

    • 8afc9e9 refactor: use an Arc<Mutex<Option<_>>> for slot

      This should be a bit smaller and more efficient than the oneshot shenanigans since oneshot itself uses an Arc and several locks internally.

    • 27f5022 chore: use futures-core rather than futures

      Now that we don't need futures::channel::oneshot we can get away with only futures-core.

    • e5f9710 chore: add .sublime-project

      Since we need some features to be enabled for rust-analyzer to run properly, it makes sense to put them in a project-specific configuration.

    • 353d6b9 chore: bump version

    opened by connec 0
  • Upgrade axum to v0.6

    Upgrade axum to v0.6

    • Upgraded axum to v0.6
    • Implemented FromRequestParts for Tx instead of FromRequestParts so that it won't consume the request body
    • Implemented Clone for axum_sqlx_tx::Layer as it is needed by axum layer
    • Since Error type can't be cloned, removed it from the axum_sqlx_tx::Layer.
    opened by kavin-kr 1
  • Treat both 2XX and 3XX responses as successful.

    Treat both 2XX and 3XX responses as successful.

    The 303 See Other response is often used to direct clients to another page after successfully creating a new resource, and such behavior is encouraged by web standards.

    Thanks for this module, it's very useful. I'm using it to develop a web application.

    opened by alexmingoia 1
Releases(0.4.0)
  • 0.4.0(Sep 20, 2022)

    What's Changed

    • fix: update sqlx to 0.6 by @greizgh in https://github.com/wasdacraic/axum-sqlx-tx/pull/11
    • chore: bump version by @connec in https://github.com/wasdacraic/axum-sqlx-tx/pull/12

    New Contributors

    • @greizgh made their first contribution in https://github.com/wasdacraic/axum-sqlx-tx/pull/11

    Full Changelog: https://github.com/wasdacraic/axum-sqlx-tx/compare/0.3.0...0.4.0

    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Apr 3, 2022)

    What's Changed

    • Upgrade axum by @connec in https://github.com/wasdacraic/axum-sqlx-tx/pull/9

    Full Changelog: https://github.com/wasdacraic/axum-sqlx-tx/compare/0.2.0...0.3.0

    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Mar 4, 2022)

    What's Changed

    • Error handling by @connec in https://github.com/wasdacraic/axum-sqlx-tx/pull/8

    Full Changelog: https://github.com/wasdacraic/axum-sqlx-tx/compare/0.1.2...0.2.0

    Source code(tar.gz)
    Source code(zip)
Owner
wasdacraic
wasdacraic
serde support for http crate types Request, Response, Uri, StatusCode, HeaderMap

serde extensions for the http crate types Allows serializing and deserializing the following types from http: Response Request HeaderMap StatusCode Ur

Andrew Toth 3 Nov 1, 2023
Better error messages for axum framework.

axum-debug This is a debugging crate that provides better error messages for axum framework. axum is a great framework for developing web applications

Eray Karatay 3 Feb 3, 2022
Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps.

rust-yew-axum-tauri-desktop template Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps. Crates frontend: Yew frontend app for de

Jet Li 54 Dec 23, 2022
Middlewares and tools to integrate axum + tracing + opentelemetry

axum-tracing-opentelemetry Middlewares and tools to integrate axum + tracing + opentelemetry. Read OpenTelemetry header from incoming request Start a

David Bernard 31 Jan 4, 2023
A proxy implement with http / socks5 in-bound and vmess out-bound, written in Rust and tokio.rs

tokio-vmess an Asynchronous proxy implement with http / socks5 in-bound and vmess out-bound, written in Rust and tokio Run example first, Fill out the

irumeria 7 Oct 3, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
Rust Axum+SQLx Sample

rust-axum-sqlx-sample Install git clone https://github.com/web3ten0/rust-axum-sqlx-1.git cd rust-axum-sqlx-1/local docker-compose up -d sh scripts/exe

web3ten0 5 Jul 9, 2022
Simple example of axum, sqlx with sqlite and utoipa (swagger) - without auth

axum_crud_api Simple example to learn creating CRUD rest apis in Rust with axum, sqlx with sqlite and utoipa (swagger) - without auth Also shows how t

null 2 Nov 12, 2022
This is a solana lite rpc which optimizes sending transactions and confirming transactions strategies.

Solana Lite RPC This project aims to create a lite rpc server which is responsible only for sending and confirming the transactions. The lite-rpc serv

Blockworks Foundation 7 Dec 24, 2022
HTTP microservice using Axum and Reqwest to request the Google Translate TTS endpoint without rate limits

HTTP microservice using Axum and Reqwest to request the Google Translate TTS endpoint without rate limits

Gnome! 5 Oct 5, 2022
Htmx extractors and request guards for axum.

axum-htmx axum-htmx is a small extension library providing extractors and request guards for the various htmx headers within axum. Additionally, the l

Rob 5 Aug 14, 2023
Stretto is a Rust implementation for ristretto. A high performance memory-bound Rust cache.

Stretto is a Rust implementation for ristretto. A high performance memory-bound Rust cache.

Al Liu 310 Dec 29, 2022
Gomez - A pure Rust framework and implementation of (derivative-free) methods for solving nonlinear (bound-constrained) systems of equations

Gomez A pure Rust framework and implementation of (derivative-free) methods for solving nonlinear (bound-constrained) systems of equations. Warning: T

Datamole 19 Dec 24, 2022
🍹Branch and bound solution using Rust to calculate an optimal cocktail ingredient list of arbitrary length 🍸

Calculating an Optimal Cocktail Ingredient List Tom Explains the Problem You have 100 different ingredients You have 20 cocktails, each of which use 2

Stephan Hügel 7 Jan 9, 2023
axum-server is a hyper server implementation designed to be used with axum framework.

axum-server axum-server is a hyper server implementation designed to be used with axum framework. Features Conveniently bind to any number of addresse

null 79 Jan 4, 2023
axum-serde is a library that provides multiple serde-based extractors and responders for the Axum web framework.

axum-serde ?? Overview axum-serde is a library that provides multiple serde-based extractors / responses for the Axum web framework. It also offers a

GengTeng 3 Dec 12, 2023
A job queue built on sqlx and PostgreSQL.

sqlxmq A job queue built on sqlx and PostgreSQL. This library allows a CRUD application to run background jobs without complicating its deployment. Th

Diggory Blake 85 Jan 5, 2023
pgvector support for Rust Supports Rust-Postgres, SQLx, and Diesel

pgvector-rust pgvector support for Rust Supports Rust-Postgres, SQLx, and Diesel Getting Started Follow the instructions for your database library: Ru

Andrew Kane 14 Nov 23, 2022
A newsletter with actix-web and sqlx-postgres

Newsletter backend Health check: production Pre-requisites You'll need to install: Rust Docker There are also some OS-specific requirements. Windows c

Nadeem Bhati 4 Dec 10, 2022
A simple tool to test sqlx with postgres. It will automatically create a database and drop it after the test.

sqlx-db-tester This a tool to test sqlx with postgres. It only supports tokio runtime at this moment. How to use it You should first create a TestDb d

Tyr Chen 4 Nov 29, 2022