rust-postgres VS sqlx

Compare rust-postgres vs sqlx and see what are their differences.

rust-postgres

Native PostgreSQL driver for the Rust programming language (by sfackler)

sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite. (by launchbadge)
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
rust-postgres sqlx
14 149
3,530 13,614
- 1.8%
8.4 9.4
3 months ago 11 days ago
Rust Rust
Apache License 2.0 Apache License 2.0
The number of mentions indicates the total number of mentions that we've tracked plus the number of user suggested alternatives.
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.

rust-postgres

Posts with mentions or reviews of rust-postgres. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2023-03-18.
  • PostgreSQL Logical Replication Explained
    4 projects | news.ycombinator.com | 18 Mar 2023
    For C there should be good options.

    For Rust it doesn't appear that well-supported.

    A very simple approach is to poll for changes using `pg_logical_slot_get_changes()` - that should work with any driver. That's what I used for my initial experimentation, before switching over to the streaming replication protocol for better performance.

    The streaming replication protocol is not that complicated, but currently you'll have to handle some of the low-level protocol yourself, or work with some very experimental implementations. There's a project to help get you started at [1], and some more discussion at [2].

    For the logical decoder, wal2json is quite nice to experiment with, but I've found pgoutput is not that complicated and gives you something closer to the raw data.

    [1]: https://github.com/seddonm1/logicaldecoding/

    [2]: https://github.com/sfackler/rust-postgres/issues/116

  • Push-Based Outbox Pattern with Postgres Logical Replication
    6 projects | news.ycombinator.com | 28 Oct 2022
  • Rust async IS broken
    1 project | /r/rust | 16 Jun 2022
    This is a bit of a rant so please bear with me. I wrote a small utility program a long time ago that used this version of the postgres crate
  • Cómo usar gRPC con Rust Tonic y Postgres con ejemplos
    2 projects | dev.to | 11 Jun 2022
    En este post aprendermos a usar Rust, Tonic y la crate gRPC, y implementaremos un CRUD con Postgresql database.
  • Reviews of the Diesel ORM, are there better alternatives?
    11 projects | /r/rust | 15 May 2022
    I can understand that this can be frustrating and I know that the situation there is not ideal for diesel. There are certainly things to improve there by either providing a bundling support which builds the native library as part of the normal build process or by implementing a pure rust connection implementation. Both is possible with diesel, but requires some work. At least the pure rust connection implementation is something that can be provided by a third party crate now with upcoming diesel 2.0 release. If you are interested in that checkout this and this issue. As for the bundling support: This requires changes in the mysqlclient-sys and pq-sys crates. Again help there is welcome. In the end it makes me sad that some people have repeating decided that a solution to this problem is to write just another crate instead of helping to fix these issues. This just results in everyone have more work to do, as there are now two non-perfect solutions instead of having one slightly improved solution.
  • GitHub - tzConnectBerlin/rust-pg_bigdecimal: A Rust native datatype for Postgres' Numeric type, to be used with Rust's "Postgres" library.
    2 projects | /r/rust | 14 Jan 2022
    We created this little library to have a fully native type for Postgres Numerics with the rust-postgres (https://github.com/sfackler/rust-postgres) library.
  • pigeon-rs: Open source email automation written in Rust
    5 projects | /r/rust | 20 Nov 2021
    The problem with a crate like postgres is that you have to define the types of the query at compile-time. And if you use the simple query protocol in postgres, you just get a bunch of strings, i.e. no proper typing at all. However, for maximal flexibility arbitrary queries should work in pigeon, without knowing the database schema.
  • Announcing Usual -- a small nORM wrapper to make dealing with SQL easier (like tokio-postgres)
    2 projects | /r/rust | 25 Aug 2021
    Some nifty things about usual: - It's a generic wrapper over any SQL "row" object. The first implementation that's provided is for tokio-postgres, but traits are available to implement over whatever you'd like. - It provides static typing for partial queries. That is, it supports fetching a subset of fields from a row and makes a unique type for the return value. This gives you some neat-o type safety like this:
  • How to use gRPC with Rust Tonic and Postgres database with examples
    3 projects | dev.to | 13 May 2021
    In this post, we will learn how to use Rust Tonic gRPC crate. We will learn how to implement CRUD with Postgresql database.
  • Hey Rustaceans! Got an easy question? Ask here (12/2021)!
    15 projects | /r/rust | 22 Mar 2021
    (see: https://github.com/sfackler/rust-postgres/blob/e15c9b1415f69821799f1370246581c1600a6196/postgres-protocol/src/types/mod.rs#L137)

sqlx

Posts with mentions or reviews of sqlx. We have used some of these posts to build our list of alternatives and similar projects. The last one was on 2024-12-07.
  • First Impressions of AWS DSQL with Lambda and Rust
    3 projects | dev.to | 7 Dec 2024
    I tend to default to as few as possible, which is why when working with SQL and Rust, I almost always reach for SQLx. Setting up SQLx with AWS DSQL requires using the v4 Signature signing of my credentials as fetched from my AWS configuration. I do this work in my main function so that I can reuse the Postgres Pool in my handler without having to establish this connection outside of the Cold Start initializing cycle. That setup is reflected in the below code.
  • Sqlc: Compile SQL to type-safe code
    15 projects | news.ycombinator.com | 8 Sep 2024
    This looks like a less ergonomic version of Rust's SQLx (https://github.com/launchbadge/sqlx) but a more robust version of TypeScript's sqlx-ts (https://jasonshin.github.io/sqlx-ts/). Sqlc seems to copy the latter's unfortunate lack of inline SQL statements. Still, seems promising.
  • Build your own SQLite with Rust, Part 1
    1 project | news.ycombinator.com | 17 Aug 2024
    SQLx seems to do some form of this. though what you're suggesting may remove the build time dependency on "connecting" to a SQLite database.

    "SQLx supports compile-time checked queries. It does not, however, do this by providing a Rust API or DSL (domain-specific language) for building queries. Instead, it provides macros that take regular SQL as input and ensure that it is valid for your database. The way this works is that SQLx connects to your development DB at compile time to have the database itself verify (and return some info on) your SQL queries."

    https://github.com/launchbadge/sqlx

  • SQLx: Async, pure Rust SQL crate, compile-time checked queries without a DSL
    1 project | news.ycombinator.com | 22 Jul 2024
  • A tale of TimescaleDB, SQLx and testing in Rust
    1 project | dev.to | 2 May 2024
    For PostgreSQL, the most relevent part of the code is here. With this in mind I changed some things around to rely on schemas instead of databases and even simplified some parts of the implementation as this was always meant to be for internal use only..
  • Rust as a general application language
    2 projects | /r/rust | 9 Dec 2023
    What exactly are you missing? I haven't really written "boring corporate backend stuff" in a few years but something like sqlx provides everything I've ever needed there.
  • Hey Rustaceans! Got a question? Ask here (49/2023)!
    9 projects | /r/rust | 5 Dec 2023
    Badges are the little rectangles you typically see at the top of a crate's README: https://github.com/launchbadge/sqlx/blob/main/README.md
  • A new F# compiler feature: graph-based type-checking
    9 projects | news.ycombinator.com | 5 Nov 2023
    SQLX has entered the chat [1].

    [1] https://github.com/launchbadge/sqlx

  • Grimoire - A recipe management application.
    7 projects | /r/rust | 5 Oct 2023
    Database : SqLite (using sqlx).
  • SQLX MSSQL Connection String Problem
    1 project | /r/rust | 6 Jul 2023
    The current (well, removed) MSSQL sqlx driver also doesn't support encrypted connections (https://github.com/launchbadge/sqlx/issues/1552), so it might work locally on an unnamed instance but not over the network until they add in the newer driver (which will be closed source but for an OSS project you should be able to request a free license I think)

What are some alternatives?

When comparing rust-postgres and sqlx you can also consider the following projects:

MeiliSearch - A lightning-fast search API that fits effortlessly into your apps, websites, and workflow

diesel - A safe, extensible ORM and Query Builder for Rust

tikv - Distributed transactional key-value database, originally created to complement TiDB

sea-orm - 🐚 An async & dynamic ORM for Rust

r2d2 - A generic connection pool for Rust

tokio - A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...

Rust Client for KairosDB   - Rust client for KairosDB

rbatis - Rust Compile Time ORM with Async Dynamic SQL

bb8 - Full-featured async (tokio-based) postgres connection pool (like r2d2)

mysql-proxy-rs - A highly scalable MySQL Proxy framework written in Rust

FrameworkBenchmarks - Source for the TechEmpower Framework Benchmarks project

rds_iamauth_proxy - Postgres proxy which allows tools that don't natively supports IAM auth to connect to AWS RDS instances.

SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured

Did you konow that Rust is
the 5th most popular programming language
based on number of metions?