about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2021-12-24 15:08:55 +0530
committerArun Isaac2021-12-24 15:08:55 +0530
commit31a43fc346f82e24f0740a162c3372454297fa54 (patch)
tree2d43bba61e2e5d3c1d3c004366aac0876c40d703
parent23963b66d278fcbb7c25bb5bb2e26791d0afa2d6 (diff)
downloadgn-transform-databases-31a43fc346f82e24f0740a162c3372454297fa54.tar.gz
Wrap SQL visualization code into a function.
* visualize-schema.scm (write-sql-visualization, main): New functions.
Invoke main.
-rw-r--r--visualize-schema.scm30
1 files changed, 20 insertions, 10 deletions
diff --git a/visualize-schema.scm b/visualize-schema.scm
index 6fb7479..be1b9e4 100644
--- a/visualize-schema.scm
+++ b/visualize-schema.scm
@@ -166,13 +166,23 @@ relations in TABLES."
                             (table-columns table)))
               tables))
 
-(let ((all-tables (tables)))
-  ((@@ (ccwl graphviz) graph->dot)
-   ((@@ (ccwl graphviz) graph) 'schema
-    #:nodes (map (lambda (table)
-                   ((@@ (ccwl graphviz) graph-node)
-                    (table-name table)
-                    `((shape . "none")
-                      (label . ,(table-label table)))))
-                 all-tables)
-    #:edges (foreign-key-graphviz-edges all-tables))))
+(define (write-sql-visualization port)
+  "Write a visualization of the SQL schema in graphviz dot syntax to
+PORT."
+  (let ((all-tables (tables)))
+    (graph->dot
+     (graph 'schema
+            #:nodes (map (lambda (table)
+                           (graph-node
+                            (table-name table)
+                            `((shape . "none")
+                              (label . ,(table-label table)))))
+                         all-tables)
+            #:edges (foreign-key-graphviz-edges all-tables))
+     port)))
+
+(define (main)
+  (call-with-output-file "sql.dot"
+    write-sql-visualization))
+
+(main)