Questions tagged [rust-sqlx]

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.

145 questions
0
votes
1 answer

Bulk inserts into table

Let's say i have one struct pub struct Student { name: String, age: i32, } I have list of Student type & i want to insert it into postgres table in single query. I am following this (UNNEST()) it has egs for primitive type list but not for…
0
votes
0 answers

Cargo cant install packages cargo-generate and sqlx-cli

I want to install cargo-generate and sqlx-cli but when I do cargo install it always exits with this lines. I am using Ubuntu 23.04 warning: build failed, waiting for other jobs to finish... error: failed to compile `cargo-generate v0.18.3`,…
0
votes
0 answers

Can't use sqlx Executor as a trait object

I need to use the Executor type as a trait object but I get the following error: the trait `Executor` cannot be made into an object. the trait cannot be made into an object because it requires `Self: Sized` If we look into the trait definition, we…
JasterV
  • 17
  • 5
0
votes
1 answer

How to implement a trait on any type that implements PgExecutor?

I have my own trait to extend the functionality that the PgExecutor trait provides. I want to implement these trait on anything that implements PgExecutor but I'm honestly having a hard time. #[async_trait] impl<'a, T> PgExecutorExt for T where…
JasterV
  • 17
  • 5
0
votes
1 answer

Rust cannot represent Postgres numeric type as BigDecimal type

I am writing simple rust web application using actix-web and sqlx. I have struct Book with price field which should be mapped to postgres NUMERIC type. First I got error from sqlx that it was expecting bigdecimal type and suggested to enable this…
Sharmiko
  • 543
  • 4
  • 21
0
votes
1 answer

How to pass SQLX connection - a `&mut Trait` as a fn parameter in Rust

I need to generalize functions to pass an Executor trait for SQLX code. In the code below with a concrete &mut SqliteConnection parameter, main can call process, or it can call process_twice which calls process 2x times. All sqlx functions require…
Yuri Astrakhan
  • 8,808
  • 6
  • 63
  • 97
0
votes
0 answers

How can I fix the issue of sqlx crate not returning any data from MySQL database in my Rust program?

I am developing a Rust program that fetch datas from a mysql database using the sqlx crate. It compiles but it seems that nothing is returned by the crate function. this is my function code so far (I’ve shortened this code at the [...] because it is…
0
votes
0 answers

I'm using sqlx both within and without a transaction, but now I need to use Executor multiple times in the same method

I'm using sqlx. I'm stuck because I can't use the PgExecutor multiple time in the same method. I would like your help to better understand what to use here because I read all the docs and all the issues but cannot find a way. As you can see in my…
Fred Hors
  • 3,258
  • 3
  • 25
  • 71
0
votes
1 answer

Rust SQLX iLike '%$1%' - select by substring

Good day! Could you tell please how tow make it works? db: Postrgresql iLike '%$1%' - doesn't works properly in rust sqlx crate, cant find in library working solution const QUERY_SELECT_COUNTRY_BY_COUNTRY_NAME: &str = "SELECT * FROM…
0
votes
0 answers

Using sqlx MySql queries with scoped threads in Rust

I am trying to copy a known list of MySql tables from one db to another. Because there is a large list of tables, and I will also need to insert large amounts of data into each table as part of the copy, I would like to use threads to make things a…
0
votes
1 answer

Accepting either mutable and immutable generic types with traits in Rust

I am using Rust with sqlx and postgres to build a REST API. I am trying to build a Database struct which has a generic connection param in it. struct Database where T: Sync + Send, for<'a> &'a T: sqlx::Executor<'a, Database =…
0
votes
1 answer

How to use sqlx query_as with rust_decimal for money postgresql type

I'm trying to use rust_decimal with sqlx for money postgresql type and got error. Of course i use decimal feature for sqlx. There is full example Table create table inventory ( id bigserial not null, name text not null, …
Barlog
  • 180
  • 2
  • 9
0
votes
0 answers

What is the most meaningful way to use futures with async/await inside of a Rocket route handler?

I have been building an http server in Rust to handle requests from a React client. I am using the rocket framework to manage the server configuration and the sqlx crate to create and perform actions on a connection pool. I need asynchronous…
0
votes
0 answers

What are these queries used for?

I'm using sqlx for the first times these days. I just found out those queries executed from sqlx in my app, but I don't know what they are used for. Can you help me understand? SELECT typname, typtype, typcategory, typrelid, typelem, …
Fred Hors
  • 3,258
  • 3
  • 25
  • 71
0
votes
0 answers

How to retrieve struct with nested structs with sqlx and Rust?

I'm trying to use Rust and sqlx (v0.6.2) to retrieve from DB structs with nested structs. I tried using the below code but I found out that there is a limit of 9 fields in tuple that I can use with FromRow. Note: As you can see I'm using a Box
Fred Hors
  • 3,258
  • 3
  • 25
  • 71