Table dropping implemented

This commit is contained in:
Andrew 2023-04-11 16:11:58 +07:00
parent 529ec239d1
commit d973954a75
4 changed files with 114 additions and 4 deletions

View file

@ -92,8 +92,9 @@ class ApiClient {
return ErrorOrData(data, error);
}
FutureErrorOrData<void> createTable(
FutureErrorOrData<bool> createTable(
String tableName, List<TableField> columns) async {
bool? ignored;
Exception? error;
final response =
@ -107,6 +108,8 @@ class ApiClient {
final body = json.decode(await response.stream.bytesToString());
if (body['error'] != null) {
error = Exception(body['error']);
} else {
ignored = true;
}
} else if (response.statusCode == 422) {
error = Exception('Invalid request parameters');
@ -114,7 +117,29 @@ class ApiClient {
error = Exception('HTTP ${response.statusCode}');
}
return ErrorOrData(null, error);
return ErrorOrData(ignored, error);
}
FutureErrorOrData<bool> dropTable(String tableName) async {
bool? ignored;
Exception? error;
final response =
await post('/api/dropTable/${Uri.encodeComponent(tableName)}');
if (response.statusCode == 200) {
final body = json.decode(await response.stream.bytesToString());
if (body['error'] != null) {
error = Exception(body['error']);
} else {
ignored = true;
}
} else if (response.statusCode == 422) {
error = Exception('Invalid request parameters');
} else {
error = Exception('HTTP ${response.statusCode}');
}
return ErrorOrData(ignored, error);
}
Future<StreamedResponse> get(