@@ -5,40 +5,50 @@ public struct WithSessionResult<ResultType: Sendable>: Sendable {
55 public let affectedTables : Set < String >
66}
77
8- /// Executes an action within a SQLite database connection session and handles its result.
8+ /// Executes an action within a SQLite database connection session and
9+ /// returns a `WithSessionResult` containing the action result and the set of
10+ /// tables that were affected during the session.
911///
10- /// The Raw SQLite connection is only available in some niche scenarios.
12+ /// The raw SQLite connection is only available in some niche scenarios. This helper is
13+ /// intended for internal use.
1114///
12- /// - Executes the provided action in a SQLite session
13- /// - Handles success/failure results
14- /// - Tracks table updates during execution
15- /// - Provides type-safe result handling
15+ /// - The provided `action` is executed inside a database session.
16+ /// - Any success or failure from the `action` is captured in
17+ /// `WithSessionResult.blockResult`.
18+ /// - The set of updated table names is returned in
19+ /// `WithSessionResult.affectedTables`.
1620///
1721/// Example usage:
1822/// ```swift
19- /// try withSession(db: database) {
20- /// return try someOperation()
21- /// } onComplete: { result, updates in
22- /// switch result {
23- /// case .success(let value):
24- /// print("Operation succeeded with: \(value)")
25- /// case .failure(let error):
26- /// print("Operation failed: \(error)")
27- /// }
23+ /// let result = try withSession(db: database) {
24+ /// // perform database work and return a value
25+ /// try someOperation()
2826/// }
27+ ///
28+ /// switch result.blockResult {
29+ /// case .success(let value):
30+ /// print("Operation succeeded with: \(value)")
31+ /// case .failure(let error):
32+ /// print("Operation failed: \(error)")
33+ /// }
34+ ///
35+ /// print("Updated tables: \(result.affectedTables)")
2936/// ```
3037///
3138/// - Parameters:
32- /// - db: The database connection pointer
33- /// - action: The operation to execute within the session
34- /// - onComplete: Callback that receives the operation result and set of updated tables
35- /// - Throws: Errors from session initialization or execution
39+ /// - db: The raw SQLite connection pointer used to open the session.
40+ /// - action: The operation to execute within the session. Its return value is
41+ /// propagated into `WithSessionResult.blockResult` on success.
42+ /// - Returns: A `WithSessionResult` containing the action's result and the set
43+ /// of affected table names.
44+ /// - Throws: Any error thrown while establishing the session or executing the
45+ /// provided `action`.
3646public func withSession< ReturnType> (
3747 db: OpaquePointer ,
38- action: @escaping ( ) throws -> ReturnType ,
48+ action: @escaping ( ) throws -> ReturnType
3949) throws -> WithSessionResult < ReturnType > {
4050 return try kotlinWithSession (
4151 db: db,
42- action: action,
52+ action: action
4353 )
4454}
0 commit comments