1use crate::expression::*;
2use crate::query_builder::*;
3use crate::query_dsl::RunQueryDslSupport;
4use crate::result::QueryResult;
5use crate::sql_types::DieselNumericOps;
6use alloc::string::String;
7use core::marker::PhantomData;
8
9#[derive(#[automatically_derived]
impl<ST: ::core::fmt::Debug, T: ::core::fmt::Debug> ::core::fmt::Debug for
SqlLiteral<ST, T> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "SqlLiteral",
"sql", &self.sql, "inner", &self.inner, "_marker", &&self._marker)
}
}Debug, #[automatically_derived]
impl<ST: ::core::clone::Clone, T: ::core::clone::Clone> ::core::clone::Clone
for SqlLiteral<ST, T> {
#[inline]
fn clone(&self) -> SqlLiteral<ST, T> {
SqlLiteral {
sql: ::core::clone::Clone::clone(&self.sql),
inner: ::core::clone::Clone::clone(&self.inner),
_marker: ::core::clone::Clone::clone(&self._marker),
}
}
}Clone, const _: () =
{
use diesel;
use diesel::internal::derives::numeric_ops as ops;
use diesel::expression::{Expression, AsExpression};
use diesel::sql_types::ops::{Add, Sub, Mul, Div};
use diesel::sql_types::{SqlType, SingleValue};
impl<ST, T, __Rhs> ::core::ops::Add<__Rhs> for SqlLiteral<ST, T> where
Self: Expression, Self: Expression,
<Self as Expression>::SqlType: Add,
<<Self as Expression>::SqlType as Add>::Rhs: SqlType +
SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Add>::Rhs> {
type Output = ops::Add<Self, __Rhs::Expression>;
fn add(self, rhs: __Rhs) -> Self::Output {
ops::Add::new(self, rhs.as_expression())
}
}
impl<ST, T, __Rhs> ::core::ops::Sub<__Rhs> for SqlLiteral<ST, T> where
Self: Expression, Self: Expression,
<Self as Expression>::SqlType: Sub,
<<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Sub>::Rhs> {
type Output = ops::Sub<Self, __Rhs::Expression>;
fn sub(self, rhs: __Rhs) -> Self::Output {
ops::Sub::new(self, rhs.as_expression())
}
}
impl<ST, T, __Rhs> ::core::ops::Mul<__Rhs> for SqlLiteral<ST, T> where
Self: Expression, Self: Expression,
<Self as Expression>::SqlType: Mul,
<<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Mul>::Rhs> {
type Output = ops::Mul<Self, __Rhs::Expression>;
fn mul(self, rhs: __Rhs) -> Self::Output {
ops::Mul::new(self, rhs.as_expression())
}
}
impl<ST, T, __Rhs> ::core::ops::Div<__Rhs> for SqlLiteral<ST, T> where
Self: Expression, Self: Expression,
<Self as Expression>::SqlType: Div,
<<Self as Expression>::SqlType as Div>::Rhs: SqlType +
SingleValue,
__Rhs: AsExpression<<<Self as Expression>::SqlType as Div>::Rhs> {
type Output = ops::Div<Self, __Rhs::Expression>;
fn div(self, rhs: __Rhs) -> Self::Output {
ops::Div::new(self, rhs.as_expression())
}
}
};DieselNumericOps)]
10#[must_use = "Queries are only executed when calling `load`, `get_result`, or similar."]
11pub struct SqlLiteral<ST, T = self::private::Empty> {
15 sql: String,
16 inner: T,
17 _marker: PhantomData<ST>,
18}
19
20impl<ST, T> SqlLiteral<ST, T>
21where
22 ST: TypedExpressionType,
23{
24 pub(crate) fn new(sql: String, inner: T) -> Self {
25 SqlLiteral {
26 sql,
27 inner,
28 _marker: PhantomData,
29 }
30 }
31
32 pub fn bind<BindST, U>(self, bind_value: U) -> UncheckedBind<Self, U::Expression>
103 where
104 BindST: SqlType + TypedExpressionType,
105 U: AsExpression<BindST>,
106 {
107 UncheckedBind::new(self, bind_value.as_expression())
108 }
109
110 pub fn sql(self, sql: &str) -> SqlLiteral<ST, Self> {
153 SqlLiteral::new(sql.into(), self)
154 }
155}
156
157impl<ST, T> Expression for SqlLiteral<ST, T>
158where
159 ST: TypedExpressionType,
160{
161 type SqlType = ST;
162}
163
164impl<ST, T, DB> QueryFragment<DB> for SqlLiteral<ST, T>
165where
166 DB: Backend,
167 T: QueryFragment<DB>,
168{
169 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
170 out.unsafe_to_cache_prepared();
171 self.inner.walk_ast(out.reborrow())?;
172 out.push_sql(&self.sql);
173 Ok(())
174 }
175}
176
177impl<ST, T> QueryId for SqlLiteral<ST, T> {
178 type QueryId = ();
179
180 const HAS_STATIC_QUERY_ID: bool = false;
181}
182
183impl<ST, T> Query for SqlLiteral<ST, T>
184where
185 Self: Expression,
186{
187 type SqlType = ST;
188}
189
190impl<ST, T> RunQueryDslSupport for SqlLiteral<ST, T> {}
191
192impl<QS, ST, T> SelectableExpression<QS> for SqlLiteral<ST, T> where Self: Expression {}
193
194impl<QS, ST, T> AppearsOnTable<QS> for SqlLiteral<ST, T> where Self: Expression {}
195
196impl<ST, T, GB> ValidGrouping<GB> for SqlLiteral<ST, T> {
197 type IsAggregate = is_aggregate::Never;
198}
199
200pub fn sql<ST>(sql: &str) -> SqlLiteral<ST>
269where
270 ST: TypedExpressionType,
271{
272 SqlLiteral::new(sql.into(), self::private::Empty)
273}
274
275#[derive(const _: () =
{
use diesel;
#[allow(non_camel_case_types)]
impl<Query: diesel::query_builder::QueryId,
Value: diesel::query_builder::QueryId>
diesel::query_builder::QueryId for UncheckedBind<Query, Value> {
type QueryId =
UncheckedBind<<Query as
diesel::query_builder::QueryId>::QueryId,
<Value as diesel::query_builder::QueryId>::QueryId>;
const HAS_STATIC_QUERY_ID: bool =
<Query as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
&&
<Value as
diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
true;
const IS_WINDOW_FUNCTION: bool =
<Query as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION
||
<Value as
diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
false;
}
};QueryId, #[automatically_derived]
impl<Query: ::core::fmt::Debug, Value: ::core::fmt::Debug> ::core::fmt::Debug
for UncheckedBind<Query, Value> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "UncheckedBind",
"query", &self.query, "value", &&self.value)
}
}Debug, #[automatically_derived]
impl<Query: ::core::clone::Clone, Value: ::core::clone::Clone>
::core::clone::Clone for UncheckedBind<Query, Value> {
#[inline]
fn clone(&self) -> UncheckedBind<Query, Value> {
UncheckedBind {
query: ::core::clone::Clone::clone(&self.query),
value: ::core::clone::Clone::clone(&self.value),
}
}
}Clone, #[automatically_derived]
impl<Query: ::core::marker::Copy, Value: ::core::marker::Copy>
::core::marker::Copy for UncheckedBind<Query, Value> {
}Copy)]
276#[must_use = "Queries are only executed when calling `load`, `get_result`, or similar."]
277pub struct UncheckedBind<Query, Value> {
279 query: Query,
280 value: Value,
281}
282
283impl<Query, Value> UncheckedBind<Query, Value>
284where
285 Query: Expression,
286{
287 pub(crate) fn new(query: Query, value: Value) -> Self {
288 UncheckedBind { query, value }
289 }
290
291 pub fn sql(self, sql: &str) -> SqlLiteral<Query::SqlType, Self> {
337 SqlLiteral::new(sql.into(), self)
338 }
339}
340
341impl<Query, Value> Expression for UncheckedBind<Query, Value>
342where
343 Query: Expression,
344{
345 type SqlType = Query::SqlType;
346}
347
348impl<Query, Value, DB> QueryFragment<DB> for UncheckedBind<Query, Value>
349where
350 DB: Backend,
351 Query: QueryFragment<DB>,
352 Value: QueryFragment<DB>,
353{
354 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
355 self.query.walk_ast(out.reborrow())?;
356 self.value.walk_ast(out.reborrow())?;
357 Ok(())
358 }
359}
360
361impl<Q, Value> Query for UncheckedBind<Q, Value>
362where
363 Q: Query,
364{
365 type SqlType = Q::SqlType;
366}
367
368impl<Query, Value, GB> ValidGrouping<GB> for UncheckedBind<Query, Value> {
369 type IsAggregate = is_aggregate::Never;
370}
371
372impl<QS, Query, Value> SelectableExpression<QS> for UncheckedBind<Query, Value> where
373 Self: AppearsOnTable<QS>
374{
375}
376
377impl<QS, Query, Value> AppearsOnTable<QS> for UncheckedBind<Query, Value> where Self: Expression {}
378
379impl<Query, Value> RunQueryDslSupport for UncheckedBind<Query, Value> {}
380
381mod private {
382 use crate::backend::{Backend, DieselReserveSpecialization};
383 use crate::query_builder::{QueryFragment, QueryId};
384
385 #[derive(#[automatically_derived]
impl ::core::fmt::Debug for Empty {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f, "Empty")
}
}Debug, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Empty { }
#[automatically_derived]
impl ::core::clone::Clone for Empty {
#[inline]
fn clone(&self) -> Empty { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Empty { }Copy, const _: () =
{
use diesel;
#[allow(non_camel_case_types)]
impl diesel::query_builder::QueryId for Empty {
type QueryId = Empty<>;
const HAS_STATIC_QUERY_ID: bool = true;
const IS_WINDOW_FUNCTION: bool = false;
}
};QueryId)]
386 pub struct Empty;
387
388 impl<DB> QueryFragment<DB> for Empty
389 where
390 DB: Backend + DieselReserveSpecialization,
391 {
392 fn walk_ast<'b>(
393 &'b self,
394 _pass: crate::query_builder::AstPass<'_, 'b, DB>,
395 ) -> crate::QueryResult<()> {
396 Ok(())
397 }
398 }
399}