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
1
vote
1 answer

Why do I get "syntax error at end of input" when binding data with sqlx?

I'm looking to bind data through my SQL string: #[derive(Debug, sqlx::FromRow)] struct CurrencyExchangeRateBdd { currency_exchange_rate_id: i64, from_currency: String, to_currency: String, rate_date: Date, rate: f64, …
Raphael M
  • 109
  • 1
  • 9
1
vote
1 answer

Query BYTEA in Postgres using sqlx

I have the following table in Postgres DB: CREATE TABLE resources_index ( hash varchar NOT NULL, "name" varchar NOT NULL, viewentry_id varchar NOT NULL, value bytea NULL ); I'd like to execute the following prepared statement using…
1
vote
1 answer

Handling duplicate inserts into database in async rust

Beginner in both rust and async programming here. I have a function that downloads and stores a bunch of tweets in the database: pub async fn process_user_timeline(config: &Settings, pool: &PgPool, user_object: &Value) { // get timeline if…
ilmoi
  • 1,994
  • 2
  • 21
  • 45
1
vote
1 answer

Async version of once_cell, or a way to avoid error[E0744]: `.await` is not allowed in a `static`?

I've been using once_cell to do a lot of work that only needs to be done once, and then persist as read-only global. This is nice because I don't have to pass these things around. I was wanting to know if something like this is permitted for db…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
1
vote
0 answers

Caching sqlx Pool causes overrun in file handles

I plan to have a application which uses Sqlite databases as data files. Because different files can be opended more often, I want to cache the connections. I'm very new to Rust; this is my first project... My problem is: Somewhen I run out of file…
macalloy
  • 43
  • 7
1
vote
1 answer

sqlx installation fails due to mismatched types

I'm installing sqlx on Ubuntu 18.04: cargo install --git https://github.com/launchbadge/sqlx sqlx-cli I get the error error[E0308]: mismatched types --> sqlx-cli/src/opt.rs:8:20 | 8 | #[clap(short = "D", long)] | ^^^…
Francesco Iapicca
  • 2,618
  • 5
  • 40
  • 85
0
votes
1 answer

Connecting to containerized postgres via Sqlx

I can't figure out what address to use when running my API service in the same container as my Postgres image. I keep getting the following error. thread 'main' panicked at 'Error connecting to db: Io(Os { code: 99, kind: AddrNotAvailable, message:…
Dumb Nerd
  • 15
  • 6
0
votes
0 answers

How to ignore a query field in rust postgres sqlx query_as()

Can I tell sqlx to ignore a field in a query I pass to query_as!()? struct User { a:String } ... let users = sqlx::query_as(User, r#" select a, b from my_table "# ).fetch_all(pool).await; (obviously) results in: error[E0560]:…
cloudsurfin
  • 2,467
  • 2
  • 25
  • 29
0
votes
0 answers

Problem with fields when working with sqlx in rust

I am working on a REST API written in Rust using axum, sqlx and PostgreSQL. There are the following two models: #[derive(FromRow, Serialize)] pub struct Brand { id: i32, title: String, #[sqlx(flatten)] product:…
0
votes
1 answer

How to fix "cannot find derive macro `FromRow` in this scope"?

I try to create a connection with a PostgreSQL databse using the Rocket framework. This is my cargo.tml: [package] name = "TestRust" version = "0.1.0" edition = "2021" [dependencies] rand = "0.8.3" rocket = { version = "=0.5.0-rc.3", features =…
macyaz
  • 3
  • 3
0
votes
1 answer

missing field `registration_key` in initializer of `database::models::RegistrationKeys`

Here is my struct definition pub struct RegistrationKeys { pub id: i64, pub registration_key: String, } Here's my table definition CREATE TABLE IF NOT EXISTS RegistrationKeys ( id SERIAL PRIMARY KEY, registration_key…
Mickers
  • 1,367
  • 1
  • 20
  • 28
0
votes
2 answers

Sqlx: Convert / Retrieve Postgresql column of type RECORD[] into a struct field of type Vec<_>

I have the following two structs: #[derive(Serialize, Deserialize)] struct Login { email: String, oidc_id: String } #[derive(Serialize, Deserialize)] struct Account { id: Uuid, created: NaiveDateTime, private_key: String, …
Achim
  • 15,415
  • 15
  • 80
  • 144
0
votes
1 answer

The results of the same SQL query using sqlx and pysql are completely different

When I execute SQL statements using rust sqlx, I find that the returned results are incorrect. For the same statements, when I use pysql, I get results consistent with those obtained from the MySQL client query. I don't know why this is happening;…
0
votes
1 answer

Trait is not implemented for std::string::String

I am almost sure I had this working a couple months a go, but now I came back to add some other functions to the API and it has type errors on all my sqlx calls. here is the error: the trait…
rek2
  • 101
  • 12
0
votes
0 answers

Insert an array of Postgres composite types using Rust (sqlx)

I have a schema that uses composite types and domains, similar to this: create domain float3 as double precision[3]; create type Sample as ( pos float3, dist double precision ); create table scans ( id uuid not null primary key, …
DoubleEwe
  • 151
  • 8