@@ -14,14 +14,14 @@ pub struct Env<'a> {
14
14
metadata : & ' a metadata:: Metadata ,
15
15
relationships : BTreeMap < String , models:: Relationship > ,
16
16
mutations_version : & ' a Option < metadata:: mutations:: MutationsVersion > ,
17
+ variables_table : Option < sql:: ast:: TableReference > ,
17
18
}
18
19
19
20
#[ derive( Debug ) ]
20
21
/// Stateful information changed throughout the translation process.
21
22
pub struct State {
22
23
native_queries : NativeQueries ,
23
24
global_table_index : TableAliasIndex ,
24
- variables_table : Option < sql:: ast:: TableReference > ,
25
25
}
26
26
27
27
#[ derive( Debug ) ]
@@ -94,11 +94,13 @@ impl<'a> Env<'a> {
94
94
metadata : & ' a metadata:: Metadata ,
95
95
relationships : BTreeMap < String , models:: Relationship > ,
96
96
mutations_version : & ' a Option < metadata:: mutations:: MutationsVersion > ,
97
+ variables_table : Option < sql:: ast:: TableReference > ,
97
98
) -> Env < ' a > {
98
99
Env {
99
100
metadata,
100
101
relationships,
101
102
mutations_version,
103
+ variables_table,
102
104
}
103
105
}
104
106
/// Lookup a collection's information in the metadata.
@@ -182,6 +184,15 @@ impl<'a> Env<'a> {
182
184
type_name : scalar_type. clone ( ) ,
183
185
} )
184
186
}
187
+
188
+ /// Try to get the variables table reference. This will fail if no variables were passed
189
+ /// as part of the query request.
190
+ pub fn get_variables_table ( & self ) -> Result < sql:: ast:: TableReference , Error > {
191
+ match & self . variables_table {
192
+ None => Err ( Error :: UnexpectedVariable ) ,
193
+ Some ( t) => Ok ( t. clone ( ) ) ,
194
+ }
195
+ }
185
196
}
186
197
187
198
impl CollectionInfo {
@@ -219,7 +230,6 @@ impl Default for State {
219
230
State {
220
231
native_queries : NativeQueries :: new ( ) ,
221
232
global_table_index : TableAliasIndex ( 0 ) ,
222
- variables_table : None ,
223
233
}
224
234
}
225
235
}
@@ -242,7 +252,6 @@ impl State {
242
252
let variables_table_alias = self . make_table_alias ( "%variables_table" . to_string ( ) ) ;
243
253
let table_reference =
244
254
sql:: ast:: TableReference :: AliasedTable ( variables_table_alias. clone ( ) ) ;
245
- self . variables_table = Some ( table_reference. clone ( ) ) ;
246
255
Some ( (
247
256
sql:: helpers:: from_variables ( variables_table_alias) ,
248
257
table_reference,
@@ -251,15 +260,6 @@ impl State {
251
260
}
252
261
}
253
262
254
- /// Try to get the variables table reference. This will fail if no variables were passed
255
- /// as part of the query request.
256
- pub fn get_variables_table ( & self ) -> Result < sql:: ast:: TableReference , Error > {
257
- match & self . variables_table {
258
- None => Err ( Error :: UnexpectedVariable ) ,
259
- Some ( t) => Ok ( t. clone ( ) ) ,
260
- }
261
- }
262
-
263
263
/// Introduce a new native query to the generated sql.
264
264
pub fn insert_native_query (
265
265
& mut self ,
0 commit comments