@@ -19,6 +19,19 @@ type ResourceNotFoundException = Amazon.DynamoDBv2.Model.ResourceNotFoundExcepti
19
19
/// Represents the provisioned throughput for given table or index
20
20
type ProvisionedThroughput = Amazon.DynamoDBv2.Model.ProvisionedThroughput
21
21
22
+ /// Represents the throughput configuration for a Table
23
+ type Throughput =
24
+ | Provisioned of ProvisionedThroughput
25
+ | OnDemand
26
+ module internal Throughput =
27
+ let applyToCreateRequest ( req : CreateTableRequest ) = function
28
+ | Provisioned t ->
29
+ req.ProvisionedThroughput <- t
30
+ for gsi in req.GlobalSecondaryIndexes do
31
+ gsi.ProvisionedThroughput <- t
32
+ | OnDemand ->
33
+ req.BillingMode <- BillingMode.PAY_ PER_ REQUEST
34
+
22
35
/// Represents the operation performed on the table, for metrics collection purposes
23
36
type Operation = GetItem | PutItem | UpdateItem | DeleteItem | BatchGetItems | BatchWriteItems | Scan | Query
24
37
@@ -973,10 +986,13 @@ type TableContext<'TRecord> internal
973
986
974
987
checkOrCreate 9 // up to 9 retries, i.e. 10 attempts before we let exception propagate
975
988
976
- member internal _.InternalCreateTableRequest ( throughput ) =
977
- template.Info.Schemata.CreateCreateTableRequest( tableName, throughput)
978
- member internal t.InternalCreateOrValidateTableAsync ( createThroughput ) =
979
- t.InternalProvision( fun () -> t.InternalCreateTableRequest( createThroughput))
989
+ member internal _.InternalCreateTableRequest ( applyThroughput ) =
990
+ let req = template.Info.Schemata.CreateCreateTableRequest( tableName)
991
+ applyThroughput req
992
+ req
993
+
994
+ member internal t.InternalCreateOrValidateTableAsync ( throughput ) =
995
+ t.InternalProvision( fun () -> t.InternalCreateTableRequest( fun r -> Throughput.applyToCreateRequest r throughput))
980
996
981
997
/// <summary>
982
998
/// Asynchronously verify that the table exists and is compatible with record key schema, or throw.<br/>
@@ -990,21 +1006,24 @@ type TableContext<'TRecord> internal
990
1006
/// If the table is not present, it is provisioned, with the specified <c>throughput</c>.<br/>
991
1007
/// See also <c>VerifyTableAsync</c>, which only verifies the Table is present and correct.
992
1008
/// </summary>
993
- /// <param name="throughput">Provisioned throughput to use for the table.</param>
994
- member t.InitializeTableAsync ( throughput : ProvisionedThroughput ) : Async < unit > =
1009
+ /// <param name="throughput">Throughput configuration to use for the table.</param>
1010
+ member t.InitializeTableAsync ( throughput : Throughput ) : Async < unit > =
995
1011
t.InternalCreateOrValidateTableAsync( throughput) |> Async.Ignore
996
1012
997
1013
/// <summary>
998
1014
/// Asynchronously verifies that the table exists and is compatible with record key schema, throwing if it is incompatible.<br/>
999
1015
/// If the table is not present, it is provisioned, with the specified <c>throughput</c>.<br/>
1000
1016
/// If it is present, and the throughput is not as specified, uses <c>UpdateProvisionedThroughputAsync</c> to update it. <br/>
1001
1017
/// </summary>
1002
- /// <param name="throughput">Provisioned throughput to use for the table.</param>
1003
- member t.ProvisionTableAsync ( throughput : ProvisionedThroughput ) : Async < unit > = async {
1018
+ /// <param name="throughput">Throughput configuration to use for the table.</param>
1019
+ member t.ProvisionTableAsync ( throughput : Throughput ) : Async < unit > = async {
1004
1020
let! tableDescription = t.InternalCreateOrValidateTableAsync( throughput)
1005
- let provisioned = tableDescription.ProvisionedThroughput
1006
- if throughput.ReadCapacityUnits <> provisioned.ReadCapacityUnits || throughput.WriteCapacityUnits <> provisioned.WriteCapacityUnits then
1007
- do ! t.UpdateProvisionedThroughputAsync( throughput) }
1021
+ match throughput with
1022
+ | Provisioned p ->
1023
+ let current = tableDescription.ProvisionedThroughput
1024
+ if p.ReadCapacityUnits <> current.ReadCapacityUnits || p.WriteCapacityUnits <> current.WriteCapacityUnits then
1025
+ do ! t.UpdateProvisionedThroughputAsync p
1026
+ | OnDemand -> () }
1008
1027
1009
1028
/// <summary>
1010
1029
/// Asynchronously verify that the table exists and is compatible with record key schema.
@@ -1015,7 +1034,7 @@ type TableContext<'TRecord> internal
1015
1034
member t.VerifyTableAsync (? createIfNotExists : bool , ? provisionedThroughput : ProvisionedThroughput ) : Async < unit > =
1016
1035
if createIfNotExists = Some true then
1017
1036
let throughput = match provisionedThroughput with Some p -> p | None -> ProvisionedThroughput( 10 L, 10 L)
1018
- t.InitializeTableAsync( throughput)
1037
+ t.InitializeTableAsync( Provisioned throughput)
1019
1038
else
1020
1039
t.VerifyTableAsync()
1021
1040
@@ -1043,7 +1062,7 @@ type TableContext internal () =
1043
1062
let context = TableContext< 'TRecord>( client, tableName, ?metricsCollector = metricsCollector)
1044
1063
if createIfNotExists = Some true then
1045
1064
let throughput = match provisionedThroughput with Some p -> p | None -> ProvisionedThroughput( 10 L, 10 L)
1046
- do ! context.InitializeTableAsync throughput
1065
+ do ! context.InitializeTableAsync( Throughput.Provisioned throughput)
1047
1066
elif verifyTable <> Some false then
1048
1067
do ! context.VerifyTableAsync()
1049
1068
return context }
0 commit comments