@@ -13,8 +13,16 @@ using SQLiteGraph
13
13
14
14
db = DB ()
15
15
# SQLiteGraph.DB(":memory:") (0 nodes, 0 edges)
16
+
17
+ db[1 ] = Config (type= " person" , name= " Fred" )
18
+
19
+ db[2 ] = Config (type= " person" , name= " Robert Ford" )
20
+
21
+ db[2 , 1 ] = Config (shot= true )
16
22
```
17
23
24
+
25
+
18
26
- Nodes and edges must have "properties" (something that is ` JSON3.write ` -able), even if its ` nothing ` .
19
27
- Nodes must have an id (` Int ` ) in ascending order starting with ` 1 ` .
20
28
- Add nodes and edges with ` setindex! `
@@ -25,17 +33,17 @@ db = DB()
25
33
- E.g. Edges from 1 to 2 or 3: ` db[1, 2:3] `
26
34
- Returned objects are ` Node ` or ` Edge ` (or generator if multiple objects queried):
27
35
- ` Node ` and ` Edge ` are simple structs.
28
- - By default, ` T ` will be ` String ` . You can set ` T ` on construction of the ` DB ` e.g. ` DB(Dict{String,String}) ` .
36
+
29
37
``` julia
30
- struct Node{T}
38
+ struct Node
31
39
id:: Int
32
- props:: T
40
+ props:: Config
33
41
end
34
42
35
- struct Edge{T}
43
+ struct Edge
36
44
source:: Int
37
45
target:: Int
38
- props:: T
46
+ props:: config
39
47
end
40
48
```
41
49
@@ -57,7 +65,9 @@ db[1] = (x=1, y=2)
57
65
db[2 ] = (x= 1 , y= 10 )
58
66
59
67
db[1 ]
60
- # "{\"x\":1,\"y\":2}"
68
+ # Node 1
69
+ # • y: 2
70
+ # • x: 1
61
71
```
62
72
63
73
### Adding Edges
@@ -66,12 +76,18 @@ db[1]
66
76
db[1 , 2 ] = (a= 1 , b= 2 )
67
77
68
78
db[1 , 2 ]
69
- # "{\"a\":1,\"b\":2}"
79
+ # Edge 1 → 2
80
+ # • a: 1
81
+ # • b: 2
70
82
```
71
83
72
- ## Querying
73
-
84
+ ## Iteration
74
85
86
+ ``` julia
87
+ for node in eachnode (db)
88
+ println (getfield (node, :id ))
89
+ end
90
+ ```
75
91
76
92
### Querying Edges Based on Node ID
77
93
0 commit comments