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
3
votes
2 answers

Create struct that is usable with sqlx, has a datetime AND is serializable. Or how to enable serde?

I have a struct that contains a date and I use it with sqlx to retrieve data from my database. So something like: use sqlx::types::chrono::{DateTime, Utc}; pub struct Account { pub id: i32, pub primary_email_id: i32, pub created:…
Achim
  • 15,415
  • 15
  • 80
  • 144
3
votes
1 answer

Connecting to SQL Server with SQLx

I'm having difficulties accessing my SQL Server database hosted on Azure via the SQLx library. I am able to connect to my database using pymssql: conn = pymssql.connect(server='SERVER.database.windows.net', user='USER', password='PASSWORD',…
picklepick
  • 1,370
  • 1
  • 11
  • 24
3
votes
1 answer

rust sqlx-cli: how to prepare offline mode for queries in tests

I use some https://github.com/launchbadge/sqlx query! macros in my tests, and I need to be able to run cargo sqlx prepare for them so my IDE can expand the macros and provide type information (autocomplete, etc.). But if I just run cargo sqlx…
HectorJ
  • 5,814
  • 3
  • 34
  • 52
3
votes
2 answers

Rust: DataFrame in polars using a vector of structs

Problem I want to read in data into polars dataframe from mysql database. I am using sqlx. sqlx generates a vector of Structs for example: Vec below: From sqlx Docs: // no traits are needed struct Country { country: String, count: i64…
Hamza Zubair
  • 1,232
  • 13
  • 21
3
votes
0 answers

Actix web - sqlx - juniper: I got 'Tried to resolve async field users on type Some("Query") with a sync resolver'

I'm trying to use Actix-SQLx-Juniper in my Rust project. I've followed and combined any tutorial that I've found, it successfully compiled and run. But when I try to post a query, I got this error in terminal: thread 'actix-web' panicked at 'Tried…
3
votes
1 answer

Rust Sqlx handle INSERT ON CONFLICT

I have a query which inserts the data of an user into the db. It works fine, but the users table has an unique index on the username, so when trying to create a row with a username already existing, it throws an error: pub async fn create(user:…
3
votes
1 answer

Mapping n:m relations into Vec using sqlx

I have 2 tables (workplaces and workers) with a n:m relationship. My goal is to have a workplace struct with a Vec that contains all the related workers. I want to do this using sqlx. Using Diesel is not an option for me. This is what i came up with…
3
votes
2 answers

How do I create an actix-web server that accepts both sqlx database pools and transactions?

I'm trying to setup a web application using actix-web and sqlx where I can have tests that have their own webserver and database transaction. I've tried to setup my server creation such that it accepts either a database (Postgres) pool or a…
Oskar Persson
  • 6,605
  • 15
  • 63
  • 124
3
votes
1 answer

How do we define a jsonb and UUID field in sqlx rust?

I have a Postgres table having three fields id which is a bigserial, meta a jsonb field and a uuid UUID field. pub struct MetaLogs { pub id:i64, pub uuid: pub meta: < What type should I give here > } I…
Asnim P Ansari
  • 1,932
  • 1
  • 18
  • 41
3
votes
1 answer

Error: failed to connect to database: password authentication failed in Rust

I am trying to connect to database in Rust using sqlx crate and Postgres database. main.rs: use dotenv; use sqlx::Pool; use sqlx::PgPool; use sqlx::query; #[async_std::main] async fn main() -> Result<(), Error> { dotenv::dotenv().ok(); …
Ayman Arif
  • 1,456
  • 3
  • 16
  • 40
2
votes
1 answer

Properly dealing with hierarchies in Rust & SQLx

I am working on a REST API written in Rust using actix-web, SQLx and PostgreSQL for storage. Let's suppose this is my schema (expressed as Rust structs): struct User { pub id: Uuid, pub email: String // And so on... } struct Customer { …
Julian Kirsch
  • 539
  • 4
  • 17
2
votes
3 answers

How to use sqlx query_as to fetch some of the model fields

I have a table called order_data which has timestamp field called created_on and i32 field order_id. I want to query those in different methods. For created_on: pub async fn fetch_last_created_on(pool: &Pool) -> Option { …
Enigo
  • 3,685
  • 5
  • 29
  • 54
2
votes
1 answer

Rust Actix-Web sqlx optional feature `time` required for type TIMESTAMPTZ of column #4 ("created_at")

I'm creating my model using Actix-Web framework and sqlx library to make all sql queries with postgresql. My problem is that I'm creating my model and when I query to get all the rows from a table, it gives me an error in the 'created_at'…
arturfil
  • 380
  • 5
  • 13
2
votes
1 answer

Rust: sqlx try_from Option

I have the following code: // cargo.toml: // serde = { version = "1.0", features = ["derive"] } // uuid = { version = "1.2", features = ["serde", "v4"] } // sqlx = { version = "0.6.2", features = ["runtime-async-std-native-tls",…
Ilya Dyachenko
  • 95
  • 1
  • 2
  • 5
2
votes
1 answer

How to cancel a long-running query when using rust-sqlx/tokio

I am migrating from rusqlite where I was using get_interrupt_handle to abort a query immediately from another thread (when the user changed the filter parameters). Here's an example of my current code. The best I can do is add an interrupt check…
jnnnnn
  • 3,889
  • 32
  • 37
1 2
3
9 10