Skip to content

Commit 57dd4c3

Browse files
committed
remove whitespace
1 parent 891e6a0 commit 57dd4c3

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ db = DB()
2020
- E.g. Nodes 1, 2, and 3: `db[1:3]`
2121
- E.g. Edges from 1 to 2 or 3: `db[1, 2:3]`
2222
- 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.
2424
- By default, `T` will be `String`. You can set `T` on construction of the `DB` e.g. `DB(Dict{String,String})`.
2525
```julia
26-
struct Node{T}
27-
id::Int
28-
props::T
26+
struct Node{T}
27+
id::Int
28+
props::T
2929
end
3030

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
3535
end
3636
```
3737

@@ -48,15 +48,15 @@ db = DB()
4848

4949
```julia
5050
# 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)
5252

5353
db[2] = (x=1, y=10)
5454

55-
db[1]
55+
db[1]
5656
# "{\"x\":1,\"y\":2}"
5757
```
5858

59-
### Adding Edges
59+
### Adding Edges
6060

6161
```julia
6262
db[1, 2] = (a=1, b=2)
@@ -65,12 +65,16 @@ db[1, 2]
6565
# "{\"a\":1,\"b\":2}"
6666
```
6767

68+
## Querying
69+
70+
71+
6872
### Querying Edges Based on Node ID
6973

7074
```julia
7175
db[1, :] # all outgoing edges from node 1
7276

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
7478

7579
db[:, 2] # all incoming edges to node 2
7680
```
@@ -95,7 +99,7 @@ find_edges(db, r"\"b\":2")
9599

96100
## ✨ Attribution ✨
97101

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).
99103

100104
## TODOs
101105

src/SQLiteGraph.jl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@ using JSON3: JSON3
66

77
export DB, Node, Edge, find_nodes, find_edges
88

9-
#-----------------------------------------------------------------------------# utils
9+
#-----------------------------------------------------------------------------# utils
1010
read_sql(fn::String) = read(joinpath(@__DIR__, "sql", fn), String)
1111

12-
function single_result_execute(db, stmt, args...)
12+
function single_result_execute(db, stmt, args...)
1313
ex = execute(db, stmt, args...)
1414
isempty(ex) ? nothing : values(first(ex))[1]
1515
end
1616

1717
#-----------------------------------------------------------------------------# Node
18-
struct Node{T}
19-
id::Int
20-
props::T
18+
struct Node{T}
19+
id::Int
20+
props::T
2121
Node(id::Integer, props=nothing) = new{typeof(props)}(id, props)
2222
end
2323

24-
function Base.show(io::IO, o::Node)
24+
function Base.show(io::IO, o::Node)
2525
print(io, "Node($(o.id)) with props: ")
2626
print(io, o.props)
2727
end
2828

2929
#-----------------------------------------------------------------------------# Edge
30-
struct Edge{T}
31-
source::Int
32-
target::Int
33-
props::T
34-
function Edge(source::Integer, target::Integer, props=nothing)
30+
struct Edge{T}
31+
source::Int
32+
target::Int
33+
props::T
34+
function Edge(source::Integer, target::Integer, props=nothing)
3535
new{typeof(props)}(source, target, props)
3636
end
3737
end
@@ -47,7 +47,7 @@ end
4747
"""
4848
DB(file = ":memory", T = String)
4949
50-
Create a graph database (in memory by default).
50+
Create a graph database (in memory by default).
5151
- 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)`.
5252
- Node and edge properties will be interpreted as `T` in Julia: `JSON3.read(props, T)`
5353
@@ -61,7 +61,7 @@ Create a graph database (in memory by default).
6161
- `target INTEGER`
6262
- `props TEXT` (via JSON3.write)
6363
64-
# Examples
64+
# Examples
6565
6666
db = DB()
6767
@@ -79,7 +79,7 @@ struct DB{T}
7979
SQLite.@register db SQLite.regexp
8080
statements = [
8181
"CREATE TABLE IF NOT EXISTS nodes (
82-
id INTEGER NOT NULL UNIQUE,
82+
id INTEGER NOT NULL UNIQUE,
8383
props TEXT,
8484
UNIQUE(id) ON CONFLICT REPLACE
8585
);",
@@ -96,7 +96,7 @@ struct DB{T}
9696
"CREATE INDEX IF NOT EXISTS target_idx ON edges(target);"
9797
]
9898
# workaround because sqlite won't run multiple statements at once
99-
map(statements) do x
99+
map(statements) do x
100100
execute(db, x)
101101
end
102102
new{T}(db)
@@ -105,7 +105,7 @@ end
105105
DB(T::Type, file::String = ":memory:") = DB(file, T)
106106
DB(T::Type, db::DB) = DB(db.sqlitedb, T)
107107
DB(db::DB, T::Type) = DB(T, db)
108-
function Base.show(io::IO, db::DB{T}) where {T}
108+
function Base.show(io::IO, db::DB{T}) where {T}
109109
print(io, "SQLiteGraph.DB{$T}(\"$(db.sqlitedb.file)\") ($(n_nodes(db)) nodes, $(n_edges(db)) edges)")
110110
end
111111

@@ -131,14 +131,14 @@ function Base.iterate(db::DB, state = (length(db), 1))
131131
Node(state[2], res), (state[1], state[2] + 1)
132132
end
133133

134-
# #-----------------------------------------------------------------------------# ReadAs
134+
# #-----------------------------------------------------------------------------# ReadAs
135135
# struct ReadAs{T}
136-
# db::DB
136+
# db::DB
137137
# end
138138
# ReadAs(db::DB, T::DataType=Dict{String,Any}) = ReadAs{T}(db)
139139
# Base.show(io::IO, r::ReadAs{T}) where {T} = (print(io, "ReadAs{$T}: "); print(io, r.db))
140140
# Base.setindex!(r::ReadAs, args...) = setindex!(r.db, args...)
141-
# function Base.getindex(r::ReadAs{T}, args...) where {T}
141+
# function Base.getindex(r::ReadAs{T}, args...) where {T}
142142
# res=r.db[args...]; isnothing(res) ? res : JSON3.read.(res, T)
143143
# end
144144

@@ -167,7 +167,7 @@ function Base.deleteat!(db::DB, id::Integer)
167167
end
168168
#-----------------------------------------------------------------------------# find_nodes
169169
function find_nodes(db::DB; kw...)
170-
param = join(map(collect(kw)) do kw
170+
param = join(map(collect(kw)) do kw
171171
k, v = kw
172172
"json_extract(props, '\$.$k') = $v"
173173
end, " AND ")
@@ -186,7 +186,7 @@ function Base.setindex!(db::DB, props, i::Integer, j::Integer)
186186
execute(db, "INSERT INTO edges VALUES(?, ?, json(?))", (i, j, JSON3.write(props)))
187187
db
188188
end
189-
function Base.getindex(db::DB, i::Integer, j::Integer)
189+
function Base.getindex(db::DB, i::Integer, j::Integer)
190190
res = single_result_execute(db, "SELECT props FROM edges WHERE source = ? AND target = ? ", (i,j))
191191
isnothing(res) ? res : Edge(i, j, res)
192192
end
@@ -218,7 +218,7 @@ end
218218

219219
#-----------------------------------------------------------------------------# find_edges
220220
function find_edges(db::DB; kw...)
221-
param = join(map(collect(kw)) do kw
221+
param = join(map(collect(kw)) do kw
222222
k, v = kw
223223
"json_extract(props, '\$.$k') = $v"
224224
end, " AND ")

0 commit comments

Comments
 (0)