diff options
author | Munyoki Kilyungi | 2023-07-11 11:03:45 +0300 |
---|---|---|
committer | BonfaceKilz | 2023-07-30 12:29:56 +0300 |
commit | 75126b1b7889769fa11dc928cf481796cf9d24a5 (patch) | |
tree | 4c9268c98b59839d4d4c199c67514343efbc5449 /dump | |
parent | d9955860338facec2d36a80ef8959254ac4ef928 (diff) | |
download | gn-transform-databases-75126b1b7889769fa11dc928cf481796cf9d24a5.tar.gz |
Construct example SQL query and expected results
Diffstat (limited to 'dump')
-rw-r--r-- | dump/special-forms.scm | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/dump/special-forms.scm b/dump/special-forms.scm index 2281f23..78ee879 100644 --- a/dump/special-forms.scm +++ b/dump/special-forms.scm @@ -485,7 +485,7 @@ The following SQL query was executed: ~a ``` -Triples take the form: +The above query results to triples that have the form: " (select-query #,(collect-fields #'(subject predicate-clauses ...)) @@ -498,8 +498,41 @@ Triples take the form: predicate object))) (map-alist '() - #,@(field->datum #'subject))) - (format out "~%") + #,@(field->datum #'(predicate-clauses ...)))) + (format out "~%Here's an example query:~%~%") + (let* ((result + (map-alist (sql-find + db + (format #f "~a LIMIT 1" + (select-query #,(collect-fields #'(subject predicate-clauses ...)) + (primary-table other-tables ...) + tables-raw ...))) + #,@(field->key #'(predicate-clauses ...)))) + (first-n (list-head result (truncate (/ (length result) 2))))) + (format out "SELECT ?s ?p ?o WHERE { ~%") + (for-each (match-lambda + ((predicate . object) + (format out + (match object + ((or (? symbol? object) + (? (lambda (el) (string-match "^\\[ .* \\]$" el)) object)) + " ?s ~a ~a .~%") + (_ " ?s ~a \"~a\" .~%")) + predicate object))) + first-n) + (format out " ?s ?p ?o .~%}~%")) + (format out "~%Expected Result:~%~%") + (sql-for-each (lambda (row) + (scm->triples + (map-alist row #,@(field->key #'(predicate-clauses ...))) + #,(field->assoc-ref #'row #'subject) + (lambda (s p o) + (triple s p o out)))) + db + (format #f "~a LIMIT 1" + (select-query #,(collect-fields #'(subject predicate-clauses ...)) + (primary-table other-tables ...) + tables-raw ...))) ;; To clear the buffer (force-output out))) (when (dump-configuration-triples? dump-configuration) |