Skip to content

Commit 3f45987

Browse files
CopilotThorium
andcommitted
Add XML documentation for runtime types and transaction support
Co-authored-by: Thorium <229355+Thorium@users.noreply.github.com>
1 parent cf80b72 commit 3f45987

3 files changed

Lines changed: 139 additions & 4 deletions

File tree

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 {

src/SQLProvider.Common/SqlRuntime.Common.fs

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,57 @@ open Microsoft.FSharp.Reflection
1616
open System.Collections.Concurrent
1717
open System.Runtime.Serialization
1818

19+
/// <summary>
20+
/// Specifies the database provider type for the SQL type provider.
21+
/// Each provider has its own specific implementation for SQL generation and data type mapping.
22+
/// </summary>
1923
type DatabaseProviderTypes =
24+
/// Microsoft SQL Server using SqlClient provider
2025
| MSSQLSERVER = 0
26+
/// SQLite database using System.Data.SQLite or Microsoft.Data.Sqlite
2127
| SQLITE = 1
28+
/// PostgreSQL using Npgsql provider
2229
| POSTGRESQL = 2
30+
/// MySQL using MySql.Data or MySqlConnector provider
2331
| MYSQL = 3
32+
/// Oracle Database using Oracle.ManagedDataAccess provider
2433
| ORACLE = 4
34+
/// Microsoft Access using OleDb provider
2535
| MSACCESS = 5
36+
/// Generic ODBC provider for various databases
2637
| ODBC = 6
38+
/// Firebird database using FirebirdSql.Data.FirebirdClient
2739
| FIREBIRD = 7
40+
/// Microsoft SQL Server with dynamic schema loading
2841
| MSSQLSERVER_DYNAMIC = 8
42+
/// Microsoft SQL Server using SSDT/DacPac for schema
2943
| MSSQLSERVER_SSDT = 9
44+
/// DuckDB using DuckDB.NET provider
3045
| DUCKDB = 10
46+
/// External/custom database provider
3147
| EXTERNAL = 11
3248

33-
type RelationshipDirection = Children = 0 | Parents = 1
49+
/// <summary>Specifies the direction for relationship navigation.</summary>
50+
type RelationshipDirection =
51+
/// Navigate to child records (foreign key relationships)
52+
Children = 0
53+
/// Navigate to parent records (primary key relationships)
54+
| Parents = 1
3455

56+
/// <summary>
57+
/// Specifies how to handle case sensitivity when generating table and column names.
58+
/// </summary>
3559
type CaseSensitivityChange =
60+
/// Keep original casing from the database
3661
| ORIGINAL = 0
62+
/// Convert all names to uppercase
3763
| TOUPPER = 1
64+
/// Convert all names to lowercase
3865
| TOLOWER = 2
3966

67+
/// <summary>
68+
/// Specifies how to represent nullable database columns in the generated types.
69+
/// </summary>
4070
type NullableColumnType =
4171
/// Nullable types are just Unchecked default. (Old false.)
4272
| NO_OPTION = 0
@@ -45,7 +75,11 @@ type NullableColumnType =
4575
/// ValueOption is more performant.
4676
| VALUE_OPTION = 2
4777

78+
/// <summary>
79+
/// Specifies the quote character style for ODBC connections when dealing with table and column names containing spaces or special characters.
80+
/// </summary>
4881
type OdbcQuoteCharacter =
82+
/// Use default quoting for the ODBC driver
4983
| DEFAULT_QUOTE = 0
5084
/// MySQL/Postgre style: `alias`
5185
| GRAVE_ACCENT = 1
@@ -58,6 +92,10 @@ type OdbcQuoteCharacter =
5892
/// Single quote: 'alias'
5993
| APHOSTROPHE = 5
6094

95+
/// <summary>
96+
/// Specifies which SQLite library to use for connections.
97+
/// Different libraries may have different capabilities and platform support.
98+
/// </summary>
6199
type SQLiteLibrary =
62100
/// .NET Framework default
63101
| SystemDataSQLite = 0
@@ -68,8 +106,16 @@ type SQLiteLibrary =
68106
/// Microsoft.Data.Sqlite. May support .NET Standard 2.0 contract in the future.
69107
| MicrosoftDataSqlite = 3
70108

109+
/// <summary>
110+
/// Contains events for monitoring SQL query execution and debugging.
111+
/// Use these events to log, debug, or analyze the SQL queries generated by the type provider.
112+
/// </summary>
71113
module public QueryEvents =
72114

115+
/// <summary>
116+
/// Contains information about a SQL command being executed, including the command text,
117+
/// parameters, and connection information for debugging and monitoring purposes.
118+
/// </summary>
73119
type SqlEventData = {
74120
/// The text of the SQL command being executed.
75121
Command: string
@@ -112,8 +158,18 @@ module public QueryEvents =
112158

113159
let private sqlEvent = Event<SqlEventData>()
114160

115-
/// This event fires immediately before the execution of every generated query.
161+
/// <summary>
162+
/// Event that fires immediately before the execution of every generated query.
116163
/// Listen to this event to display or debug the content of your queries.
164+
/// This is useful for logging, performance monitoring, and debugging SQL generation.
165+
/// </summary>
166+
/// <example>
167+
/// <code>
168+
/// QueryEvents.SqlQueryEvent.Add(fun event ->
169+
/// printfn "Executing: %s" event.Command
170+
/// printfn "Parameters: %A" event.Parameters)
171+
/// </code>
172+
/// </example>
117173
[<CLIEvent>]
118174
let SqlQueryEvent = sqlEvent.Publish
119175

@@ -150,13 +206,26 @@ module public QueryEvents =
150206
let internal PublishExpression(e) = expressionEvent.Trigger(e)
151207

152208
[<Struct>]
209+
/// <summary>
210+
/// Represents the current state of a database entity for change tracking purposes.
211+
/// Used internally by the SQL provider to determine what operations need to be performed during SubmitUpdates().
212+
/// </summary>
153213
type EntityState =
214+
/// Entity has not been modified since it was loaded
154215
| Unchanged
216+
/// Entity is new and should be inserted into the database
155217
| Created
218+
/// Entity has been modified; contains list of changed column names
156219
| Modified of string list
220+
/// Entity is marked for deletion (soft delete)
157221
| Delete
222+
/// Entity has been deleted from the database
158223
| Deleted
159224

225+
/// <summary>
226+
/// Specifies how to handle conflicts when inserting records with duplicate primary keys.
227+
/// Currently supported only on databases that have UPSERT capabilities.
228+
/// </summary>
160229
[<Struct>]
161230
type OnConflict =
162231
/// Throws an exception if the primary key already exists (default behaviour).
@@ -168,18 +237,40 @@ type OnConflict =
168237
/// Currently supported only on PostgreSQL 9.5+
169238
| DoNothing
170239

240+
/// <summary>
241+
/// Attribute for mapping entity properties to database columns with different names.
242+
/// Use this when your database column name differs from your preferred F# property name.
243+
/// </summary>
244+
/// <example>
245+
/// <code>
246+
/// [&lt;MappedColumn("customer_id")&gt;]
247+
/// member x.CustomerId = x.GetColumn&lt;int&gt;("customer_id")
248+
/// </code>
249+
/// </example>
171250
type MappedColumnAttribute(name: string) =
172251
inherit Attribute()
252+
/// Gets the database column name this property maps to
173253
member x.Name with get() = name
174254

255+
/// <summary>Represents a result set as a sequence of rows, where each row is an array of column name-value pairs.</summary>
175256
type ResultSet = seq<(string * obj)[]>
257+
258+
/// <summary>Represents different types of result sets that can be returned from stored procedures.</summary>
176259
type ReturnSetType =
260+
/// A single scalar value with name and value
177261
| ScalarResultSet of string * obj
262+
/// A result set with name and data rows
178263
| ResultSet of string * ResultSet
264+
265+
/// <summary>Represents different types of return values from stored procedures and functions.</summary>
179266
type ReturnValueType =
267+
/// No return value (void)
180268
| Unit
269+
/// A single scalar value
181270
| Scalar of string * obj
271+
/// A single result set
182272
| SingleResultSet of string * ResultSet
273+
/// Multiple result sets
183274
| Set of seq<ReturnSetType>
184275

185276
/// Interface to hide internal members that are typically not needed by the user
@@ -478,6 +569,11 @@ type SqlEntity(dc: ISqlDataContext, tableName, columns: ColumnLookup, activeColu
478569
override __.ShouldSerializeValue(_) = false })
479570
|> Seq.cast<PropertyDescriptor> |> Seq.toArray )
480571

572+
/// <summary>
573+
/// The main interface for SQL data context operations. This interface provides all the core functionality
574+
/// for querying, creating, updating, and deleting data through the SQL type provider.
575+
/// Users typically access this through the generated GetDataContext() method.
576+
/// </summary>
481577
and ISqlDataContext =
482578
/// Connection string to database
483579
abstract ConnectionString : string
@@ -520,8 +616,12 @@ and ISqlDataContext =
520616
/// Context meant to be read operations only
521617
abstract IsReadOnly : bool
522618

523-
/// This is publically exposed and used in the runtime
619+
/// <summary>
620+
/// Interface implemented by generated types that provide access to the underlying data context.
621+
/// This allows access to the ISqlDataContext for advanced operations.
622+
/// </summary>
524623
type IWithDataContext =
624+
/// Gets the underlying SQL data context
525625
abstract DataContext : ISqlDataContext
526626

527627
/// LinkData is for joins with SelectMany

src/SQLProvider.Common/SqlRuntime.Transactions.fs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,43 @@ namespace FSharp.Data.Sql.Transactions
22

33
open System
44

5-
/// Corresponds to the System.Transactions.IsolationLevel.
5+
/// <summary>
6+
/// Transaction isolation level for database operations.
7+
/// Corresponds to the System.Transactions.IsolationLevel but provides SQL provider specific functionality.
8+
/// </summary>
69
type IsolationLevel =
10+
/// Highest isolation level - transactions are completely isolated from each other
711
| Serializable = 0
12+
/// Prevents dirty reads and non-repeatable reads, but phantom reads can occur
813
| RepeatableRead = 1
14+
/// Prevents dirty reads but allows non-repeatable reads and phantom reads (default for most databases)
915
| ReadCommitted = 2
16+
/// Allows dirty reads, non-repeatable reads, and phantom reads (fastest but least safe)
1017
| ReadUncommitted = 3
18+
/// SQL Server specific - provides statement-level read consistency using versioning
1119
| Snapshot = 4
20+
/// Allows any level of isolation, including overlapping changes (SQL Server specific)
1221
| Chaos = 5
22+
/// Use the default isolation level of the database
1323
| Unspecified = 6
24+
/// Special value to indicate that no transaction should be created
1425
| DontCreateTransaction = 99
1526

27+
/// <summary>
28+
/// Configuration options for database transactions.
1629
/// Corresponds to the System.Transactions.TransactionOptions.
30+
/// </summary>
1731
[<Struct>]
1832
type TransactionOptions = {
33+
/// Maximum time the transaction can remain active before timing out
1934
Timeout : TimeSpan
35+
/// The isolation level for the transaction
2036
IsolationLevel : IsolationLevel
2137
}
2238

39+
/// <summary>
40+
/// Utility functions for converting between different transaction isolation level representations.
41+
/// </summary>
2342
module TransactionUtils =
2443
let internal toSystemTransactionsIsolationLevel isolationLevel =
2544
match isolationLevel with
@@ -32,6 +51,12 @@ module TransactionUtils =
3251
| IsolationLevel.Unspecified -> System.Transactions.IsolationLevel.Unspecified
3352
| _ -> failwithf "Unhandled IsolationLevel value: %A." isolationLevel
3453

54+
/// <summary>
55+
/// Converts SQL provider isolation level to System.Data.IsolationLevel.
56+
/// Use this when you need to work directly with ADO.NET connection transactions.
57+
/// </summary>
58+
/// <param name="isolationLevel">The SQL provider isolation level</param>
59+
/// <returns>The corresponding System.Data.IsolationLevel</returns>
3560
let toSystemDataIsolationLevel isolationLevel =
3661
match isolationLevel with
3762
| IsolationLevel.Serializable -> System.Data.IsolationLevel.Serializable

0 commit comments

Comments
 (0)