Skip to main content

easy_sql/markers/
query.rs

1use easy_macros::always_context;
2
3use crate::{Driver, traits::ToConvert};
4
5#[always_context]
6/// Indicates that a table type participates in the current query context.
7///
8/// Implemented by the table macros; avoid manual implementations.
9#[diagnostic::on_unimplemented(
10    message = "Type `{T}` is not a part of requested tables clause in this query, nor it is not an Output type (or using columns from Output type might not be supported in this position)"
11)]
12pub trait HasTable<T> {}
13
14#[always_context]
15/// Indicates that a joined table is optional and columns should be wrapped in `Option`.
16///
17/// Implemented by the join/output macros; avoid manual implementations.
18pub trait HasTableJoined<T> {
19    type MaybeOption<Y>;
20
21    fn into_maybe_option<Y>(t: Y) -> Self::MaybeOption<Y>;
22}
23
24#[always_context]
25/// Marker for row types supported by `query_lazy!` streaming output.
26///
27/// Implemented by driver integrations for their row types.
28#[diagnostic::on_unimplemented(
29    message = "Only types representing single row are allowed as output in query_lazy! calls."
30)]
31pub trait ToConvertSingle<D: Driver>: ToConvert<D> + sqlx::Row {}
32
33#[diagnostic::on_unimplemented(
34    message = "Providing arguments for the selected output type is required. Tip: add parentheses with the inputs, after the selected output type, Example: {Self}(\"Example joined string start: \" || joined_column, 26)"
35)]
36/// Marker for outputs without custom select arguments.
37///
38/// Implemented by the [`Output`](macro@crate::Output) derive macro.
39pub trait NormalSelect {}
40
41#[diagnostic::on_unimplemented(
42    message = "Selected output type is not requesting any input arguments. Tip: remove parentheses with the inputs, after the selected output type"
43)]
44/// Marker for outputs that require custom select arguments.
45///
46/// Implemented by the [`Output`](macro@crate::Output) derive macro.
47pub trait WithArgsSelect {}
48
49/// Marker trait for tables that are not created via [`table_join!`](crate::table_join).
50///
51/// Implemented by the table macros; avoid manual implementations.
52#[diagnostic::on_unimplemented(message = "UPDATE and DELETE queries do not support joined tables.")]
53pub trait NotJoinedTable {}
54
55/// Support trait providing fields information for query validation.
56///
57/// Implemented by the [`Output`](macro@crate::Output) derive macro and used internally by the query
58/// macros.
59pub trait OutputData<Table> {
60    type SelectProvider;
61}
62
63impl<T: OutputData<Table>, Table> OutputData<Table> for Vec<T> {
64    type SelectProvider = T::SelectProvider;
65}
66
67impl<T: OutputData<Table>, Table> OutputData<Table> for Option<T> {
68    type SelectProvider = T::SelectProvider;
69}
70impl<Table> OutputData<Table> for () {
71    type SelectProvider = ();
72}