You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-13Lines changed: 17 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,18 +20,18 @@ db = DB()
20
20
- E.g. Nodes 1, 2, and 3: `db[1:3]`
21
21
- E.g. Edges from 1 to 2 or 3: `db[1, 2:3]`
22
22
- Returned objects are `Node` or `Edge` (or generator if multiple objects queried):
23
-
-`Node` and `Edge` are simple structs.
23
+
-`Node` and `Edge` are simple structs.
24
24
- By default, `T` will be `String`. You can set `T` on construction of the `DB` e.g. `DB(Dict{String,String})`.
25
25
```julia
26
-
struct Node{T}
27
-
id::Int
28
-
props::T
26
+
struct Node{T}
27
+
id::Int
28
+
props::T
29
29
end
30
30
31
-
struct Edge{T}
32
-
source::Int
33
-
target::Int
34
-
props::T
31
+
struct Edge{T}
32
+
source::Int
33
+
target::Int
34
+
props::T
35
35
end
36
36
```
37
37
@@ -48,15 +48,15 @@ db = DB()
48
48
49
49
```julia
50
50
# properties must be `JSON3.write`-able (saved in the SQLite database as TEXT)
51
-
db[1] = (x=1, y=2)
51
+
db[1] = (x=1, y=2)
52
52
53
53
db[2] = (x=1, y=10)
54
54
55
-
db[1]
55
+
db[1]
56
56
# "{\"x\":1,\"y\":2}"
57
57
```
58
58
59
-
### Adding Edges
59
+
### Adding Edges
60
60
61
61
```julia
62
62
db[1, 2] = (a=1, b=2)
@@ -65,12 +65,16 @@ db[1, 2]
65
65
# "{\"a\":1,\"b\":2}"
66
66
```
67
67
68
+
## Querying
69
+
70
+
71
+
68
72
### Querying Edges Based on Node ID
69
73
70
74
```julia
71
75
db[1, :] # all outgoing edges from node 1
72
76
73
-
db[1, 2:5] # outgoing edges from node 1 to any of nodes 2,3,4,5
77
+
db[1, 2:5] # outgoing edges from node 1 to any of nodes 2,3,4,5
74
78
75
79
db[:, 2] # all incoming edges to node 2
76
80
```
@@ -95,7 +99,7 @@ find_edges(db, r"\"b\":2")
95
99
96
100
## ✨ Attribution ✨
97
101
98
-
SQLiteGraph is **STRONGLY** influenced (much has been copied verbatim) from [https://github.com/dpapathanasiou/simple-graph](https://github.com/dpapathanasiou/simple-graph).
102
+
SQLiteGraph is **STRONGLY** influenced (much has been copied verbatim) from [https://github.com/dpapathanasiou/simple-graph](https://github.com/dpapathanasiou/simple-graph).
- Node and edge properties are saved in the database as `TEXT` (see [https://www.sqlite.org/datatype3.html](https://www.sqlite.org/datatype3.html)) via `JSON3.write(props)`.
52
52
- Node and edge properties will be interpreted as `T` in Julia: `JSON3.read(props, T)`
53
53
@@ -61,7 +61,7 @@ Create a graph database (in memory by default).
61
61
- `target INTEGER`
62
62
- `props TEXT` (via JSON3.write)
63
63
64
-
# Examples
64
+
# Examples
65
65
66
66
db = DB()
67
67
@@ -79,7 +79,7 @@ struct DB{T}
79
79
SQLite.@register db SQLite.regexp
80
80
statements = [
81
81
"CREATE TABLE IF NOT EXISTS nodes (
82
-
id INTEGER NOT NULL UNIQUE,
82
+
id INTEGER NOT NULL UNIQUE,
83
83
props TEXT,
84
84
UNIQUE(id) ON CONFLICT REPLACE
85
85
);",
@@ -96,7 +96,7 @@ struct DB{T}
96
96
"CREATE INDEX IF NOT EXISTS target_idx ON edges(target);"
97
97
]
98
98
# workaround because sqlite won't run multiple statements at once
0 commit comments