行の作成
単一行の作成
newRow()メソッドを使用して、指定されたインスタンスのData Storeテーブルに新しい行を作成できます。カラム名と対応する行の値をキーと値のペアとして指定することで、テーブル内の行の値を設定する必要があります。
以下のコード構文で使用される<ROW_INSTANCE>は、行インスタンスページで定義されたインスタンスです。
Future<(APIResponse, ZCatalystRow)> <ROW_INSTANCE>.create()
行インスタンスの作成を含むサンプルコードスニペットを以下に示します:
var row = ZCatalystApp.getInstance()
.getDataStoreInstance()
.getTableInstance(identifier: 'Products')
.newRow(); //テーブルの行インスタンスを定義し、行のキーと値のデータを渡す
row.setColumnValue('product_name', 'power_bank');
row.setColumnValue('product_price', 2000);
row.setColumnValue('product_quantity', 2);
try {
var (response, row) = await row.create();
print(‘New row created successfully : ${row.id}’);
} on ZCatalystException catch (ex) {
print(‘Failed to create the row: $exception’);
}
複数行の作成
Catalyst Flutter SDKでは、指定されたインスタンスのテーブルに複数の行を一度に作成できます。テーブルに挿入する必要がある行を含むリストを渡すことで実行されます。以下のコード構文に示すように、リストはcreateRows()メソッドの引数として渡されます。
以下のコードで使用される<TABLE_INSTANCE>は、テーブルインスタンスページで定義されたインスタンスです。
Future<(APIResponse, List<ZCatalystRow>)> <TABLE_INSTANCE>.createRows(List<ZCatalystRow> rows)
パラメータ:
- rows: 作成する行の配列
行インスタンスの作成を含むサンプルコードスニペットを以下に示します:
List<ZCatalystRow> newRows = []; //配列を作成する
//作成する行の行インスタンスを定義する
ZCatalystRow row1 =
dataStore.getTableInstance(identifier: 'Products').newRow();
row1.setColumnValue('product_name', 'a');
row1.setColumnValue('product_price', 25);
row1.setColumnValue('product_quantity', 50);
ZCatalystRow row2 =
dataStore.getTableInstance(identifier: ‘Products’).newRow();
row2.setColumnValue(‘product_name’, ‘b’);
row2.setColumnValue(‘product_price’, 30);
row2.setColumnValue(‘product_quantity’, 40);
ZCatalystRow row3 =
dataStore.getTableInstance(identifier: ‘Products’).newRow();
row3.setColumnValue(‘product_name’, ‘c’);
row3.setColumnValue(‘product_price’, 25);
row3.setColumnValue(‘product_quantity’, 70);
//配列に行インスタンスを追加する
newRows.add(row1);
newRows.add(row2);
newRows.add(row3);
try{
var (response, rows) = await dataStore.getTableInstance(identifier: ‘Products’).createRows(rows: newRows);
for (var row in rows) {
print(row.id); //行の正常な作成時に実行するアクション
}
} on ZCatalystException catch (ex) {
print(‘The IDs of the rows that were successfully created are listed below:’)
}
最終更新日 2026-03-30 13:40:30 +0530 IST
Yes
No
Send your feedback to us