File tree Expand file tree Collapse file tree 3 files changed +63
-3
lines changed
Expand file tree Collapse file tree 3 files changed +63
-3
lines changed Original file line number Diff line number Diff line change 6464 "float8_field" : 1.23456789012345 ,
6565 "numeric_field" : 1234.5678 ,
6666 "date_field" : " 2023-07-19" ,
67- "ts_field" : " 2023-07-19T06:39:15.000Z " ,
67+ "ts_field" : " 2023-07-19T06:39:15" ,
6868 "tstz_field" : " 2023-07-19T06:39:15.000Z"
6969 },
7070 {
131131 "float8_field" : 1.23456789012345 ,
132132 "numeric_field" : 1234.5678 ,
133133 "date_field" : " 2023-07-19" ,
134- "ts_field" : " 2023-07-19T06:39:15.000Z " ,
134+ "ts_field" : " 2023-07-19T06:39:15" ,
135135 "tstz_field" : " 2023-07-19T06:39:15.000Z"
136136 }
137137 ]
Original file line number Diff line number Diff line change 1111data = json .loads (open ("data.json" ).read ())
1212
1313@router .get ("/{endpoint:path}" )
14- def endpoint ():
14+ def endpoint (
15+ endpoint : str ,
16+ id : str | None = None ,
17+ date_field : str | None = None ,
18+ ts_field : str | None = None ,
19+ tstz_field : str | None = None ,
20+ ):
21+ if id is None and date_field is None and ts_field is None and tstz_field is None :
22+ return data
23+
24+ def matches (item : dict ) -> bool :
25+ if id is not None and str (item .get ("id" )) != id :
26+ return False
27+ if date_field is not None and str (item .get ("date_field" )) != date_field :
28+ return False
29+ if ts_field is not None and str (item .get ("ts_field" )) != ts_field .replace (" " , "T" ):
30+ return False
31+ if tstz_field is not None and str (item .get ("tstz_field" ))[:10 ] != tstz_field [:10 ]:
32+ return False
33+ return True
34+
35+ if isinstance (data , list ):
36+ return [item for item in data if isinstance (item , dict ) and matches (item )]
37+
38+ if isinstance (data , dict ):
39+ if isinstance (data .get ("result" ), list ):
40+ return {
41+ ** data ,
42+ "result" : [
43+ item for item in data ["result" ]
44+ if isinstance (item , dict ) and matches (item )
45+ ],
46+ }
47+
48+ if matches (data ):
49+ return data
50+
51+ return {}
52+
1553 return data
1654
1755app = FastAPI ()
Original file line number Diff line number Diff line change @@ -41,6 +41,10 @@ mod tests {
4141 date_field date,
4242 ts_field timestamp,
4343 tstz_field timestamptz,
44+ _param_id text,
45+ _param_date_field date,
46+ _param_ts_field timestamp,
47+ _param_tstz_field timestamptz,
4448 _result text
4549 )
4650 SERVER logflare_server
@@ -66,6 +70,24 @@ mod tests {
6670 "f45121ea-1738-46c9-a506-9ee52ff8220f"
6771 ]
6872 ) ;
73+
74+ let results = c
75+ . select (
76+ "
77+ SELECT * FROM logflare_table
78+ WHERE _param_id = '84e1ed2a-3627-4d70-b311-c0e7c0bed313'
79+ AND _param_date_field = '2023-07-19'::date
80+ AND _param_ts_field = '2023-07-19T06:39:15'::timestamp
81+ AND _param_tstz_field = '2023-07-19T06:39:15.000Z'::timestamptz
82+ " ,
83+ None ,
84+ & [ ] ,
85+ )
86+ . unwrap ( )
87+ . filter_map ( |r| r. get_by_name :: < & str , _ > ( "id" ) . unwrap ( ) )
88+ . collect :: < Vec < _ > > ( ) ;
89+
90+ assert_eq ! ( results, vec![ "84e1ed2a-3627-4d70-b311-c0e7c0bed313" ] ) ;
6991 } ) ;
7092 }
7193}
You can’t perform that action at this time.
0 commit comments