(module query-util mzscheme
(require (file "base.ss")
(prefix era: (file "era.ss"))
(file "query-core.ss")
(prefix q: (file "query-lang.ss")))
(define (let-alias-item name item)
(cond [(era:entity? item)
(q:entity name item)]
[(symbol? item)
(q:table name item)]
[(or (field? item) (aggregate? item) (table? item) (entity? item) (select? item))
item]
[else (raise-exn exn:fail:snooze
(format "let-alias: ~a: expected (U era-entity table-name-symbol any-what-item), received ~a."
name
item))]))
(define-syntax (let-alias stx)
(syntax-case stx ()
[(_ ([identifier item] ...) stmt ...)
#'(let ([identifier (let-alias-item 'identifier item)] ...)
stmt ...)]))
(define-syntax (let*-alias stx)
(syntax-case stx ()
[(_ ([identifier item] ...) stmt ...)
#'(let* ([identifier (let-alias-item 'identifier item)] ...)
stmt ...)]))
(provide let-alias
let*-alias)
)