Bu konuda, PHP SDK kullanarak Tablestore veri tablosunun nasıl oluşturulacağı açıklanmaktadır.
Kullanım notları
Veri tablosunu oluşturduktan sonra veriler üzerinde işlem gerçekleştirmeden önce tablonun yüklenmesini bekleyin. Aksi takdirde işlemler başarısız olur. Bu süreç genellikle birkaç saniye sürer.
Önkoşullar
Yöntem açıklaması
public function createTable(array $request)
Örnek kod
Veri tablosu oluşturun
Aşağıdaki örnek kod, bir String türünde birincil anahtar içeren test_table tablosunu oluşturur.
$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.";
}
İkincil dizinlerle veri tablosu oluşturun
Aşağıdaki örnek kod, ikincil dizinlere sahip bir veri tablosu oluşturur.
$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.";
}