launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.42k stars 1.28k forks source link

Any driver does not support the Postgres type PgTypeInfo(Uuid) #3571

Open Huyyyyyyyy opened 2 weeks ago

Huyyyyyyyy commented 2 weeks ago

Bug Description

A clear and concise description of what the bug is. I got an error while I am trying to get data from column has type UUID ColumnDecode { index: "request_id", source: AnyDriverError("Any driver does not support the Postgres type PgTypeInfo(Uuid)") } My query use: select request_id from tb_purchase request_id is UUID type in PostgreSQL

Code block:

use super::trait_connection::IConnection;
use async_trait::async_trait;
use sqlx::{any::AnyRow, pool::PoolOptions, AnyPool};

#[derive(Debug)]
pub struct PostgresConnection {
    pub database_url: String,
    pub pool: Option<AnyPool>,
}
// ... code snippet

    async fn query(&self, query: &str) -> Result<Vec<AnyRow>, String> {
        let pool = self
            .pool
            .as_ref()
            .ok_or("Database connection not established")?;

        if query.is_empty() {
            return Err("No query provided".to_string());
        }

        let rows = sqlx::query(query)
            .fetch_all(pool)
            .await
            .map_err(|e| format!("Failed to query - {:?}", e))?;

        Ok(rows)
    }

Got error due to I am using AnyPool When I replace AnyPool with PgPool, the system work normally. But I prefer using AnyPool because I am thinking of AnyPool can adapt to different DB types, instead of hardcoded to PostgreSQL

Minimal Reproduction

A small code snippet or a link to a Github repo or Gist, with instructions on reproducing the bug.

Info

Norlock commented 1 week ago

Also PgTypeInfo(Numeric) is not recognized as anytypeinfo, I found out.

AnyTypeInfoKind::Real | AnyTypeInfoKind::Double, cannot be parsed to from PgTypeInfo(Numeric)

Shirogaki commented 6 days ago

Seems like you'll have to switch implementation, use an adapter or limit yourself to Postgre