diff --git a/Supabase/Client.cs b/Supabase/Client.cs index 3f6e6772..d0e93ddc 100644 --- a/Supabase/Client.cs +++ b/Supabase/Client.cs @@ -280,5 +280,82 @@ internal Dictionary GetAuthHeaders() return headers; } +///// + /// + /// Executes multiple database operations as a single transaction. + /// + /// A list of operations to execute in a transaction. + /// Optional configuration for the transaction. + /// A response containing the results of all operations. + public async Task ExecuteBatchTransactionAsync(List operations, BatchOptions? options = null) + { + options ??= new BatchOptions { Atomic = true }; + + // Prepare the batch request + var batch = new BatchRequest + { + Operations = operations, + Options = options + }; + + // Send the batch request to the Postgrest client + var response = await Postgrest.ExecuteBatchAsync(batch); + + // Process results and return + return response; + } + + /// + /// Represents a database operation to be included in a batch transaction. + /// + public class PostgrestOperation + { + /// + /// The method to execute (INSERT, UPDATE, DELETE, SELECT). + /// + public string Method { get; set; } = string.Empty; + + /// + /// The table name to operate on. + /// + public string Table { get; set; } = string.Empty; + + /// + /// The query parameters. + /// + public Dictionary? Parameters { get; set; } + + /// + /// The data to insert or update. + /// + public object? Payload { get; set; } + } + + /// + /// Configuration options for batch operations. + /// + public class BatchOptions + { + /// + /// When true, all operations are executed in a single transaction. + /// + public bool Atomic { get; set; } = true; + } + + /// + /// Response from a batch operation. + /// + public class BatchResponse + { + /// + /// Results from each operation in the batch. + /// + public List Results { get; set; } = new List(); + + /// + /// Status of each operation. + /// + public List Status { get; set; } = new List(); + } } }