insertDatabaseConnection method

Future<Response> insertDatabaseConnection({
  1. required String dbName,
  2. required String host,
  3. required String password,
  4. required String port,
  5. required String username,
  6. required String databaseName,
  7. required String databaseType,
  8. bool isNoSql = false,
  9. bool isEncrypt = false,
})

Implementation

Future<http.Response> insertDatabaseConnection({
  required String dbName,
  required String host,
  required String password,
  required String port,
  required String username,
  required String databaseName,
  required String databaseType,
  bool isNoSql = false,
  bool isEncrypt = false,
}) async {
  final url = Uri.parse('$baseUrl/insertDatabaseConnectionInfo?workspaceId=$workspaceId');
  final headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer $token',
  };
  final body = jsonEncode({
    "database_attributes": {
      "dbName": dbName,
      "host": host,
      "password": password,
      "port": port,
      "username": username
    },
    "database_name": databaseName,
    "database_type": databaseType,
    "is_nosql": isNoSql,
    "is_encrypt": isEncrypt
  });

  print("Request Body = $body");

  try {
    final response = await http.post(url, headers: headers, body: body);

    print("Response Status Code: ${response.statusCode}");
    print("Response Body: ${response.body}");

    return response;
  } catch (e) {
    print("Error occurred: $e");
    throw Exception('Failed to insert database connection');
  }
}