Skip to content

Commit 2884cbd

Browse files
committed
readme
1 parent 0de0317 commit 2884cbd

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

README.md

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,22 @@ db[1]
3232
### Adding Edges
3333

3434
```julia
35-
db[1,2] = (a=1, b=2)
35+
db[1, 2] = (a=1, b=2)
3636

37-
db[1,2]
37+
db[1, 2]
3838
# "{\"a\":1,\"b\":2}"
3939
```
4040

41-
### `ReadAs`
42-
43-
- You can wrap a `DB` with `ReadAs` to enforce how you want the `TEXT` to be `JSON3.read`:
41+
### Querying Edges
4442

4543
```julia
46-
rdb = ReadAs(db, Dict{String, Int})
47-
# ReadAs{Dict{String, Int64}}: SimpleGraphDB(":memory:") (2 nodes, 1 edges)
48-
49-
rdb[1]
50-
# Dict{String, Int64} with 2 entries:
51-
# "x" => 1
52-
# "y" => 2
53-
54-
rdb[1,2]
55-
# Dict{String, Int64} with 2 entries:
56-
# "b" => 2
57-
# "a" => 1
58-
```
44+
db[1, :] # all outgoing edges from node 1
5945

46+
db[1, 2:5] # outgoing edges from node 1 to any of nodes 2,3,4,5
6047

48+
db[:, 1] # all incoming edges to node 1
49+
50+
```
6151

6252
## Attribution
6353

src/SQLiteGraph.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,19 @@ function Base.iterate(db::DB, state = (length(db), 1))
111111
single_result_execute(db, "SELECT props FROM nodes WHERE id = ?", (state[2],)), (state[1], state[2] + 1)
112112
end
113113

114-
#-----------------------------------------------------------------------------# ReadAs
115-
struct ReadAs{T}
116-
db::DB
117-
end
118-
ReadAs(db::DB, T::DataType=Dict{String,Any}) = ReadAs{T}(db)
119-
Base.show(io::IO, r::ReadAs{T}) where {T} = (print(io, "ReadAs{$T}: "); print(io, r.db))
120-
Base.setindex!(r::ReadAs, args...) = setindex!(r.db, args...)
121-
function Base.getindex(r::ReadAs{T}, args...) where {T}
122-
res=r.db[args...]; isnothing(res) ? res : JSON3.read.(res, T)
123-
end
124-
125-
_transform(node::Node{String}, T) = Node(node.id, JSON)
126-
Base.deleteat!(r::ReadAs, args...) = deleteat!(r.db, args...)
114+
# #-----------------------------------------------------------------------------# ReadAs
115+
# struct ReadAs{T}
116+
# db::DB
117+
# end
118+
# ReadAs(db::DB, T::DataType=Dict{String,Any}) = ReadAs{T}(db)
119+
# Base.show(io::IO, r::ReadAs{T}) where {T} = (print(io, "ReadAs{$T}: "); print(io, r.db))
120+
# Base.setindex!(r::ReadAs, args...) = setindex!(r.db, args...)
121+
# function Base.getindex(r::ReadAs{T}, args...) where {T}
122+
# res=r.db[args...]; isnothing(res) ? res : JSON3.read.(res, T)
123+
# end
124+
125+
# _transform(node::Node{String}, T) = Node(node.id, JSON)
126+
# Base.deleteat!(r::ReadAs, args...) = deleteat!(r.db, args...)
127127

128128
#-----------------------------------------------------------------------------# nodes
129129
function Base.setindex!(db::DB, props, id::Integer)

0 commit comments

Comments
 (0)