The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL. Don't confuse with the sqlx tag, which is a GO library.
Questions tagged [rust-sqlx]
145 questions
2
votes
0 answers
How to log parameters instead of placeholders using sqlx with Postgres?
I'm using sqlx for the first time today.
I'm having really hard time understanding my SQL errors because I cannot copy & paste logged queries in my IDE because the parameters are not converted from placeholders.
It prints:
SELECT * from players…

Fred Hors
- 3,258
- 3
- 25
- 71
2
votes
1 answer
Only one of runetimes can be active error when only one runtime specified
What is going on here:
From Cargo.toml:
name = "sitegen"
version = "0.2.0"
edition = "2021"
[dependencies]
axum_database_sessions = { version = "5.0", features = [ "mysql-native"] }
sqlx = { version = "0.6", features = ["runtime-tokio-rustls",…

user3524890
- 23
- 3
2
votes
0 answers
Rust sqlx generic function over specific backends
I am trying to abstract a query over 2 backends (postgres and sqlite). I understand why the following does not work
async fn my_query(p: sqlx::Pool, bar: &Uuid) -> Result<(), Error>
where
T: sqlx::Database,
{
sqlx::query_as::<_,…

clo_jur
- 1,359
- 1
- 11
- 27
2
votes
0 answers
How to use fetch_many / execute_many in sqlx?
In my sample program I'm trying to do the following:
use futures::StreamExt;
use sqlx::Connection;
#[tokio::main]
async fn main() {
let mut conn = sqlx::MySqlConnection::connect("mysql://user:pass@localhost/db")
.await
…

kyku
- 5,892
- 4
- 43
- 51
2
votes
0 answers
How to store rich enum type (variants hold data) in Postgres using `sqlx`?
we would like store an enum with variants holding data in our Postgres database. For example, something like:
enum Animal {
Cat { name: String },
Dog { age: i32 },
}
For now we created three tables animals, cats, and dogs. But this makes…

felixinho
- 625
- 7
- 17
2
votes
1 answer
SQLx MySQL connection with lazy_static cannot be sent between threads safely
I use sqlx for initializing mysql connection (asynchronous) using lazy_static but weird errors occurred.
This is the code that I wrote:
use actix_web::middleware::Logger;
use actix_web::web::{Data, JsonConfig};
use actix_web::{App,…

Abdelaziz Said
- 21
- 6
2
votes
0 answers
How to wrap Sqlx data access types retaining transaction support?
I need to wrap Sqlx connection and Transaction types into my corresponding opaque types that will implement domain-specific data access methods. Trying to achieve that I'm struggling to support spawning of transactions. Here is my simplified…

ababo
- 1,490
- 1
- 10
- 24
2
votes
1 answer
Error communicating with database: IO driver has terminated
I have an API with actix_web and I'm trying to write some tests for it.
I want all the tests to share the same pool as the get_pool function resets and then seeds some data into the db.
The tests do not need to be executed in order.
The structure is…

alakhpc
- 21
- 3
2
votes
2 answers
rust SQLx: "expected enum `std::option::Option`" in a query but not in a similar one
I have two Rust methods selecting data with sqlx from the same SQLite table depending on two different parameters.
I cannot manage to have both working due to an expected `i64`, found enum `std::option::Option` error.
Code
// src/main.rs
use tokio;…

AleG
- 108
- 9
2
votes
1 answer
SQLx to Mssql connection string
I'm learning rust and I've written my first very simple API using Rocket. Now I'd like to connect my server to an existing database I've got on MSFT Azure.
I'm having a hard time finding examples on how this works for Mssql, the SQLx repository only…

picklepick
- 1,370
- 1
- 11
- 24
2
votes
1 answer
Problem with Errors with actix-session, sqlx, async-graphql
I am trying to create a graphql resolver (with async-graphql) in an actix web app. I am doing a me query, where I am getting the user id from the session, and fetching the user from the database. This is the most relevant parts of the code
use…

Norse
- 628
- 8
- 26
2
votes
2 answers
extract macro argument inside string
I have following macro :-
macro_rules! update_user {
($tx:ident, $id:expr, $key:expr, $val:expr) => {
sqlx::query!(
"UPDATE users SET
$key = ?
WHERE id = $id
"
, $val
…

너를 속였다
- 899
- 11
- 26
1
vote
1 answer
Retry an async function that takes mutable ref as argument
I have a function fetch_stuff that needs a mutable ref to a sqlx connection. I would like to retry this function up to N times if it fails. I need this retry behavior for many similar functions so I tried to make a generic retry_up_to_n_times func,…

valentinRssl
- 48
- 6
1
vote
1 answer
launchbadge/sqlx: id column type is incorrectly inferred as Option
In my to-do application back-end using Actix Web and SQLx crates, along with SQLite database, after the UPDATE query I noticed id field on the Record type is Option instead of i64. It's supposed to be i64 since it is declared as PRIMARY KEY NOT…

Gabriel Pureliani
- 263
- 4
- 8
1
vote
2 answers
error originates in the macro $crate::sqlx_macros::expand_query which comes from the expansion of the macro sqlx::query_as
My database and model have all the relevant fields. I want to send query to database, but I faced this error.:
error: error occurred while decoding column 0: expected value at line 13 column 5
--> src/handler.rs:98:16
|
98 | let user =…

dhiraka
- 817
- 6
- 13