1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00

Update How-to-get-result-set-suitable-for-graph-visualisation.md

This commit is contained in:
lana-k
2025-11-01 20:10:28 +01:00
committed by GitHub
parent ae39f9e66e
commit 07409a0e20

View File

@@ -1,6 +1,6 @@
# How to get result set suitable for graph visualisation # How to get result set suitable for graph visualisation
There are some requirements for result sets if you want to build a graph. There are some [requirements][1] for result sets if you want to build a graph.
Here is an example of building a query that returns a result set appropriate for graph visualisation. Here is an example of building a query that returns a result set appropriate for graph visualisation.
Let's say, you have 2 tables: Let's say, you have 2 tables:
@@ -25,7 +25,8 @@ student:
Each student belongs to a certain house. Each student belongs to a certain house.
Let's say you want to build a graph with houses and students as nodes, where each house is linked with its students. Let's say you want to build a graph with houses and students as nodes, where each house is linked with its students.
We are going to use [json_object][1] function to form JSONs. The result set should contain both nodes and edges and we have to provide a field indicating that (0 - for nodes and 1 - for edges). Let's provide it as 'object_type': We are going to use [json_object][2] function to form JSONs. The result set should contain both nodes and edges
and we have to provide a field indicating that (0 - for nodes and 1 - for edges). Let's provide it as 'object_type':
```sql ```sql
SELECT json_object('object_type', 0) SELECT json_object('object_type', 0)
@@ -99,3 +100,6 @@ Run the query, the result set will look like this:
| {"object_type":1,"node_source":"Slytherin","target":3} | | {"object_type":1,"node_source":"Slytherin","target":3} |
| {"object_type":1,"node_source":"Ravenclaw","target":4} | | {"object_type":1,"node_source":"Ravenclaw","target":4} |
| {"object_type":1,"node_source":"Hufflepuff","target":5} | | {"object_type":1,"node_source":"Hufflepuff","target":5} |
[1]: ./graph
[2]: https://sqlite.org/json1.html#jobj