ArangoDB-Community / pyArango

Python Driver for ArangoDB with built-in validation
https://pyarango.readthedocs.io/en/latest/
Apache License 2.0
238 stars 90 forks source link

Added support for satellite graphs #175

Closed hkernbach closed 4 years ago

hkernbach commented 4 years ago

Also added two new graph (cluster) option parameters:

See: https://www.arangodb.com/docs/stable/http/gharial-management.html#create-a-graph

Simple example:

from pyArango.connection import *
from pyArango.collection import Collection, Edges, Field
from pyArango.graph import Graph, EdgeDefinition

databaseName = "satellite_graph_db"

conn = Connection()

# Cleanup (if needed)
try:
    conn.createDatabase(name=databaseName)
except Exception:
    pass

# Select our "satellite_graph_db" database
db = conn[databaseName] # all databases are loaded automatically into the connection and are accessible in this fashion

# Define our vertex to use
class Humans(Collection):
    _fields = {
        "name": Field()
    }

# Define our edge to use
class Friend(Edges):
    _fields = {
        "lifetime": Field()
    }

# Here's how you define a Satellite Graph
class MySatelliteGraph(Graph) :
    _edgeDefinitions = [EdgeDefinition("Friend", fromCollections=["Humans"], toCollections=["Humans"])]
    _orphanedCollections = []

theSatelliteGraph = db.createSatelliteGraph("MySatelliteGraph")
joerg84 commented 4 years ago

@hkernbach Do you want to add the example from the description to the readme or is that too much detail?

hkernbach commented 4 years ago

@joerg84 I think that would be nice, but keep in mind that 3.7 is not released yet

codecov-io commented 4 years ago

Codecov Report

Merging #175 into master will decrease coverage by 0.05%. The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #175      +/-   ##
==========================================
- Coverage   78.13%   78.08%   -0.06%     
==========================================
  Files          17       17              
  Lines        2946     2952       +6     
==========================================
+ Hits         2302     2305       +3     
- Misses        644      647       +3     
Impacted Files Coverage Δ
pyArango/database.py 56.04% <57.14%> (-0.14%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 4eae333...26ab1e0. Read the comment docs.

hkernbach commented 4 years ago

Besides the writeConcern fixed at None, I don't see anything wrong with this PR. It's pretty cool.

Ups, writeConcern can be fully removed as a parameter in the new function. It will be set internally by the server automatically. The parameter will be ignored anyway.

joerg84 commented 4 years ago

@tariqdaouda Can we merge this?