What does HackerNews think of rust-postgres?

Native PostgreSQL driver for the Rust programming language

Language: Rust

The Materialize team manage a fork of https://github.com/sfackler/rust-postgres with the changes required to consume from the Postgres WAL: https://github.com/materializeInc/rust-postgres.

Here is a comment and link to some code which seems to work: https://github.com/sfackler/rust-postgres/issues/116#issueco...

I just launched a jigsaw puzzle website last week that has a backend API written in Rust and uses the postgres crate [1].

Since this is a side project for me, there wasn't much risk if it ended up being a bad decision. Multiple times throughout the project I got frustrated with the DX of existing http frameworks I tried and ended up building my own [2] on top of hyper. However, after launching my site and seeing how it performs in production, I could not be happier with the result! I had a bit of Rust experience before the project but learned a lot more through building this.

For you and others, I think it really depends on the situation. Building a Rust CRUD app will likely take longer than the other languages you're used to as the ecosystem is under heavy development, especially with async/await. So if you or your team are in a rush, I'll just echo that you should build with the tools you already know. If you have time and budget to experiment like I did, it might be worthwhile and I can promise it will be fun :)

[1]: https://github.com/sfackler/rust-postgres

[2]: https://twitter.com/jakedeichert/status/1205230350160539650

Why is

    Post::belonging_to(user).load(&connection)
an improvement over

    SELECT * FROM posts WHERE user_id = 1;
?

If you use this, it nails the database schema into your Rust code, because this needs to know the table formats. If someone adds a new field to a row, you have to rebuild all your Rust programs that use the database. Now your deployment process just got much more complicated.

It's a neat hack, but seems an overly complex way to do something that's not that complicated. Unless this has some huge performance gain over rust-postgres[1], it's probably too much.

If rust-postgres is too slow, it would be worth having an optional generic for rust-postgres to help with unmarshalling returned rows. Rust-postgres returns row objects from which fields can be extracted. Converting that to a Rust struct is the only operation which needs to go fast.

[1] https://github.com/sfackler/rust-postgres

sflacker has a library that does this for Postgres: https://github.com/sfackler/rust-postgres is the connection/query/etc part, and https://github.com/sfackler/rust-postgres-macros actually links with the postgres query parser to provide compile-time SQL syntax checking.
Not really. A lot of the infrastructure has kept changing for a while (eg, the IO facilities were recently rewritten), so code for older versions of Rust (like [1]) fall behind and do not get updated anymore.

With Chris Morgan's rust-http library (which I think is also used by Servo), you should have the base on which to build a web framework. Somebody apparently wrote (and still maintains) a pure Rust Postgresql driver ([2]), so you could in theory write a simple CRUD webapp, if you're willing to write the routing yourself.

1: https://github.com/erickt/mre

2: https://github.com/sfackler/rust-postgres