Este tópico descreve como criar uma tabela de dados do Tablestore com o SDK para PHP.
Observações de uso
Após criar uma tabela de dados, aguarde o carregamento completo antes de executar operações nos dados. Caso contrário, as operações falharão. Esse processo geralmente leva alguns segundos.
Pré-requisitos
Descrição do método
public function createTable(array $request)
Código de exemplo
Criar uma tabela de dados
O exemplo a seguir cria uma tabela chamada test_table com uma chave primária do tipo String.
$request = array (
// Table structure information
'table_meta' => array (
'table_name' => 'test_table',
// At least one primary key is required to create a data table
'primary_key_schema' => array (
array('id', PrimaryKeyTypeConst::CONST_STRING)
),
// (Optional) Add predefined columns
'defined_column' => array (
array('name', DefinedColumnTypeConst::DCT_STRING)
)
),
// (Optional) Table configuration information
'table_options' => array (
// (Optional) Data lifecycle, -1 indicates that data never expires
'time_to_live' => -1,
// (Optional) Maximum number of versions
'max_versions' => 1,
// (Optional) Maximum version offset
'deviation_cell_version_in_sec' => 86400,
// (Optional) Whether to allow updates
'allow_update' => true
),
// (Optional) Set Stream information
'stream_spec' => array (
'enable_stream' => true,
'expiration_time' => 168
),
// Reserved read and write throughput must be set when creating a data table (only high-performance instances in CU mode support setting non-zero values for reserved read and write throughput)
'reserved_throughput' => array (
'capacity_unit' => array (
'read' => 0,
'write' => 0
)
)
);
try{
$client->createTable( $request );
echo "Create table succeeded.";
} catch (Exception $e) {
echo "Create table failed.";
}
Criar uma tabela de dados com índices secundários
O exemplo a seguir cria uma tabela de dados com índices secundários.
$request = array (
// Table structure information
'table_meta' => array (
'table_name' => 'test_table',
// Primary key
'primary_key_schema' => array (
array('id', PrimaryKeyTypeConst::CONST_STRING)
),
// Predefined columns
'defined_column' => array (
array('name', DefinedColumnTypeConst::DCT_STRING)
)
),
// Reserved read and write throughput (only high-performance instances in CU mode support setting non-zero values for reserved read and write throughput)
'reserved_throughput' => array (
'capacity_unit' => array (
'read' => 0,
'write' => 0
)
),
// Secondary index information
'index_metas' => array(
array(
'name' => 'test_table_index',
'primary_key' => array('id'),
'defined_column' => array('name'),
'index_type' => IndexTypeConst::LOCAL_INDEX,
'index_update_mode' => IndexUpdateModeConst::SYNC_INDEX
)
)
);
try{
$client->createTable( $request );
echo "Create table succeeded.";
} catch (Exception $e) {
echo "Create table failed.";
}