mod schema;
use diesel::{prelude::*, sql_query};
use diesel::{Queryable, Selectable};
use diesel_async::pooled_connection::bb8::Pool;
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
use diesel_async::RunQueryDsl;
use serde::{Deserialize, Serialize};
#[derive(
Serialize,
Deserialize,
Queryable,
Selectable,
Insertable,
Identifiable,
QueryableByName,
AsChangeset,
)]
#[diesel(table_name = crate::schema::te_test_tst, primary_key(tst_id))]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct TestEntity {
#[diesel(column_name = "tst_id")]
pub id: i64,
#[diesel(column_name = "tst_fname")]
pub fname: Option<String>,
}
#[tokio::main]
async fn main() {
println!("Hello, world!");
let database_url = "postgres://xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// create a new connection pool with the default config
let config = AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(database_url);
let pool = Pool::builder().build(config).await.unwrap();
// checkout a connection from the pool
let mut connection = pool.get().await.unwrap();
let results = match sql_query("SELECT * FROM table_test")
.get_results::<TestEntity>(&mut connection)
.await
{
Ok(r) => r,
Err(e) => match e {}, //<------- !!!
};
}
[package]
name = "diesel_test"
version = "0.1.0"
edition = "2021"
[dependencies]
diesel = { version = "2.1.6" }
diesel-async = { version = "0.4.1", features = ["postgres", "bb8"] }
serde = { version = "1.0.199", features = ["derive"] }
tokio = { version = "1.37.0", features = ["full"] }
I've also noticed that from time to time (not always, I get this error in the logs ) I don't know if it's related
2024-05-10T19:56:26.477624Z ERROR hir_ty::mir: Only tuple has tuple field
2024-05-10T19:56:26.477644Z ERROR hir_ty::mir: Only tuple has tuple field
2024-05-10T19:56:26.477653Z ERROR hir_ty::mir: Only tuple has tuple field
2024-05-10T19:56:26.479280Z ERROR hir_ty::mir: Only tuple has tuple field
I get this error only when I use diesel / diesel-async .
Hello,
I noticed that Rust-analyzer fails to autocomplete Match with diesel errors, it can't determine the Enum of
diesel::result::Error
.I've included the code that reproduces the error, as well as a video showing the error and how to fix it temporarily.
rust-analyzer version: rust-analyzer version: 0.3.1950-standalone
rustc version:
rustc 1.78.0 (9b00956e5 2024-04-29)
editor or extension: VSCode : Version: 1.88.1 rust-analyzer extension : v0.3.1950
video
you'll notice on the video that
quick-fixes
no longer works (I'll have to use some tricks to make it work)[ sorry if the mouse is not visible on the video, probably a bug in the ubuntu recorder ]
Screencast from 2024-05-10 21-06-58.webm
code snippet to reproduce :
main.rs
schema.rs
Cargo.toml :
I've also noticed that from time to time (not always, I get this error in the logs ) I don't know if it's related
I get this error only when I use diesel / diesel-async .
Thank you for your help..