1+ using  Serilog . Ui . Core . Models ; 
2+ using  static  Serilog . Ui . Core . Models . SearchOptions ; 
3+ 
4+ namespace  Serilog . Ui . Core . QueryBuilder . Sql ; 
5+ 
6+ /// <summary> 
7+ /// Abstract class that provides methods to build SQL queries for fetching and counting logs. 
8+ /// </summary> 
9+ public  abstract  class  SqlQueryBuilder 
10+ { 
11+     /// <summary> 
12+     /// Builds a SQL query to fetch logs from the specified table. 
13+     /// </summary> 
14+     /// <typeparam name="T">The type of the log model.</typeparam> 
15+     /// <param name="columns">The column names used in the sink for logging.</param> 
16+     /// <param name="schema">The schema of the table.</param> 
17+     /// <param name="tableName">The name of the table.</param> 
18+     /// <param name="query">The query parameters for fetching logs.</param> 
19+     /// <returns>A SQL query string to fetch logs.</returns> 
20+     public  abstract  string  BuildFetchLogsQuery < T > ( SinkColumnNames  columns ,  string  schema ,  string  tableName ,  FetchLogsQuery  query )  where  T  :  LogModel ; 
21+ 
22+     /// <summary> 
23+     /// Builds a SQL query to count logs in the specified table. 
24+     /// </summary> 
25+     /// <typeparam name="T">The type of the log model.</typeparam> 
26+     /// <param name="columns">The column names used in the sink for logging.</param> 
27+     /// <param name="schema">The schema of the table.</param> 
28+     /// <param name="tableName">The name of the table.</param> 
29+     /// <param name="query">The query parameters for counting logs.</param> 
30+     /// <returns>A SQL query string to count logs.</returns> 
31+     public  abstract  string  BuildCountLogsQuery < T > ( SinkColumnNames  columns ,  string  schema ,  string  tableName ,  FetchLogsQuery  query )  where  T  :  LogModel ; 
32+ 
33+     /// <summary> 
34+     /// Generates a SQL sort clause based on the specified sort property and direction. 
35+     /// </summary> 
36+     /// <param name="columns">The column names used in the sink for logging.</param> 
37+     /// <param name="sortOn">The property to sort on.</param> 
38+     /// <param name="sortBy">The direction to sort by.</param> 
39+     /// <returns>A SQL sort clause string.</returns> 
40+     protected  static   string  GenerateSortClause ( SinkColumnNames  columns ,  SortProperty  sortOn ,  SortDirection  sortBy ) 
41+     { 
42+         var  sortPropertyName  =  sortOn  switch 
43+         { 
44+             SortProperty . Timestamp  =>  columns . Timestamp , 
45+             SortProperty . Level  =>  columns . Level , 
46+             SortProperty . Message  =>  columns . Message , 
47+             _ =>  columns . Timestamp 
48+         } ; 
49+ 
50+         return  $ "\" { sortPropertyName } \"  { sortBy . ToString ( ) . ToUpper ( ) } "; 
51+     } 
52+ } 
0 commit comments