Skip to content

Commit e5e4f6f

Browse files
authored
Merge pull request #9 from asjir/main
Added functionality to query by node label
2 parents dff9ce1 + 1469c07 commit e5e4f6f

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SQLiteGraph"
22
uuid = "de2defd0-d76e-464a-9029-1d71e199ae58"
33
authors = ["joshday <emailjoshday@gmail.com> and contributors"]
4-
version = "0.2.2"
4+
version = "0.3.0"
55

66
[deps]
77
DBInterface = "a10d1c49-ce27-4219-8d33-6db1a4562965"

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,16 @@ replace!(db, Node(2, "Movie"; title="Forest Gump", genre="Drama"))
8080

8181
- Use `getindex` to access elements.
8282
- If `:` is used as an index, an iterator is returned.
83+
- If `s::String` is used as an index, an iterator of nodes where `s` is *one* of the labels is returned.
8384

8485
```julia
85-
db[1] # Node(2, "Movie"; title="Forest Gump", genre="Drama")
86+
db[1] # Node(1, "Person", "Actor"; name="Tom Hanks")
8687

8788
for node in db[:]
8889
println(node)
8990
end
9091

92+
only(db["Movie"]) # Node(2, "Movie"; title="Forest Gump", genre="Drama")
9193

9294
# (Pretend the graph is populated with many more items. The following return iterators.)
9395

src/SQLiteGraph.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function Base.show(io::IO, o::Node)
3838
!isempty(o.props) && print(io, "; "); print_props(io, o.props)
3939
print(io, ')')
4040
end
41-
args(n::Node) = (n.id, isempty(n.labels) ? "" : join(n.labels, ';'), JSON3.write(n.props))
41+
args(n::Node) = (n.id, isempty(n.labels) ? "" : ";"*join(n.labels, ';')*";", JSON3.write(n.props))
4242

4343

4444

@@ -148,6 +148,7 @@ end
148148
#-----------------------------------------------------------------------------# getindex (Node)
149149
Base.getindex(db::DB, i::Integer) = Node(first(query(db, "*", "nodes", "id=$i")))
150150
Base.getindex(db::DB, ::Colon) = (Node(row) for row in query(db, "*", "nodes", "TRUE"))
151+
Base.getindex(db::DB, label::String) = (Node(row) for row in SQLiteGraph.query(db, "*", "nodes", "labels LIKE '%;$label;%'"))
151152

152153
#-----------------------------------------------------------------------------# getindex (Edge)
153154
# all specified

test/runtests.jl

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ db = DB()
3030
@test n.id == i
3131
end
3232
@test length(collect(db[:])) == 5
33+
@test length(collect(db["lab"])) == 3
34+
@test length(collect(db["lab1"])) == 2
35+
@test length(collect(db["lab2"])) == 2
3336
end
3437
end
3538

0 commit comments

Comments
 (0)