Skip to content

Commit

Permalink
Make query_builder::nodes private
Browse files Browse the repository at this point in the history
  • Loading branch information
weiznich committed Mar 2, 2022
1 parent 5d83a72 commit ad1ce71
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
1 change: 0 additions & 1 deletion diesel/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ pub type LoadRowIter<'conn, 'query, C, DB> =
/// **It's important to use prepared statements to implement the following methods:**
/// * [`Connection::load`]
/// * [`Connection::execute_returning_count`]
/// * [`Connection::execute`]
///
/// For performance reasons it may also be meaningful to cache already prepared statements.
#[cfg_attr(
Expand Down
4 changes: 4 additions & 0 deletions diesel/src/internal/table_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ pub use crate::pg::query_builder::only_clause::Only;
#[doc(hidden)]
pub use crate::query_builder::from_clause::{FromClause, NoFromClause};
#[doc(hidden)]
pub use crate::query_builder::nodes::{
Identifier, InfixNode, StaticQueryFragment, StaticQueryFragmentInstance,
};
#[doc(hidden)]
pub use crate::query_builder::select_statement::boxed::BoxedSelectStatement;
#[doc(hidden)]
pub use crate::query_builder::select_statement::SelectStatement;
Expand Down
34 changes: 17 additions & 17 deletions diesel/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ macro_rules! __diesel_column {

impl<DB> $crate::query_builder::QueryFragment<DB> for $column_name where
DB: $crate::backend::Backend,
$crate::query_builder::nodes::StaticQueryFragmentInstance<table>: $crate::query_builder::QueryFragment<DB>,
$crate::internal::table_macro::StaticQueryFragmentInstance<table>: $crate::query_builder::QueryFragment<DB>,
{
#[allow(non_snake_case)]
fn walk_ast<'b>(&'b self, mut __out: $crate::query_builder::AstPass<'_, 'b, DB>) -> $crate::result::QueryResult<()>
{
const FROM_CLAUSE: $crate::query_builder::nodes::StaticQueryFragmentInstance<table> = $crate::query_builder::nodes::StaticQueryFragmentInstance::new();
const FROM_CLAUSE: $crate::internal::table_macro::StaticQueryFragmentInstance<table> = $crate::internal::table_macro::StaticQueryFragmentInstance::new();

FROM_CLAUSE.walk_ast(__out.reborrow())?;
__out.push_sql(".");
Expand Down Expand Up @@ -753,11 +753,11 @@ macro_rules! __diesel_table_impl {
pub type BoxedQuery<'a, DB, ST = SqlType> = $crate::internal::table_macro::BoxedSelectStatement<'a, ST, $crate::internal::table_macro::FromClause<table>, DB>;

impl $crate::QuerySource for table {
type FromClause = $crate::query_builder::nodes::StaticQueryFragmentInstance<table>;
type FromClause = $crate::internal::table_macro::StaticQueryFragmentInstance<table>;
type DefaultSelection = <Self as $crate::Table>::AllColumns;

fn from_clause(&self) -> Self::FromClause {
$crate::query_builder::nodes::StaticQueryFragmentInstance::new()
$crate::internal::table_macro::StaticQueryFragmentInstance::new()
}

fn default_selection(&self) -> Self::DefaultSelection {
Expand All @@ -768,10 +768,10 @@ macro_rules! __diesel_table_impl {

impl<DB> $crate::query_builder::QueryFragment<DB> for table where
DB: $crate::backend::Backend,
<table as $crate::query_builder::nodes::StaticQueryFragment>::Component: $crate::query_builder::QueryFragment<DB>
<table as $crate::internal::table_macro::StaticQueryFragment>::Component: $crate::query_builder::QueryFragment<DB>
{
fn walk_ast<'b>(&'b self, pass: $crate::query_builder::AstPass<'_, 'b, DB>) -> $crate::result::QueryResult<()> {
<table as $crate::query_builder::nodes::StaticQueryFragment>::STATIC_COMPONENT.walk_ast(pass)
<table as $crate::internal::table_macro::StaticQueryFragment>::STATIC_COMPONENT.walk_ast(pass)
}
}

Expand Down Expand Up @@ -981,7 +981,7 @@ macro_rules! __diesel_table_impl {
fn walk_ast<'b>(&'b self, mut __out: $crate::query_builder::AstPass<'_, 'b, DB>) -> $crate::result::QueryResult<()>
{
use $crate::QuerySource;
const FROM_CLAUSE: $crate::query_builder::nodes::StaticQueryFragmentInstance<table> = $crate::query_builder::nodes::StaticQueryFragmentInstance::new();
const FROM_CLAUSE: $crate::internal::table_macro::StaticQueryFragmentInstance<table> = $crate::internal::table_macro::StaticQueryFragmentInstance::new();

FROM_CLAUSE.walk_ast(__out.reborrow())?;
__out.push_sql(".*");
Expand Down Expand Up @@ -1061,22 +1061,22 @@ macro_rules! __diesel_valid_grouping_for_table_columns {
#[doc(hidden)]
macro_rules! __diesel_table_generate_static_query_fragment_for_table {
(public, $table: ident, $table_name:expr) => {
impl $crate::query_builder::nodes::StaticQueryFragment for table {
type Component = $crate::query_builder::nodes::Identifier<'static>;
const STATIC_COMPONENT: &'static Self::Component = &$crate::query_builder::nodes::Identifier($table_name);
impl $crate::internal::table_macro::StaticQueryFragment for table {
type Component = $crate::internal::table_macro::Identifier<'static>;
const STATIC_COMPONENT: &'static Self::Component = &$crate::internal::table_macro::Identifier($table_name);
}

};
($schema_name:ident, $table: ident, $table_name:expr) => {
impl $crate::query_builder::nodes::StaticQueryFragment for table {
type Component = $crate::query_builder::nodes::InfixNode<
$crate::query_builder::nodes::Identifier<'static>,
$crate::query_builder::nodes::Identifier<'static>,
impl $crate::internal::table_macro::StaticQueryFragment for table {
type Component = $crate::internal::table_macro::InfixNode<
$crate::internal::table_macro::Identifier<'static>,
$crate::internal::table_macro::Identifier<'static>,
&'static str
>;
const STATIC_COMPONENT: &'static Self::Component = &$crate::query_builder::nodes::InfixNode::new(
$crate::query_builder::nodes::Identifier(stringify!($schema_name)),
$crate::query_builder::nodes::Identifier($table_name),
const STATIC_COMPONENT: &'static Self::Component = &$crate::internal::table_macro::InfixNode::new(
$crate::internal::table_macro::Identifier(stringify!($schema_name)),
$crate::internal::table_macro::Identifier($table_name),
"."
);
}
Expand Down
3 changes: 1 addition & 2 deletions diesel/src/query_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ pub(crate) mod insert_statement;
pub(crate) mod limit_clause;
pub(crate) mod limit_offset_clause;
pub(crate) mod locking_clause;
#[doc(hidden)]
pub mod nodes;
pub(crate) mod nodes;
pub(crate) mod offset_clause;
pub(crate) mod order_clause;
mod returning_clause;
Expand Down
6 changes: 6 additions & 0 deletions diesel/src/query_builder/nodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ use crate::query_builder::*;
use crate::result::QueryResult;
use std::marker::PhantomData;

#[doc(hidden)] // used by the table macro
pub trait StaticQueryFragment {
type Component: 'static;
const STATIC_COMPONENT: &'static Self::Component;
}

#[derive(Debug, Copy, Clone)]
#[doc(hidden)] // used by the table macro
pub struct StaticQueryFragmentInstance<T>(PhantomData<T>);

impl<T> StaticQueryFragmentInstance<T> {
#[doc(hidden)] // used by the table macro
pub const fn new() -> Self {
Self(PhantomData)
}
Expand All @@ -29,6 +32,7 @@ where
}

#[derive(Debug, Copy, Clone)]
#[doc(hidden)] // used by the table macro
pub struct Identifier<'a>(pub &'a str);

impl<'a, DB: Backend> QueryFragment<DB> for Identifier<'a> {
Expand All @@ -48,13 +52,15 @@ impl<'a, DB: Backend> MiddleFragment<DB> for &'a str {
}

#[derive(Debug, Copy, Clone)]
#[doc(hidden)] // used by the table macro
pub struct InfixNode<T, U, M> {
lhs: T,
rhs: U,
middle: M,
}

impl<T, U, M> InfixNode<T, U, M> {
#[doc(hidden)] // used by the table macro
pub const fn new(lhs: T, rhs: U, middle: M) -> Self {
InfixNode { lhs, rhs, middle }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ error[E0277]: the trait bound `{integer}: QueryFragment<Pg>` is not satisfied
<() as QueryFragment<DB>>
<(T0, T1) as QueryFragment<__DB>>
<(T0, T1, T2) as QueryFragment<__DB>>
and 259 others
and 260 others
= note: required because of the requirements on the impl of `QueryFragment<Pg>` for `({integer}, diesel::internal::derives::as_expression::Bound<diesel::sql_types::Double, f64>)`
= note: 3 redundant requirements hidden
= note: required because of the requirements on the impl of `QueryFragment<Pg>` for `SelectStatement<NoFromClause, diesel::query_builder::select_clause::SelectClause<diesel::pg::expression::array::ArrayLiteral<({integer}, diesel::internal::derives::as_expression::Bound<diesel::sql_types::Double, f64>), diesel::sql_types::Double>>>`
Expand All @@ -206,7 +206,7 @@ error[E0277]: the trait bound `{integer}: QueryId` is not satisfied
<() as QueryId>
<(T0, T1) as QueryId>
<(T0, T1, T2) as QueryId>
and 222 others
and 223 others
= note: required because of the requirements on the impl of `QueryId` for `({integer}, diesel::internal::derives::as_expression::Bound<diesel::sql_types::Double, f64>)`
= note: 3 redundant requirements hidden
= note: required because of the requirements on the impl of `QueryId` for `SelectStatement<NoFromClause, diesel::query_builder::select_clause::SelectClause<diesel::pg::expression::array::ArrayLiteral<({integer}, diesel::internal::derives::as_expression::Bound<diesel::sql_types::Double, f64>), diesel::sql_types::Double>>>`
Expand Down

0 comments on commit ad1ce71

Please sign in to comment.