1use super::*;
35
36pub trait Add {
38 type Rhs: SqlType;
40 type Output: SqlType;
42}
43
44pub trait Sub {
46 type Rhs: SqlType;
48 type Output: SqlType;
50}
51
52pub trait Mul {
54 type Rhs: SqlType;
56 type Output: SqlType;
58}
59
60pub trait Div {
62 type Rhs: SqlType;
64 type Output: SqlType;
66}
67
68macro_rules! numeric_type {
69 ($($tpe: ident),*) => {
70 $(
71 impl Add for $tpe {
72 type Rhs = $tpe;
73 type Output = $tpe;
74 }
75
76 impl Sub for $tpe {
77 type Rhs = $tpe;
78 type Output = $tpe;
79 }
80
81 impl Mul for $tpe {
82 type Rhs = $tpe;
83 type Output = $tpe;
84 }
85
86 impl Div for $tpe {
87 type Rhs = $tpe;
88 type Output = $tpe;
89 }
90 )*
91 }
92}
93
94numeric_type!(SmallInt, Integer, BigInt, Float, Double, Numeric);
95
96impl Add for Time {
97 type Rhs = Interval;
98 type Output = Time;
99}
100
101impl Sub for Time {
102 type Rhs = Interval;
103 type Output = Time;
104}
105
106impl Add for Date {
107 type Rhs = Interval;
108 type Output = Timestamp;
109}
110
111impl Sub for Date {
112 type Rhs = Interval;
113 type Output = Timestamp;
114}
115
116impl Add for Timestamp {
117 type Rhs = Interval;
118 type Output = Timestamp;
119}
120
121impl Sub for Timestamp {
122 type Rhs = Interval;
123 type Output = Timestamp;
124}
125
126impl Add for Interval {
127 type Rhs = Interval;
128 type Output = Interval;
129}
130
131impl Sub for Interval {
132 type Rhs = Interval;
133 type Output = Interval;
134}
135
136impl Mul for Interval {
137 type Rhs = Integer;
138 type Output = Interval;
139}
140
141impl Div for Interval {
142 type Rhs = Integer;
143 type Output = Interval;
144}
145
146impl<T> Add for Nullable<T>
147where
148 T: Add + SqlType<IsNull = is_nullable::NotNull>,
149 T::Rhs: SqlType<IsNull = is_nullable::NotNull>,
150 T::Output: SqlType<IsNull = is_nullable::NotNull>,
151{
152 type Rhs = Nullable<T::Rhs>;
153 type Output = Nullable<T::Output>;
154}
155
156impl<T> Sub for Nullable<T>
157where
158 T: Sub + SqlType<IsNull = is_nullable::NotNull>,
159 T::Rhs: SqlType<IsNull = is_nullable::NotNull>,
160 T::Output: SqlType<IsNull = is_nullable::NotNull>,
161{
162 type Rhs = Nullable<T::Rhs>;
163 type Output = Nullable<T::Output>;
164}
165
166impl<T> Mul for Nullable<T>
167where
168 T: Mul + SqlType<IsNull = is_nullable::NotNull>,
169 T::Rhs: SqlType<IsNull = is_nullable::NotNull>,
170 T::Output: SqlType<IsNull = is_nullable::NotNull>,
171{
172 type Rhs = Nullable<T::Rhs>;
173 type Output = Nullable<T::Output>;
174}
175
176impl<T> Div for Nullable<T>
177where
178 T: Div + SqlType<IsNull = is_nullable::NotNull>,
179 T::Rhs: SqlType<IsNull = is_nullable::NotNull>,
180 T::Output: SqlType<IsNull = is_nullable::NotNull>,
181{
182 type Rhs = Nullable<T::Rhs>;
183 type Output = Nullable<T::Output>;
184}