Skip to content

Commit 913efda

Browse files
authored
Merge pull request #861 from fsprojects/copilot/add-xml-documentation-for-apis
Add comprehensive XML documentation for public APIs
2 parents 66b6496 + 3f45987 commit 913efda

6 files changed

Lines changed: 441 additions & 14 deletions

File tree

src/SQLProvider.Common/Operators.fs

Lines changed: 173 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,43 @@ namespace FSharp.Data.Sql
22

33
open System.Linq
44

5+
/// <summary>
6+
/// Represents SQL conditional operators used in WHERE clauses and query expressions.
7+
/// These operators are translated to their SQL equivalents when building database queries.
8+
/// </summary>
59
[<Struct>]
610
type ConditionOperator =
11+
/// SQL LIKE operator for pattern matching with wildcards
712
| Like
13+
/// SQL NOT LIKE operator for negated pattern matching
814
| NotLike
15+
/// SQL equality operator (=)
916
| Equal
17+
/// SQL inequality operator (<>)
1018
| NotEqual
19+
/// SQL greater than operator (>)
1120
| GreaterThan
21+
/// SQL less than operator (<)
1222
| LessThan
23+
/// SQL greater than or equal operator (>=)
1324
| GreaterEqual
25+
/// SQL less than or equal operator (<=)
1426
| LessEqual
27+
/// SQL IS NULL operator for checking null values
1528
| IsNull
29+
/// SQL IS NOT NULL operator for checking non-null values
1630
| NotNull
31+
/// SQL IN operator for membership testing
1732
| In
33+
/// SQL NOT IN operator for negated membership testing
1834
| NotIn
35+
/// SQL IN operator for nested subqueries
1936
| NestedIn
37+
/// SQL NOT IN operator for negated nested subqueries
2038
| NestedNotIn
39+
/// SQL EXISTS operator for subquery existence testing
2140
| NestedExists
41+
/// SQL NOT EXISTS operator for negated subquery existence testing
2242
| NestedNotExists
2343
with
2444
override x.ToString() =
@@ -42,127 +62,273 @@ type ConditionOperator =
4262
| NestedExists -> "EXISTS"
4363
| NestedNotExists -> "NOT EXISTS"
4464

65+
/// <summary>
66+
/// Represents SQL aggregate operations for GROUP BY clauses and data summarization.
67+
/// Each operation includes the column name to aggregate.
68+
/// </summary>
4569
[<Struct>]
4670
type AggregateOperation = // Aggregate (column name if not default)
71+
/// Groups results by the specified key column
4772
| KeyOp of key: string
73+
/// Finds the maximum value in the specified column
4874
| MaxOp of max: string
75+
/// Finds the minimum value in the specified column
4976
| MinOp of min: string
77+
/// Calculates the sum of values in the specified column
5078
| SumOp of sum: string
79+
/// Calculates the average of values in the specified column
5180
| AvgOp of avg: string
81+
/// Counts the number of rows in the specified column
5282
| CountOp of count: string
83+
/// Counts the number of distinct values in the specified column
5384
| CountDistOp of countDist: string
85+
/// Calculates the standard deviation of values in the specified column
5486
| StdDevOp of std: string
87+
/// Calculates the variance of values in the specified column
5588
| VarianceOp of var: string
5689

90+
/// <summary>
91+
/// Specifies where SELECT operations should be executed for query optimization.
92+
/// </summary>
5793
type SelectOperations =
94+
/// Execute the operation on the .NET client side
5895
| DotNetSide = 0
96+
/// Execute the operation on the database server side
5997
| DatabaseSide = 1
6098

6199
[<AutoOpenAttribute>]
62100
module ColumnSchema =
63101

64102
type alias = string
103+
/// <summary>
104+
/// Represents WHERE clause conditions for SQL queries.
105+
/// Supports complex boolean expressions with AND/OR operators and nested conditions.
106+
/// </summary>
65107
type Condition =
66108
// this is (table alias * column name * operator * right hand value ) list * (the same again list)
67109
// basically any AND or OR expression can have N terms and can have N nested condition children
68110
// this is largely from my CRM type provider. I don't think in practice for the SQL provider
69111
// you will ever have more than what is representable in a traditional binary expression tree, but
70112
// changing it would be a lot of effort ;)
113+
/// AND condition with a list of terms and optional nested conditions
71114
| And of (alias * SqlColumnType * ConditionOperator * obj option) list * (Condition list) option
115+
/// OR condition with a list of terms and optional nested conditions
72116
| Or of (alias * SqlColumnType * ConditionOperator * obj option) list * (Condition list) option
117+
/// Always evaluates to true
73118
| ConstantTrue
119+
/// Always evaluates to false
74120
| ConstantFalse
121+
/// Expression that cannot be translated to SQL
75122
| NotSupported of System.Linq.Expressions.Expression
76123

124+
/// <summary>
125+
/// Represents SQL functions and operations that can be applied to columns.
126+
/// These operations are translated to database-specific SQL functions.
127+
/// </summary>
77128
and CanonicalOp =
78129
//String functions
130+
/// Extracts a substring from the specified position to the end
79131
| Substring of SqlItemOrColumn
132+
/// Extracts a substring with specified start position and length
80133
| SubstringWithLength of SqlItemOrColumn*SqlItemOrColumn
134+
/// Converts string to uppercase
81135
| ToUpper
136+
/// Converts string to lowercase
82137
| ToLower
138+
/// Removes leading and trailing whitespace
83139
| Trim
140+
/// Returns the length of a string
84141
| Length
142+
/// Replaces occurrences of a substring with another substring
85143
| Replace of SqlItemOrColumn*SqlItemOrColumn
144+
/// Returns the index of the first occurrence of a substring
86145
| IndexOf of SqlItemOrColumn
146+
/// Returns the index of a substring starting from a specified position
87147
| IndexOfStart of SqlItemOrColumn*SqlItemOrColumn
88148
// Date functions
149+
/// Extracts the date part from a datetime value
89150
| Date
151+
/// Extracts the year from a datetime value
90152
| Year
153+
/// Extracts the month from a datetime value
91154
| Month
155+
/// Extracts the day from a datetime value
92156
| Day
157+
/// Extracts the hour from a datetime value
93158
| Hour
159+
/// Extracts the minute from a datetime value
94160
| Minute
161+
/// Extracts the second from a datetime value
95162
| Second
163+
/// Adds the specified number of years to a datetime value
96164
| AddYears of SqlItemOrColumn
165+
/// Adds the specified number of months to a datetime value
97166
| AddMonths of int
167+
/// Adds the specified number of days to a datetime value
98168
| AddDays of SqlItemOrColumn
169+
/// Adds the specified number of hours to a datetime value
99170
| AddHours of float
171+
/// Adds the specified number of minutes to a datetime value
100172
| AddMinutes of SqlItemOrColumn
173+
/// Adds the specified number of seconds to a datetime value
101174
| AddSeconds of float
175+
/// Calculates the difference in days between two datetime values
102176
| DateDiffDays of SqlItemOrColumn
177+
/// Calculates the difference in seconds between two datetime values
103178
| DateDiffSecs of SqlItemOrColumn
104179

105180
// Numerical functions
181+
/// Returns the absolute value of a number
106182
| Abs
183+
/// Returns the smallest integer greater than or equal to a number (ceiling)
107184
| Ceil
185+
/// Returns the largest integer less than or equal to a number (floor)
108186
| Floor
187+
/// Rounds a number to the nearest integer
109188
| Round
189+
/// Rounds a number to the specified number of decimal places
110190
| RoundDecimals of int
191+
/// Truncates a number to its integer part
111192
| Truncate
193+
/// Returns the square root of a number
112194
| Sqrt
195+
/// Returns the sine of an angle (in radians)
113196
| Sin
197+
/// Returns the cosine of an angle (in radians)
114198
| Cos
199+
/// Returns the tangent of an angle (in radians)
115200
| Tan
201+
/// Returns the arcsine of a number
116202
| ASin
203+
/// Returns the arccosine of a number
117204
| ACos
205+
/// Returns the arctangent of a number
118206
| ATan
207+
/// Raises a number to the power of another number
119208
| Pow of SqlItemOrColumn
209+
/// Raises a number to a constant power
120210
| PowConst of SqlItemOrColumn
211+
/// Returns the greatest value among the provided arguments
121212
| Greatest of SqlItemOrColumn
213+
/// Returns the smallest value among the provided arguments
122214
| Least of SqlItemOrColumn
123215
// Other
216+
/// Basic mathematical operation with a constant value
124217
| BasicMath of string*obj //operation, constant
218+
/// Left-side basic mathematical operation with a constant value
125219
| BasicMathLeft of string*obj //operation, constant
220+
/// Basic mathematical operation between columns
126221
| BasicMathOfColumns of string*string*SqlColumnType //operation, alias, column
222+
/// SQL CASE expression with condition and false value
127223
| CaseSql of Condition * SqlItemOrColumn // operation, if-false
224+
/// SQL CASE expression with negated condition and true value
128225
| CaseNotSql of Condition * SqlItemOrColumn // operation, if-true
226+
/// SQL CASE expression with condition and two constant values
129227
| CaseSqlPlain of Condition * obj * obj // with 2 constants
228+
/// Casts a value to VARCHAR type
130229
| CastVarchar
230+
/// Casts a value to INTEGER type
131231
| CastInt
132232

233+
/// <summary>
234+
/// Represents a column with optional operations applied to it.
235+
/// </summary>
133236
and SqlColumnType =
237+
/// A key column used for grouping or joining
134238
| KeyColumn of string
239+
/// A column with a canonical operation applied
135240
| CanonicalOperation of CanonicalOp * SqlColumnType
241+
/// A column used in aggregate operations
136242
| GroupColumn of AggregateOperation * SqlColumnType
137243

244+
/// <summary>
245+
/// Represents either a database column or a constant value in SQL expressions.
246+
/// </summary>
138247
// More recursion, because you mighn want to say e.g.
139248
// where (x.Substring(x.IndexOf("."), (x.Length-x.IndexOf("."))
140249
and SqlItemOrColumn =
250+
/// A database column with table alias and column type
141251
| SqlCol of string*SqlColumnType //alias*column
252+
/// A constant value to be used in SQL expressions
142253
| SqlConstant of obj
143254

255+
/// <summary>
256+
/// Represents parameters for SQL projections (SELECT clause elements).
257+
/// </summary>
144258
type ProjectionParameter =
259+
/// A direct entity column reference
145260
| EntityColumn of string
261+
/// A column with operations applied for computed expressions
146262
| OperationColumn of string*SqlColumnType//name*operations
147263

148264
// Dummy operators, these are placeholders that are replaced in the expression tree traversal with special server-side operations such as In, Like
149265
// The operators here are used to force the compiler to statically check against the correct types
266+
/// <summary>
267+
/// Contains custom SQL operators for use in query expressions.
268+
/// These operators are translated to their SQL equivalents during query compilation.
269+
/// </summary>
150270
[<AutoOpenAttribute>]
151271
module Operators =
152-
//// In
272+
/// <summary>
273+
/// SQL IN operator. Tests if a value exists in a sequence.
274+
/// Example: where (customer.Country |=| ["USA"; "Canada"])
275+
/// </summary>
276+
/// <param name="a">The value to test</param>
277+
/// <param name="b">The sequence to search in</param>
278+
/// <returns>Always false at compile time - replaced with SQL IN during query execution</returns>
153279
let (|=|) (a:'a) (b:'a seq) = false
154-
/// Not In
280+
281+
/// <summary>
282+
/// SQL NOT IN operator. Tests if a value does not exist in a sequence.
283+
/// Example: where (customer.Country |<>| ["USA"; "Canada"])
284+
/// </summary>
285+
/// <param name="a">The value to test</param>
286+
/// <param name="b">The sequence to search in</param>
287+
/// <returns>Always false at compile time - replaced with SQL NOT IN during query execution</returns>
155288
let (|<>|) (a:'a) (b:'a seq) = false
156-
/// Like
289+
290+
/// <summary>
291+
/// SQL LIKE operator for pattern matching with wildcards.
292+
/// Example: where (customer.Name =% "John%")
293+
/// </summary>
294+
/// <param name="a">The value to test</param>
295+
/// <param name="b">The pattern to match (use % and _ as wildcards)</param>
296+
/// <returns>Always false at compile time - replaced with SQL LIKE during query execution</returns>
157297
let (=%) (a:'a) (b:string) = false
158-
/// Not Like
298+
299+
/// <summary>
300+
/// SQL NOT LIKE operator for negated pattern matching.
301+
/// Example: where (customer.Name <>% "John%")
302+
/// </summary>
303+
/// <param name="a">The value to test</param>
304+
/// <param name="b">The pattern to reject</param>
305+
/// <returns>Always false at compile time - replaced with SQL NOT LIKE during query execution</returns>
159306
let (<>%) (a:'a) (b:string) = false
160-
/// Left join
307+
308+
/// Left join helper function for internal use
161309
let private leftJoin (a:'a) = a
310+
311+
/// <summary>
312+
/// Left outer join operator. Performs a left join on a related table.
313+
/// Example: for customer in ctx.Main.Customers do
314+
/// for order in (!!) customer.``main.Orders by CustomerID`` do
315+
/// </summary>
316+
/// <param name="a">The related table queryable</param>
317+
/// <returns>A queryable that performs a left outer join</returns>
162318
let (!!) (a:IQueryable<'a>) = query { for x in a do select (leftJoin x) }
163319

164-
/// Standard Deviation
320+
/// <summary>
321+
/// Calculates the standard deviation of numeric values in a column.
322+
/// Used in aggregate queries with groupBy.
323+
/// </summary>
324+
/// <param name="a">The column value</param>
325+
/// <returns>Always 1m at compile time - replaced with SQL STDDEV during query execution</returns>
165326
let StdDev (a:'a) = 1m
166327

167-
/// Variance
328+
/// <summary>
329+
/// Calculates the variance of numeric values in a column.
330+
/// Used in aggregate queries with groupBy.
331+
/// </summary>
332+
/// <param name="a">The column value</param>
333+
/// <returns>Always 1m at compile time - replaced with SQL VARIANCE during query execution</returns>
168334
let Variance (a:'a) = 1m

src/SQLProvider.Common/SqlRuntime.Async.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ open FSharp.Data.Sql.Common
88
open FSharp.Data.Sql.Patterns
99
open System.Linq
1010

11+
/// <summary>
12+
/// Provides asynchronous operations for SQL queries.
13+
/// Use these functions when you need to execute queries asynchronously to avoid blocking threads.
14+
/// </summary>
1115
module AsyncOperations =
1216

17+
/// <summary>
18+
/// Executes a queryable asynchronously and returns the results as a sequence.
19+
/// This is useful for executing large queries without blocking the calling thread.
20+
/// </summary>
21+
/// <param name="s">The queryable to execute</param>
22+
/// <returns>A task that yields a sequence of results</returns>
1323
let executeAsync (s:Linq.IQueryable<'T>) =
1424
let inline yieldseq (en: IEnumerator<'T>) =
1525
seq {

0 commit comments

Comments
 (0)