@@ -3,55 +3,73 @@ package main
3
3
import (
4
4
"graph-db/api"
5
5
"graph-db/internal/app/core/structs"
6
- "graph-db/internal/app/core"
7
- "graph-db/internal/pkg/utils"
8
- "graph-db/internal/app/core/globals"
9
- "log"
6
+ "strings"
7
+ "strconv"
10
8
)
11
9
12
10
func printNode (node structs.Node ) {
13
11
var str string
14
- str += "Node labels: "
15
- for _ , label := range node .GetLabel ().GetLabelNames () {
12
+ str += strings . Join ([] string { "Node id: " , strconv . Itoa ( node . GetId ()), ", labels: "}, "" )
13
+ for index , label := range node .GetLabel ().GetLabelNames () {
16
14
if label != nil && label .GetTitle () != "" {
17
15
str += label .GetTitle ()
18
- str += ", "
16
+ if index != len (node .GetLabel ().GetLabelNames ()) - 1 {
17
+ if node .GetLabel ().GetLabelNames ()[index + 1 ] != nil {
18
+ str += ", "
19
+ } else {
20
+ str += "."
21
+ }
22
+ }
19
23
}
20
24
}
21
- str += "\n "
22
- str += "Relationships: \n "
23
- relationship := node .GetRelationship ()
24
- if relationship != nil {
25
- str += "\t Title: "
26
- str += relationship .GetTitle ().GetTitle ()
25
+ if node .GetProperty () != nil {
26
+ str += "\n Node properties: \n "
27
+ property := node .GetProperty ()
28
+ var prop string
29
+ index := 1
30
+ for property != nil {
31
+ prop += strings .Join ([]string {strconv .Itoa (index ), ". Property title: \" " , property .GetTitle ().String (),
32
+ "\" ; value: " , (* property .GetValue ()).String (), "\n " }, "" )
33
+ property = property .GetNextProperty ()
34
+ index ++
35
+ }
36
+ str += prop [:len (prop ) - 2 ]
37
+ }
38
+ if node .GetRelationship () != nil {
39
+ str += "\n Relationships: \n "
40
+ relationship := node .GetRelationship ()
41
+ var rel string
42
+ index := 0
43
+ for relationship != nil {
44
+ rel += strings .Join ([]string {"\t " , strconv .Itoa (index + 1 ), ". Node with id " ,
45
+ strconv .Itoa (relationship .GetFirstNode ().GetId ()), " " ,
46
+ relationship .GetTitle ().GetTitle (), " node with id " ,
47
+ strconv .Itoa (relationship .GetSecondNode ().GetId ()), "\n " }, "" )
48
+ property := relationship .GetProperty ()
49
+ index2 := 0
50
+ if property != nil {
51
+ rel += "\t \t Relationship properties:\n "
52
+ }
53
+ for property != nil {
54
+ rel += strings .Join ([]string {"\t \t \t " , strconv .Itoa (index2 + 1 ), ". Property title: \" " , property .GetTitle ().String (),
55
+ "\" ; value: " , (* property .GetValue ()).String (), "\n " }, "" )
56
+ property = property .GetNextProperty ()
57
+ index2 ++
58
+ }
59
+ if relationship .GetFirstNode ().GetId () == node .GetId () {
60
+ relationship = relationship .GetFirstNextRelationship ()
61
+ } else {
62
+ relationship = relationship .GetSecondNextRelationship ()
63
+ }
64
+ index ++
65
+ }
66
+ str += rel
27
67
}
28
68
println (str )
29
69
}
30
70
31
71
func main () {
32
- //err := core.InitDb("asd", "local")
33
- ////err = core.SwitchDb("asd")
34
- //utils.CheckError(err)
35
-
36
- dbTitle := "asd"
37
- var dfh core.DistributedFileHandler
38
- dfh .InitFileSystem ()
39
- err := core .InitDb (dbTitle , "distributed" )
40
- dfh .InitDatabaseStructure (dbTitle )
41
- if err != nil {
42
- log .Fatal ("Error in initialization of database" )
43
- }
44
-
45
- bs := utils .StringToByteArray ("Test" )
46
- dfh .Write (globals .NodesStore , 20 , bs , 0 )
47
- newBs := make ([]byte , 4 )
48
- dfh .Read (globals .NodesStore , 20 , & newBs , 0 )
49
-
50
- if string (newBs ) != string (bs ) {
51
- log .Fatal ("Byte arrays are not the same!" )
52
- } else {
53
- println ("Congratulations!" )
54
- }
72
+ api .CreateDatabase ("asd" , "local" ) // flag "distributed" for distributed
55
73
56
74
node1 := api .CreateNode ("Kevin" )
57
75
node2 := api .CreateNode ("Sergey" )
0 commit comments