@@ -14,9 +14,9 @@ function single_result_execute(db, stmt, args...)
1414end
1515
1616function print_props (io:: IO , o:: Config )
17- for (k,v) in pairs (o)
18- printstyled (io, " \n • $k : " , color = :light_black )
19- print (IOContext ( io, :compat => true ), v )
17+ for (i,( k,v)) in enumerate ( pairs (o) )
18+ print (io, k, ' = ' , v )
19+ i == length (o) || print (io, " , " )
2020 end
2121end
2222
@@ -32,11 +32,11 @@ Node(row::SQLite.Row) = Node(row.id, split(row.labels, ';', keepempty=false), JS
3232function Base. show (io:: IO , o:: Node )
3333 print (io, " Node($(o. id) " )
3434 ! isempty (o. labels) && print (io, " , " , join (repr .(o. labels), " , " ))
35- ! isempty (o. props) && print (io, " ; " , ( " $k = $v " for (k,v) in pairs ( o. props)) . .. )
35+ ! isempty (o. props) && print (io, " ; " ); print_props (io, o. props)
3636 print (io, ' )' )
3737end
3838args (n:: Node ) = (n. id, isempty (n. labels) ? " " : join (n. labels, ' ;' ), JSON3. write (n. props))
39- Base.:( == )(a :: Node , b :: Node ) = all ( getfield (a,f) == getfield (b,f) for f in fieldnames (Node))
39+
4040
4141
4242struct Edge
@@ -49,12 +49,21 @@ Edge(src::Int, tgt::Int, type::String; props...) = Edge(src, tgt, type, Config(p
4949Edge (row:: SQLite.Row ) = Edge (row. source, row. target, row. type, JSON3. read (row. props, Config))
5050function Base. show (io:: IO , o:: Edge )
5151 print (io, " Edge($(o. source) , $(o. target) , " , repr (o. type))
52- ! isempty (o. props) && print (io, " ; " , ( " $k = $v " for (k,v) in pairs ( o. props)) . .. )
52+ ! isempty (o. props) && print (io, " ; " ); print_props (io, o. props)
5353 print (io, ' )' )
5454end
5555args (e:: Edge ) = (e. source, e. target, e. type, JSON3. write (e. props))
56+
57+
58+ # -----------------------------------------------------------------------------# Base methods
59+ Base.:(== )(a:: Node , b:: Node ) = all (getfield (a,f) == getfield (b,f) for f in fieldnames (Node))
5660Base.:(== )(a:: Edge , b:: Edge ) = all (getfield (a,f) == getfield (b,f) for f in fieldnames (Edge))
5761
62+ Base. pairs (o:: T ) where {T<: Union{Node, Edge} } = (f => getfield (o,f) for f in fieldnames (T))
63+
64+ Base. NamedTuple (o:: Union{Node,Edge} ) = NamedTuple (pairs (o))
65+
66+
5867
5968# -----------------------------------------------------------------------------# DB
6069struct DB
@@ -70,7 +79,6 @@ struct DB
7079 labels TEXT NOT NULL,
7180 props TEXT NOT NULL
7281 );" ,
73-
7482 # edges
7583 " CREATE TABLE IF NOT EXISTS edges (
7684 source INTEGER NOT NULL REFERENCES nodes(id),
0 commit comments