From ea43eb9bfb4acbc9aa882a3ca3b44a506e3330ed Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 24 Dec 2021 14:58:17 +0530 Subject: Fetch entire table schema in single SPARQL query. * visualize-schema.scm (tables): Fetch entire table schema in single SPARQL query. --- visualize-schema.scm | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'visualize-schema.scm') diff --git a/visualize-schema.scm b/visualize-schema.scm index af86477..8fa27a6 100644 --- a/visualize-schema.scm +++ b/visualize-schema.scm @@ -118,33 +118,27 @@ return #f. ALL-TABLES is a list of all tables in the database." "Return list of all tables in DB. Each element of the returned list is a object." (map (match-lambda - ((table size) + ((table size fields field-types field-dumped) (make-table table - ;; FIXME: Why is size coming out as a string? (string->number size) - (map (match-lambda - ((field type) (make-column field type))) - (sparql-query-records - ;; We use format to construct the query instead of - ;; select due to an outstanding bug in - ;; guile-sparql. See - ;; https://github.com/roelj/guile-sparql/issues/5 - (format - "SELECT ?fieldname ?fieldtype + (map make-column + (string-split fields #\,) + (string-split field-types #\,) + (map (cut string=? <> "1") + (string-split field-dumped #\,)))))) + (sparql-query-records + "PREFIX gn: +SELECT SAMPLE(?tablename) SAMPLE(?size) GROUP_CONCAT(?fieldname ; separator=\",\") GROUP_CONCAT(?fieldtype ; separator=\",\") GROUP_CONCAT(EXISTS{ ?dump rdf:type gn:dump . ?dump gn:dependsOn ?field .} ; separator=\",\") WHERE { - ?table . - ?table ~s . - ?field . - ?table ?field . - ?field ?fieldname . - ?field ?fieldtype . -}" table)))))) - (sparql-query-records - (select '(tablename size) - `((table ,(rdf "type") ,(gn "sqlTable")) - (table ,(gn "name") tablename) - (table ,(gn "hasSize") size)))))) + ?table rdf:type gn:sqlTable ; + gn:name ?tablename ; + gn:hasSize ?size ; + gn:hasField ?field . + ?field rdf:type gn:sqlTableField ; + gn:name ?fieldname ; + gn:sqlFieldType ?fieldtype . +} GROUP BY ?table"))) (define (foreign-key-graphviz-edges tables) "Return the list of graphviz edges representing foreign key -- cgit v1.2.3