upsertRow method

Future<Row> upsertRow({
  1. required String databaseId,
  2. required String tableId,
  3. required String rowId,
  4. Map? data,
  5. List<String>? permissions,
  6. String? transactionId,
})

Create or update a Row. Before using this route, you should create a new table resource using either a server integration API or directly from your database console.

Implementation

Future<models.Row> upsertRow({
  required String databaseId,
  required String tableId,
  required String rowId,
  Map? data,
  List<String>? permissions,
  String? transactionId,
}) async {
  if (databaseId.isEmpty) {
    throw AppwriteException(
      'Missing required parameter: "databaseId"',
    );
  }

  if (tableId.isEmpty) {
    throw AppwriteException(
      'Missing required parameter: "tableId"',
    );
  }

  if (rowId.isEmpty) {
    throw AppwriteException(
      'Missing required parameter: "rowId"',
    );
  }

  final String apiPath =
      '/tablesdb/{databaseId}/tables/{tableId}/rows/{rowId}'
          .replaceAll(
            '{databaseId}',
            _encodePath(databaseId),
          )
          .replaceAll(
            '{tableId}',
            _encodePath(tableId),
          )
          .replaceAll(
            '{rowId}',
            _encodePath(rowId),
          );

  final Map<String, dynamic> apiParams = {
    if (data != null) 'data': data,
    if (permissions != null) 'permissions': permissions,
    if (transactionId != null) 'transactionId': transactionId,
  };

  final Map<String, String> apiHeaders = {
    'X-Appwrite-Project': client.config['project'] ?? '',
    'content-type': 'application/json',
    'accept': 'application/json',
  };

  final res = await client.call(
    HttpMethod.put,
    path: apiPath,
    params: apiParams,
    headers: apiHeaders,
  );

  return models.Row.fromMap(res.data);
}