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

Returning rows from MySQL with RUST sqlx when a VARBINARY(16) column is part of the where clause

I'm trying to query a simple table using sqlx where the field in the WHERE clause is defined in MySQL as a VARBINARY(16). The table is defined as: mysql> desc machine_state; +------------+-----------------+------+-----+---------+-------+ | Field …
0
votes
0 answers

Encode Arc> to PostgreSQL jsonb

Obligatory disclaimer: I'm definitely no Rust/SQL expert, but I'm still learning. I'd appreciate any help in this process. I am trying to encode a struct containing a field of type Arc> into the jsonb PostgreSQL type using the sqlx…
0
votes
2 answers

Rust Rocket with SQLX test database endpoints

I am looking to test my /signup endpoint of my application. This endpoint will fail if an email already exists. My test gets a success the first time, but after that it fails. Indicating that the database is saving the response. Below is my…
Colin99d
  • 3
  • 1
  • 4
0
votes
1 answer

How to execute same query with different bindings within same transaction in Rust SQLx?

I need to insert multiple rows into a table, so I've got a query like INSERT INTO table (col1, col2) VALUES (?, ?) and arguments as list of pairs. Is there a way to execute it in SQLx without constructing a new string like INSERT ... VALUES ((?, ?),…
0
votes
1 answer

specifying the trait bounds for this function that uses sqlx

Would like to make this function generic but having trouble specifying the bounds for parameter T Errors : 1)'cannot find type DB in this scope not found in this scope' Not sure if I was supposed to include ::bind either. I got that from…
0
votes
0 answers

Connecting to SQL Server Instance Using SQLx

I am attempting to connect to Mssql server that is not local. I am using SQLx and am attempting to connect using the following: use sqlx::mssql::MssqlPool; #[tokio::main] async fn main() -> Result<(), sqlx::Error> { let pool =…
Coldchain9
  • 1,373
  • 11
  • 31
0
votes
0 answers

How to convert flat SQL response into domain model with nested entities?

I recently decided to try to work with a database without an additional layer like ORMs. The problem that currently bothers me is how to convert flat SQL query results into domain models with nested entities. Let me show what I mean I have a domain…
Roman Mahotskyi
  • 4,576
  • 5
  • 35
  • 68
0
votes
1 answer

Error inserting multiple columns into Postgresql DB From SQLX

I'm trying to perform an insert query into my Postgresql DB, but I am getting a mismatched type issue that I'm unsure how to solve. Here's the code: pub struct Product { pub id: i32, pub product_id: i64, pub title: String, pub…
G.Rose
  • 644
  • 7
  • 29
0
votes
1 answer

How to convert BigDecimal into f64?

I have a SQL query that returns a column with the BigDecimal type but my domain model works with f64: price: Price::new(record.price).unwrap(), ^^^^^^^^^^^^ rustc: mismatched types expected…
Roman Mahotskyi
  • 4,576
  • 5
  • 35
  • 68
0
votes
1 answer

Serialize is not implemented for PgRange>

I would like to be able to serialize a struct containing PgRange> however, #[derive(Serialize)] fails for struct Reservation with the error: pub timespan: PgRange>, ^^^ the trait `Serialize` is not implemented for…
Blank
  • 423
  • 1
  • 5
  • 16
0
votes
1 answer

Rust sqlx don't save anything to database

After creating Postgres and execute query. Database doesn't include any changes, but if I execute the same INSERT with the unique field, it returns an Error like it already exists. let from_ssl = |ssl: bool| -> PgSslMode { match ssl { …
0
votes
0 answers

Creating trait to be implemented by `PgPool`, `MySqlPool`, etc. - what is the correct `sql::Executor` trait bound on `Self`?

I'm using SQLx to define a trait that is to be implemented on PgPool, MySqlPool, etc. and looks something like this: #[async_trait] trait MyTrait { const QUERY: &'static str; fn fetch(&self) -> Option { …
bmoxb
  • 33
  • 3
0
votes
1 answer

thread 'main' panicked at 'assertion failed: self.remaining() >= dst.len()' when trying to connect database MYSQL

So when i try to connect mysql database main tread panics it was working fine with sqlite but when i try to use it with mysql it's not working. cargo check is also working fine. The error is located at line 20 where i created a database…
0
votes
0 answers

Rollback integration test

I'm currently trying to create a simple integration test that for example try the signup endpoint. Coming from many other backend languages I'm used to rollback database after each test. How can I do this using sqlx? Is there any way to start sqlx…
mcfly
  • 774
  • 1
  • 8
  • 18
0
votes
0 answers

MssqlRow to json string without knowing structure and data type on compile time

I'm trying to query a database to get data, convert it to json file and send it to another service. Because those queries can have any column in any table it is impossible to define all structures and data types. I was trying to use sqlx lib but…
1 2 3
9
10