diff options
author | Munyoki Kilyungi | 2023-07-11 11:03:45 +0300 |
---|---|---|
committer | Munyoki Kilyungi | 2023-07-21 14:36:37 +0300 |
commit | 07d1e79fa6cd1294f97394f15fa20da721cb32af (patch) | |
tree | 4c9268c98b59839d4d4c199c67514343efbc5449 | |
parent | e0de65a1ea4eee21b9d42586145bb2a41ca3c958 (diff) | |
download | gn-transform-databases-07d1e79fa6cd1294f97394f15fa20da721cb32af.tar.gz |
Construct example SQL query and expected results
-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) |