diff --git a/src/FSharp.AWS.DynamoDB/TableContext.fs b/src/FSharp.AWS.DynamoDB/TableContext.fs index e24dea8..6022a84 100644 --- a/src/FSharp.AWS.DynamoDB/TableContext.fs +++ b/src/FSharp.AWS.DynamoDB/TableContext.fs @@ -866,7 +866,6 @@ type TableContext<'TRecord> internal return () } - member internal _.InternalDescribe() : Async = let rec wait () = async { let! ct = Async.CancellationToken @@ -881,7 +880,7 @@ type TableContext<'TRecord> internal } wait () - member internal __.CreateOrValidateTableAsync(createThroughput) : Async = + member internal __.InternalProvision(?makeCreateTableRequest) : Async = let (|Conflict|_|) (e : exn) = match e with | :? AmazonDynamoDBException as e when e.StatusCode = HttpStatusCode.Conflict -> Some() @@ -898,11 +897,10 @@ type TableContext<'TRecord> internal |> invalidOp return desc - | Choice2Of2 (:? ResourceNotFoundException) when Option.isSome createThroughput -> + | Choice2Of2 (:? ResourceNotFoundException) when Option.isSome makeCreateTableRequest -> let! ct = Async.CancellationToken - let ctr = template.Info.Schemata.CreateCreateTableRequest(tableName, Option.get createThroughput) let! response = - client.CreateTableAsync(ctr, ct) + client.CreateTableAsync(makeCreateTableRequest.Value (), ct) |> Async.AwaitTaskCorrect |> Async.Catch @@ -923,26 +921,17 @@ type TableContext<'TRecord> internal checkOrCreate 9 // up to 9 retries, i.e. 10 attempts before we let exception propagate - /// - /// Asynchronously verify that the table exists and is compatible with record key schema. - /// - /// Create the table instance now instance if it does not exist. Defaults to false. - /// Provisioned throughput for the table if newly created. Defaults to (10,10). - [] - member __.VerifyTableAsync(?createIfNotExists : bool, ?provisionedThroughput : ProvisionedThroughput) : Async = - let throughputIfCreate = - if createIfNotExists = Some true then - let throughput = match provisionedThroughput with Some p -> p | None -> ProvisionedThroughput(10L, 10L) - Some throughput - else None - __.CreateOrValidateTableAsync(throughputIfCreate) |> Async.Ignore + member internal _.InternalCreateTableRequest(throughput) = + template.Info.Schemata.CreateCreateTableRequest(tableName, throughput) + member internal t.InternalCreateOrValidateTableAsync(createThroughput) = + t.InternalProvision(fun () -> t.InternalCreateTableRequest(createThroughput)) /// /// Asynchronously verify that the table exists and is compatible with record key schema, or throw.
/// See also InitializeTableAsync, which performs the same check, but can create or re-provision the Table if required. ///
member __.VerifyTableAsync() : Async = - __.CreateOrValidateTableAsync(None) |> Async.Ignore + __.InternalProvision() |> Async.Ignore /// /// Asynchronously verifies that the table exists and is compatible with record key schema, throwing if it is incompatible.
@@ -950,8 +939,8 @@ type TableContext<'TRecord> internal /// See also VerifyTableAsync, which only verifies the Table is present and correct. ///
/// Provisioned throughput to use for the table. - member __.InitializeTableAsync(throughput : ProvisionedThroughput) : Async = - __.CreateOrValidateTableAsync(Some throughput) |> Async.Ignore + member t.InitializeTableAsync(throughput : ProvisionedThroughput) : Async = + t.InternalCreateOrValidateTableAsync(throughput) |> Async.Ignore /// /// Asynchronously verifies that the table exists and is compatible with record key schema, throwing if it is incompatible.
@@ -959,12 +948,24 @@ type TableContext<'TRecord> internal /// If it is present, and the throughput is not as specified, uses UpdateProvisionedThroughputAsync to update it.
///
/// Provisioned throughput to use for the table. - member __.ProvisionTableAsync(throughput : ProvisionedThroughput) : Async = async { - let! desc = __.CreateOrValidateTableAsync(Some throughput) - let provisioned = desc.ProvisionedThroughput - if throughput.ReadCapacityUnits <> provisioned.ReadCapacityUnits - || throughput.WriteCapacityUnits <> provisioned.WriteCapacityUnits then - do! __.UpdateProvisionedThroughputAsync(throughput) } + member t.ProvisionTableAsync(throughput : ProvisionedThroughput) : Async = async { + let! tableDescription = t.InternalCreateOrValidateTableAsync(throughput) + let provisioned = tableDescription.ProvisionedThroughput + if throughput.ReadCapacityUnits <> provisioned.ReadCapacityUnits || throughput.WriteCapacityUnits <> provisioned.WriteCapacityUnits then + do! t.UpdateProvisionedThroughputAsync(throughput) } + + /// + /// Asynchronously verify that the table exists and is compatible with record key schema. + /// + /// Create the table instance now instance if it does not exist. Defaults to false. + /// Provisioned throughput for the table if newly created. Defaults to (10,10). + [] + member t.VerifyTableAsync(?createIfNotExists : bool, ?provisionedThroughput : ProvisionedThroughput) : Async = + if createIfNotExists = Some true then + let throughput = match provisionedThroughput with Some p -> p | None -> ProvisionedThroughput(10L, 10L) + t.InitializeTableAsync(throughput) + else + t.VerifyTableAsync() // Deprecated factory method, to be removed. Replaced with // 1. TableContext<'T> ctor (synchronous)