Add edge_type support to graph table and API
- New column edge_type varchar(30) in graph table - GET /api/graph/edges returns edge_type (defaults to "db" if null) - POST /api/graph/edges accepts type parameter and stores as edge_type Types: mirror, sequence, composition, dependency, maturity, manual, db
This commit is contained in:
6
app.py
6
app.py
@@ -240,8 +240,8 @@ if __name__ == "__main__":
|
||||
def api_graph_edges():
|
||||
conn = get_db()
|
||||
cur = conn.cursor()
|
||||
cur.execute("SELECT id, h_a, h_b, weight FROM graph ORDER BY weight DESC")
|
||||
edges = [{"id": r[0], "source_h": r[1], "target_h": r[2], "weight": r[3], "type": "db"} for r in cur.fetchall()]
|
||||
cur.execute("SELECT id, h_a, h_b, weight, edge_type FROM graph ORDER BY weight DESC")
|
||||
edges = [{"id": r[0], "source_h": r[1], "target_h": r[2], "weight": r[3], "type": r[4] or "db"} for r in cur.fetchall()]
|
||||
cur.close()
|
||||
conn.close()
|
||||
return jsonify({"count": len(edges), "edges": edges})
|
||||
@@ -259,7 +259,7 @@ def api_graph_edges_create():
|
||||
|
||||
conn = get_db()
|
||||
cur = conn.cursor()
|
||||
cur.execute("INSERT INTO graph (h_a, h_b, weight) VALUES (%s, %s, %s) RETURNING id", (source_h, target_h, weight))
|
||||
cur.execute("INSERT INTO graph (h_a, h_b, weight, edge_type) VALUES (%s, %s, %s, %s) RETURNING id", (source_h, target_h, weight, edge_type))
|
||||
new_id = cur.fetchone()[0]
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
Reference in New Issue
Block a user