mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 07:21:08 +00:00
fix: allow queries that select just void to pass through macros as ()
instead of struct { _1: () }
This commit is contained in:
parent
67142259e4
commit
3885ae6ddf
@ -755,6 +755,10 @@ impl TypeInfo for PgTypeInfo {
|
||||
fn is_null(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn is_void(&self) -> bool {
|
||||
matches!(self.0, PgType::Void)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<PgCustomType> for PgCustomType {
|
||||
|
@ -8,4 +8,9 @@ pub trait TypeInfo: Debug + Display + Clone + PartialEq<Self> + Send + Sync {
|
||||
/// Common type names are `VARCHAR`, `TEXT`, or `INT`. Type names should be uppercase. They
|
||||
/// should be a rough approximation of how they are written in SQL in the given database.
|
||||
fn name(&self) -> &str;
|
||||
|
||||
#[doc(hidden)]
|
||||
fn is_void(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ pub use input::QueryMacroInput;
|
||||
use quote::{format_ident, quote};
|
||||
use sqlx_core::connection::Connection;
|
||||
use sqlx_core::database::Database;
|
||||
use sqlx_core::describe::Describe;
|
||||
use sqlx_core::{column::Column, describe::Describe, type_info::TypeInfo};
|
||||
use sqlx_rt::block_on;
|
||||
|
||||
use crate::database::DatabaseExt;
|
||||
@ -208,7 +208,7 @@ where
|
||||
|
||||
let query_args = format_ident!("query_args");
|
||||
|
||||
let output = if data.describe.columns().is_empty() {
|
||||
let output = if data.describe.columns().iter().all(|it| it.type_info().is_void()) {
|
||||
let db_path = DB::db_path();
|
||||
let sql = &input.src;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/// Statically checked SQL query with `println!()` style syntax.
|
||||
///
|
||||
/// This expands to an instance of [`query::Map`][crate::query::Map] that outputs an ad-hoc anonymous
|
||||
/// struct type, if the query has output columns, or `()` (unit) otherwise:
|
||||
/// struct type, if the query has at least one output column that is not `Void`, or `()` (unit) otherwise:
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// # use sqlx::Connect;
|
||||
|
@ -89,12 +89,10 @@ async fn test_text_var_char_char_n() -> anyhow::Result<()> {
|
||||
async fn test_void() -> anyhow::Result<()> {
|
||||
let mut conn = new::<Postgres>().await?;
|
||||
|
||||
let record = sqlx::query!(r#"select pg_notify('chan', 'message') as _1"#)
|
||||
.fetch_one(&mut conn)
|
||||
let _ = sqlx::query!(r#"select pg_notify('chan', 'message')"#)
|
||||
.execute(&mut conn)
|
||||
.await?;
|
||||
|
||||
assert_eq!(record._1, Some(()));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user