Diesel: Use SQLx (https://github.com/launchbadge/sqlx) under the hood or allow support as conditional feature

Created on 10 Sep 2020  路  1Comment  路  Source: diesel-rs/diesel

Hi, I would like to thank you all of the contributors for this amazing library

Please I am a very beginner in rust and diesel so apologies if I am suggesting something that architecturally not possible etc.. (I don't have that much knowledge of diesel internals)

What I am suggesting?
Diesel should use SQLx (https://github.com/launchbadge/sqlx) under the hood or add support as a feature

Why Should we add SQLx ?

  1. Pure Rust - The Postgres and MySQL/MariaDB drivers are written in pure Rust using zero unsafe code
  2. Truly Asynchronous - Built from the ground-up using async/await for maximum concurrency (This will solve https://github.com/diesel-rs/diesel/issues/399)
  3. Database Agnostic - Support for PostgreSQL, MySQL, SQLite, and MSSQL.
  4. Type-safe SQL - macro to check your SQL and bind parameters at compile time.
  5. Runtime Agnostic - Works on async-std or tokio with the runtime-async-std or runtime-tokio cargo feature flag.
  6. and many more, please take a look at README(https://github.com/launchbadge/sqlx/blob/master/README.md)

SQLx does not have DSL and Diesel has one of the best DSL so it would be a good fit for using it

Most helpful comment

Just to clarify a few things:

  1. Pure Rust - The Postgres and MySQL/MariaDB drivers are written in pure Rust using zero unsafe code

While it's true that those drivers are pure rust with zero unsafe code, they do not handle all the edge cases in the underlying database protocols. Also at least their MySQL` driver is for a factor of 2-5 slower than that one provided by mysqlclient.
Migrating to some pure rust driver is definitely something that would be interesting for diesel, but such a driver should be similar mature than the existing C-drivers provided by the database itself.

  1. Truly Asynchronous - Built from the ground-up using async/await for maximum concurrency (This will solve #399)

You can certainly explain how to solve the problems outlined in this comment. Otherwise please get fluent in rust first before you start to suggest fundementally changing the implementation of a big crate.

  1. Database Agnostic - Support for PostgreSQL, MySQL, SQLite, and MSSQL.

Diesel is already database agnostic, even more than SQLx. It is possible to add support for other database backends as third party crate. See diesel-oci as an example.

  1. Type-safe SQL - macro to check your SQL and bind parameters at compile time.

This point is the most arguable. In my opinion diesel is already more type safe than sqlx because it correctly handles LEFT JOINS for example. (SQLx does not infer columns coming for a LEFT JOIN as nullable for example.)

  1. Runtime Agnostic - Works on async-std or tokio with the runtime-async-std or runtime-tokio cargo feature flag.

Technically that's not "Runtime Agnostic". That's just: We support more than one concrete runtime. Runtime agnostic would mean that everyone could use it's own homegrown runtime.

Additionally the last time I've checked the SQLx documentation their exposed interface is missing important methods for diesel (to implement for example prepared statement caching).

(Additionally you should assume that we are well aware of the state of rust's database ecosystem.)

I'm closing this issue as Off-Topic now.

>All comments

Just to clarify a few things:

  1. Pure Rust - The Postgres and MySQL/MariaDB drivers are written in pure Rust using zero unsafe code

While it's true that those drivers are pure rust with zero unsafe code, they do not handle all the edge cases in the underlying database protocols. Also at least their MySQL` driver is for a factor of 2-5 slower than that one provided by mysqlclient.
Migrating to some pure rust driver is definitely something that would be interesting for diesel, but such a driver should be similar mature than the existing C-drivers provided by the database itself.

  1. Truly Asynchronous - Built from the ground-up using async/await for maximum concurrency (This will solve #399)

You can certainly explain how to solve the problems outlined in this comment. Otherwise please get fluent in rust first before you start to suggest fundementally changing the implementation of a big crate.

  1. Database Agnostic - Support for PostgreSQL, MySQL, SQLite, and MSSQL.

Diesel is already database agnostic, even more than SQLx. It is possible to add support for other database backends as third party crate. See diesel-oci as an example.

  1. Type-safe SQL - macro to check your SQL and bind parameters at compile time.

This point is the most arguable. In my opinion diesel is already more type safe than sqlx because it correctly handles LEFT JOINS for example. (SQLx does not infer columns coming for a LEFT JOIN as nullable for example.)

  1. Runtime Agnostic - Works on async-std or tokio with the runtime-async-std or runtime-tokio cargo feature flag.

Technically that's not "Runtime Agnostic". That's just: We support more than one concrete runtime. Runtime agnostic would mean that everyone could use it's own homegrown runtime.

Additionally the last time I've checked the SQLx documentation their exposed interface is missing important methods for diesel (to implement for example prepared statement caching).

(Additionally you should assume that we are well aware of the state of rust's database ecosystem.)

I'm closing this issue as Off-Topic now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Fuckoffee picture Fuckoffee  路  3Comments

mkroman picture mkroman  路  3Comments

pwoolcoc picture pwoolcoc  路  3Comments

qmx picture qmx  路  3Comments

jimmycuadra picture jimmycuadra  路  3Comments