@@ -2,58 +2,56 @@ package client
2
2
3
3
import (
4
4
"fmt"
5
- "github.com/IntelliLog/IntelliLog-GoLang-Driver/connection"
6
- "strings"
5
+ "github.com/citra-org/chrono-db-go-driver/connection"
7
6
)
8
7
9
8
type Client struct {
10
9
conn * connection.Connection
11
10
}
12
11
13
- func NewClient (uri string ) (* Client , error ) {
14
- conn , err := connection .NewConnection (uri )
12
+ func Connect (uri string ) (* Client , string , error ) {
13
+ conn , dbName , err := connection .NewConnection (uri )
15
14
if err != nil {
16
- return nil , err
15
+ return nil , "" , err
17
16
}
18
- return & Client {conn : conn }, nil
17
+ return & Client {conn : conn }, dbName , nil
19
18
}
20
19
21
20
func (c * Client ) Close () error {
22
21
return c .conn .Close ()
23
22
}
24
23
25
- func (c * Client ) Create () error {
26
- response , err := c .conn .Execute ("c" )
27
- if err != nil {
28
- return err
24
+ func (c * Client ) CreateChrono (chrono string ) error {
25
+ if response , err := c .conn .Execute ("cc " + "heheh" ); err != nil || response != "OK" {
26
+ return fmt .Errorf ("create failed: %v" , err )
29
27
}
30
- if response != "OK" {
31
- return fmt .Errorf ("create failed: %s" , response )
28
+ return nil
29
+ }
30
+
31
+ func (c * Client ) CreateStream (chrono string , stream string ) error {
32
+ if response , err := c .conn .Execute ("cs " + stream ); err != nil || response != "OK" {
33
+ return fmt .Errorf ("create failed: %v" , err )
34
+ }
35
+ return nil
36
+ }
37
+ func (c * Client ) DeleteStream (chrono string , stream string ) error {
38
+ if response , err := c .conn .Execute ("ds " + stream ); err != nil || response != "OK" {
39
+ return fmt .Errorf ("delete failed: %v" , err )
32
40
}
33
41
return nil
34
42
}
35
43
36
- func (c * Client ) Write ( data map [string ]string ) error {
37
- command := "w"
44
+ func (c * Client ) WriteEvent ( chrono string , stream string , data map [string ]string ) error {
45
+ command := "w " + stream + " "
38
46
for k , v := range data {
39
- command += fmt .Sprintf (" %s %s" , k , v )
40
- }
41
- response , err := c .conn .Execute (command )
42
- if err != nil {
43
- return err
47
+ command += k + " " + v + " "
44
48
}
45
- if response != "OK" {
46
- return fmt .Errorf ("write failed: %s " , response )
49
+ if response , err := c . conn . Execute ( command ); err != nil || response != "OK" {
50
+ return fmt .Errorf ("write failed: %v " , err )
47
51
}
48
52
return nil
49
53
}
50
54
51
- func (c * Client ) Read () (string , error ) {
52
- response , err := c .conn .Execute ("r" )
53
- if err != nil {
54
- return "" , err
55
- }
56
- //TODO: fix this to send lines insted of lines as string (check ops/read.rs)
57
- formattedResponse := strings .ReplaceAll (response , "&/n" , "\n " )
58
- return formattedResponse , nil
55
+ func (c * Client ) Read (chrono string , stream string ) (string , error ) {
56
+ return c .conn .Execute ("r " + stream )
59
57
}
0 commit comments