On Tuesday, August 1, 2017 at 8:45:25 PM UTC+8, david.vanderson wrote:
> On 07/31/2017 10:46 PM, Alex Harsanyi wrote:
> > Unfortunately, `define-runtime-path` can only be used at top-level, so the
> > above code does not compile.  It works fine without the 
> > `define-runtime-path',
> > I need to use it so they query files are found when the application is
> > compiled to a stand-alone executable.
> >
> > Does anyone have an idea on how `sql-query` might be defined?
> 
> Maybe not the best solution, but you can put define-runtime-path for the 
> containing directory at the module level.  Does this work for you?

No, not really, as I would like the entire relative path to be present in the 
"sql-query" form, so "C-c C-e" in Emacs and "gf" in vim will directly open the 
file.

Adding the current directory, as was suggested in another message by David, 
would not work either, as "sql-query" would be defined in a separate file and 
used throughout the code base.

After thinking about it for a bit, I came up with a "define-sql-query" macro.  
This has the disadvantage that queries can only be defined at top-level, but 
other than that, seems to work ok:

    (define-syntax (define-sql-query stx)
      (syntax-case stx ()
        [(_ id file-name)
         #'(begin
             (define-runtime-path rp file-name)
             (define id
               (let ([qtext #f])
                 (virtual-statement
                  (lambda (dbsys)
                    (unless qtext
                      (set! qtext (file->string rp)))
                    qtext)))))]))

    (define-sql-query q1 "./q.sql")
    (define-sql-query q2 "./q2.sql")

Best Regards,
Alex.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to