当前位置: 首页>>代码示例>>Python>>正文


Python TableConnection.create_table方法代码示例

本文整理汇总了Python中pynamodb.connection.TableConnection.create_table方法的典型用法代码示例。如果您正苦于以下问题:Python TableConnection.create_table方法的具体用法?Python TableConnection.create_table怎么用?Python TableConnection.create_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pynamodb.connection.TableConnection的用法示例。


在下文中一共展示了TableConnection.create_table方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_table

# 需要导入模块: from pynamodb.connection import TableConnection [as 别名]
# 或者: from pynamodb.connection.TableConnection import create_table [as 别名]
 def test_create_table(self):
     """
     TableConnection.create_table
     """
     conn = TableConnection(self.test_table_name)
     kwargs = {"read_capacity_units": 1, "write_capacity_units": 1}
     self.assertRaises(ValueError, conn.create_table, **kwargs)
     kwargs["attribute_definitions"] = [
         {"attribute_name": "key1", "attribute_type": "S"},
         {"attribute_name": "key2", "attribute_type": "S"},
     ]
     self.assertRaises(ValueError, conn.create_table, **kwargs)
     kwargs["key_schema"] = [
         {"attribute_name": "key1", "key_type": "hash"},
         {"attribute_name": "key2", "key_type": "range"},
     ]
     params = {
         "TableName": "ci-table",
         "ProvisionedThroughput": {"WriteCapacityUnits": 1, "ReadCapacityUnits": 1},
         "AttributeDefinitions": [
             {"AttributeType": "S", "AttributeName": "key1"},
             {"AttributeType": "S", "AttributeName": "key2"},
         ],
         "KeySchema": [{"KeyType": "HASH", "AttributeName": "key1"}, {"KeyType": "RANGE", "AttributeName": "key2"}],
     }
     with patch(PATCH_METHOD) as req:
         req.return_value = {}
         conn.create_table(**kwargs)
         kwargs = req.call_args[0][1]
         self.assertEqual(kwargs, params)
开发者ID:antoinemenini,项目名称:PynamoDB,代码行数:32,代码来源:test_table_connection.py

示例2: print

# 需要导入模块: from pynamodb.connection import TableConnection [as 别名]
# 或者: from pynamodb.connection.TableConnection import create_table [as 别名]
                        'KeyType': 'HASH',
                        'AttributeName': 'Forum'
                    },
                    {
                        'KeyType': 'RANGE',
                        'AttributeName': 'AltKey'
                    }
                ],
                'projection': {
                    'ProjectionType': 'KEYS_ONLY'
                }
            }
        ]
    }
    print("conn.create_table...")
    conn.create_table(**params)

while table is None:
    time.sleep(2)
    table = conn.describe_table()
while table['TableStatus'] == 'CREATING':
    time.sleep(5)
    print(table['TableStatus'])
    table = conn.describe_table()
print("conn.update_table...")

conn.update_table(
    read_capacity_units=table.get(PROVISIONED_THROUGHPUT).get(READ_CAPACITY_UNITS) + 1,
    write_capacity_units=2
)
开发者ID:BCVisin,项目名称:PynamoDB,代码行数:32,代码来源:table_integration.py

示例3: test_create_table

# 需要导入模块: from pynamodb.connection import TableConnection [as 别名]
# 或者: from pynamodb.connection.TableConnection import create_table [as 别名]
 def test_create_table(self):
     """
     TableConnection.create_table
     """
     conn = TableConnection(self.test_table_name)
     kwargs = {
         'read_capacity_units': 1,
         'write_capacity_units': 1,
     }
     self.assertRaises(ValueError, conn.create_table, **kwargs)
     kwargs['attribute_definitions'] = [
         {
             'attribute_name': 'key1',
             'attribute_type': 'S'
         },
         {
             'attribute_name': 'key2',
             'attribute_type': 'S'
         }
     ]
     self.assertRaises(ValueError, conn.create_table, **kwargs)
     kwargs['key_schema'] = [
         {
             'attribute_name': 'key1',
             'key_type': 'hash'
         },
         {
             'attribute_name': 'key2',
             'key_type': 'range'
         }
     ]
     params = {
         'TableName': 'ci-table',
         'ProvisionedThroughput': {
             'WriteCapacityUnits': 1,
             'ReadCapacityUnits': 1
         },
         'AttributeDefinitions': [
             {
                 'AttributeType': 'S',
                 'AttributeName': 'key1'
             },
             {
                 'AttributeType': 'S',
                 'AttributeName': 'key2'
             }
         ],
         'KeySchema': [
             {
                 'KeyType': 'HASH',
                 'AttributeName': 'key1'
             },
             {
                 'KeyType': 'RANGE',
                 'AttributeName': 'key2'
             }
         ]
     }
     with patch(PATCH_METHOD) as req:
         req.return_value = {}
         conn.create_table(
             **kwargs
         )
         kwargs = req.call_args[0][1]
         self.assertEqual(kwargs, params)
开发者ID:BCVisin,项目名称:PynamoDB,代码行数:67,代码来源:test_table_connection.py


注:本文中的pynamodb.connection.TableConnection.create_table方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。