すべてのプロダクト
Search
ドキュメントセンター

Tablestore:データの一括操作の実行

最終更新日:Apr 21, 2026

Node.js SDK の `batchWriteRow` メソッドを使用すると、1 回のリクエストで複数の Tablestore テーブルにまたがる行の書き込み、更新、削除ができます。

注意事項

  • サーバーがいずれかの操作でパラメーターエラーを検出した場合、パラメーターエラーの例外が返されます。この場合、リクエスト内のどの操作も実行されません。

  • 1 回の一括更新操作でサポートされる行数は最大 200 行です。すべての行の合計データ量は 4 MB を超えることはできません。

前提条件

Tablestore クライアントの初期化

メソッド

batchWriteRow: function batchWriteRow(params, callback)

`params` パラメーターの説明

  • tables (必須) 配列: 行データ操作の配列です。 型は List[TableInBatchWriteRowItem] です。 配列の各項目には、以下のパラメーターが含まれます。

    名前

    説明

    tableName (必須)

    string

    データテーブルの名前です。

    rows (必須)

    Array

    データ操作のタイプ。書き込み、更新、削除の操作が含まれます。

  • transactionId (任意) string:ローカルトランザクション ID です。ローカルトランザクションを一意に識別します。詳細については、「ローカルトランザクション」をご参照ください。

コード例

次のコード例は、一括操作メソッドを使用して `test_table` テーブルに行を挿入する方法を示しています。

var table = {
    tableName: 'test_table',
    rows: [
        {
            type: 'PUT',
            // 書き込み操作の条件。
            // TableStore.RowExistenceExpectation.IGNORE は、行が既に存在するかどうかに関係なく行を書き込むことを指定します。
            condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null),
            primaryKey: [{ 'id': 'row1' }]
        }
    ]
};
var params = {
    tables: [table]
};

// batchWriteRow メソッドを呼び出して一括操作を実行します。
client.batchWriteRow(params, function (err, data) {
    if (err) {
        console.log('Batch write row failed with error: %s', err);
        return;
    }

    // 応答を処理します。
    console.log('RequestId: %s', data.RequestId);
    data.tables.forEach(function (item) {
        if (!item.isOk) {
            console.log('Table name: %s. Error message: %s', item.tableName, item.errorMessage);
        }
    });
});

次のコード例は、さまざまなタイプのデータ操作を示しています。

  • `PutRowChange`:行を書き込みます。

    var table = {
        tableName: 'test_table',
        rows: [
            {
                type: 'PUT',
                // 書き込み操作の条件を指定します。TableStore.RowExistenceExpectation.IGNORE は、行の存在をチェックしないことを指定します。
                condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null),
                primaryKey: [{ 'id': 'row1' }]
            }
        ]
    };

    行を書き込む際に属性列も追加します。

    var table = {
        tableName: 'test_table',
        rows: [
            {
                type: 'PUT',
                // 書き込み操作の条件を指定します。TableStore.RowExistenceExpectation.IGNORE は、行の存在をチェックしないことを指定します。
                condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null),
                primaryKey: [{ 'id': 'row1' }],
                attributeColumns: [
                    // 属性列を追加します。
                    { 'col1': 'val1' }, 
                    // カスタムのデータバージョン番号を持つ属性列を追加します。
                    { 'col2': 'val2', 'timestamp': Date.now() }
                ]
            }
        ]
    };
  • `UpdateRowChange`:行を更新します。属性列の値の変更、属性列の追加、または属性列の特定バージョンの削除や属性列全体の削除ができます。

    var table = {
        tableName: 'test_table',
        rows: [
            {
                type: 'UPDATE',
                // 更新操作の条件を指定します。TableStore.RowExistenceExpectation.IGNORE は、行の存在をチェックしないことを指定します。
                condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null),
                primaryKey: [{ 'id': 'row1' }],
                attributeColumns: [{ 'PUT': [{ 'col1': 'changed_val1' }] }],
            }
        ]
    };

    行を更新する際に属性列を追加または削除することもできます。

    var table = {
        tableName: 'test_table',
        rows: [
            {
                type: 'UPDATE',
                // 更新操作の条件を指定します。TableStore.RowExistenceExpectation.IGNORE は、行の存在をチェックしないことを指定します。
                condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null),
                primaryKey: [{ 'id': 'row1' }],
                attributeColumns: [
                    {
                        'PUT':
                            [
                                // 属性列を追加します。
                                { 'col3': 'val3' },
                                // カスタムのデータバージョン番号を持つ属性列を追加します。
                                { 'col4': 'val4', 'timestamp': Date.now() }
                            ]
                    },
                    {   // 属性列を削除します。
                        'DELETE_ALL':
                            ['col2']
                    }
                ],
            }
        ]
    };
  • `DeleteRowChange`:行を削除します。

    var table = {
        tableName: 'test_table',
        rows: [
            {
                type: 'DELETE',
                // 削除操作の条件を指定します。TableStore.RowExistenceExpectation.IGNORE は、行の存在をチェックしないことを指定します。
                condition: new TableStore.Condition(TableStore.RowExistenceExpectation.IGNORE, null),
                primaryKey: [{ 'id': 'row1' }]
            }
        ]
    };

関連ドキュメント