A Graph Database for Julia, built on top of SQLite.jl.
SQLiteGraph.jl uses the Property Graph Model of the Cypher Query Language (PDF).
- A Node describes a discrete object in a domain.
- Nodes can have 0+ labels that classify what kind of node they are.
- An Edge describes a directional relationship between nodes.
- An edge must have a type that classifies the relationship.
- Both edges and nodes can have additional key-value properties that provide further information.
- Nodes and Edges have a simple representation:
struct Node
id::Int
labels::Vector{String}
props::EasyConfig.Config
end
struct Edge
source::Int
target::Int
type::String
props::EasyConfig.Config
end
- With simple constructors:
Node(id, labels...; props...)
Edge(source_id, target_id, type; props...)
using SQLiteGraph
db = DB()
insert!(db, Node(1, "Person", "Actor"; name="Tom Hanks"))
insert!(db, Node(2, "Movie"; title="Forest Gump"))
insert!(db, Edge(1, 2, "Acts In"; awards=["Best Actor in a Leading Role"]))
insert!
will not replace an existing node or edge. Instead, use replace!
.
replace!(db, Node(2, "Movie"; title="Forest Gump", genre="Drama"))
- Use
getindex
to access elements. - If
:
is used as an index, an iterator is returned. - If
s::String
is used as an index, an iterator of nodes wheres
is one of the labels is returned.
db[1] # Node(1, "Person", "Actor"; name="Tom Hanks")
for node in db[:]
println(node)
end
only(db["Movie"]) # Node(2, "Movie"; title="Forest Gump", genre="Drama")
# (Pretend the graph is populated with many more items. The following return iterators.)
db[1, :, "Acts In"] # All movies that Tom Hanks acts in
db[:, 2, "Acts In"] # All actors in "Forest Gump"
db[1, 2, :] # All relationships between "Tom Hanks" and "Forest Gump"
db[:, :, :] # All edges
SQLiteGraph is STRONGLY influenced by https://github.com/dpapathanasiou/simple-graph.
- Nodes and edges are saved in the
nodes
andedges
tables, respectively. nodes
id
(INTEGER
): unique identifier of a nodelabels
(TEXT
): stored as;
-delimited (thus;
cannot be used in a label)props
(TEXT
): stored asJSON3.write(props)
edges
source
(INTEGER
): id of "from" node (nodes(id)
is a foreign key)target
(INTEGER
): id of "to" node (nodes(id)
is a foreign key)type
(TEXT
): the "class" of the edge/relationshipprops
(TEXT
)