aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-03-27 22:48:57 +0300
committerBonfaceKilz2023-04-05 16:17:11 +0300
commit274c4cc42c5451fd073f577bf1592aed091dacf7 (patch)
tree63689086a579a55a648573dd99b52c93a463ca9d
parent396f32999ad1270df79ebde2f8be236f3413118e (diff)
downloadgn-transform-databases-274c4cc42c5451fd073f577bf1592aed091dacf7.tar.gz
Allow running raw queries in field form
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rwxr-xr-xdump.scm7
-rw-r--r--dump/sql.scm4
2 files changed, 8 insertions, 3 deletions
diff --git a/dump.scm b/dump.scm
index 112086b..b05af85 100755
--- a/dump.scm
+++ b/dump.scm
@@ -134,6 +134,7 @@ association list mapping substrings to their replacements."
#`(key #,(symbol->string
(syntax->datum
((syntax-rules (field)
+ ((field (query alias)) alias)
((field table column) column)
((field table column alias) alias)
((field table column operation alias) alias))
@@ -149,6 +150,7 @@ ALIST field-name) forms."
#,(symbol->string
(syntax->datum
((syntax-rules (field)
+ ((field (query alias)) alias)
((field table column) column)
((field table column alias) alias)
((field table column operation alias) alias))
@@ -311,7 +313,10 @@ must be remedied."
((table-name column-name _ ...)
(datum->syntax
x (column-id (symbol->string table-name)
- (symbol->string column-name))))))
+ (symbol->string column-name))))
+ (((query alias))
+ (datum->syntax
+ x (column-id query (symbol->string alias))))))
(collect-fields predicate-clause))))
#,(dump-id dump-table (syntax->datum #'predicate)))
;; Automatically create domain triples
diff --git a/dump/sql.scm b/dump/sql.scm
index 54371a2..76c9e0e 100644
--- a/dump/sql.scm
+++ b/dump/sql.scm
@@ -29,12 +29,12 @@
(_ ""))
#,(string-join (filter-map (match-lambda
('distinct #f)
+ (((query alias))
+ (format #f "~a AS ~a" query alias))
((table column)
(format #f "~a.~a" table column))
((table column alias)
(format #f "~a.~a AS ~a" table column alias))
- ((table column operation alias)
- (format #f "~a(~a.~a) AS ~a" operation table column alias))
(field-spec
(error "Invalid field specification" field-spec)))
(syntax->datum #'fields))