aboutsummaryrefslogtreecommitdiffstats
path: root/lib/data/data_providers/storage_client.dart
blob: 5c72785b7a86643b53bb30eadd337cf3b202ac8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import 'package:flutter_ics_homescreen/export.dart';
import 'package:protos/storage-api.dart' as storage_api;

class StorageClient{
  final StorageConfig config;
  final Ref ref;
  late storage_api.ClientChannel channel;
  late storage_api.DatabaseClient stub;

 StorageClient({required this.config, required this.ref}) {
    debugPrint(
        "Connecting to storage service at ${config.hostname}:${config.port}");
    storage_api.ChannelCredentials creds = const storage_api.ChannelCredentials.insecure();
    channel = storage_api.ClientChannel(config.hostname,
        port: config.port, options: storage_api.ChannelOptions(credentials: creds));
    stub = storage_api.DatabaseClient(channel);
  }


  Future<storage_api.StandardResponse> destroyDB() async {
    try {
      var response = await stub.destroyDB(storage_api.DestroyArguments());
      return response;
    } catch (e) {
      print(e);
      rethrow;
    }
  }

  Future<storage_api.StandardResponse> write(storage_api.KeyValue keyValue) async {
    try {
      var response = await stub.write(keyValue);
      return response;
    } catch (e) {
      print(e);
      rethrow;
    }
  }
  
  Future<storage_api.ReadResponse> read(storage_api.Key key) async{
    try{
      var response = await stub.read(key);
      return response;
    } catch(e) {
      print(e);
      rethrow;
    }
  }

  Future<storage_api.StandardResponse> delete(storage_api.Key key) async{
    try{
      var response = await stub.delete(key);
      return response;
    } catch(e) {
      print(e);
      rethrow;
    }
  }

    Future<storage_api.ListResponse> search(storage_api.Key key) async{
    try{
      var response = await stub.search(key);
      return response;
    } catch(e) {
      print(e);
      rethrow;
    }
  }

    Future<storage_api.StandardResponse> deleteNodes(storage_api.Key key) async{
    try{
      var response = await stub.deleteNodes(key);
      return response;
    } catch(e) {
      print(e);
      rethrow;
    }
  }

    Future<storage_api.ListResponse> listNodes(storage_api.SubtreeInfo subtreeInfo) async{
    try{
      var response = await stub.listNodes(subtreeInfo);
      return response;
    } catch(e) {
      print(e);
      rethrow;
    }
  }
}