[racket] A language mode for SQL

57 views
Skip to first unread message

Sean McBeth

unread,
May 8, 2013, 2:49:56 PM5/8/13
to users
Is there a language mode for Racket, or perhaps a 3rd party library, that can do basic syntax checking for ANSI SQL? I hate writing a query, starting the app, getting through the UI to the point I'm working on, executing a command, and only THEN learning I have a syntax error from accidentally typing a period instead of a comma or some-such issue. It'd be nice if there were some set of macros that understood the basic SQL syntax could be used to generate arbitrary queries.

I'm also not looking for an ORM. I don't need anything that tries to abstract the SQL away from me, as I am often in need of rather complex queries. I just want a thing that can check my syntax for my live code sometime before run-time.

If there is no such thing currently, I'd be highly motivated to trying my hand at writing such a thing.

Stephen De Gabrielle

unread,
May 9, 2013, 12:02:50 PM5/9/13
to Sean McBeth, users
Hi,
I can't find one for SQL, but there do seem to be some other modes on
Planet you could take a look at:
https://www.google.co.uk/search?q=%22add-mode%22+site:planet.racket-lang.org

'add-mode' is documented at http://docs.racket-lang.org/tools/Editor_Modes.html

Weirdly Datalog on planet seems to have a editor mode, but it doesn't
seem to be
in datalog as distrubuted with DrRacket (full?) version
5.3.2.2--2013-01-26(295bb1e/a) [3m].
(maybe I'm not looking hard enough - or I have an old instance - I'll
check again wehn I get home)

HTH,

Stephen
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
____________________
Racket Users list:
http://lists.racket-lang.org/users

Neil Van Dyke

unread,
May 9, 2013, 12:34:08 PM5/9/13
to Sean McBeth, users
There have been several SQL-in-sexp libraries over the years. When done
as Racket syntax extension, they can do some compile-type syntax
checking. They also can automatically do escaping of values to avoid
SQL injection attacks. The library I've used most recently is
unfortunately closed source, but there were others for PLT Scheme in the
past; try Googling.

Neil V.

Jay McCarthy

unread,
May 9, 2013, 1:52:44 PM5/9/13
to Stephen De Gabrielle, users
On Thu, May 9, 2013 at 10:02 AM, Stephen De Gabrielle
<stephen.d...@acm.org> wrote:
> Weirdly Datalog on planet seems to have a editor mode, but it doesn't
> seem to be
> in datalog as distrubuted with DrRacket (full?) version
> 5.3.2.2--2013-01-26(295bb1e/a) [3m].
> (maybe I'm not looking hard enough - or I have an old instance - I'll
> check again wehn I get home)

I switched Datalog to be a #lang and they can't communicate edit-modes
to DrRacket.

Jay

--
Jay McCarthy <j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Stephen De Gabrielle

unread,
May 10, 2013, 7:53:39 AM5/10/13
to Jay McCarthy, users
That's a shame,

Anyway, I took a punt and created a tool by lifting http://planet.racket-lang.org/package-source/jaymccarthy/datalog.plt/1/0/drscheme/tool.ss into its own collection.
I gave it a folder and an info.rkt file and popped it into collects.  
(raco setup datalog-editor-mode & restart DrRacket to install )

Seems to work OK as example, but I can't work out how to get it to select the mode based on file extension on loading the document. Currently it defaults to racket mode.

I think I should be overriding a method 'mode:surrogate-text%', but I can't work out from the documentation, as everything 'Returns the result of invoking call-super.' but a search for 'call-super' turns up noting. Any suggestions from the list appreciated :)


  1.     (define datalog:surrogate-text% ;; keep
  2.       (class mode:surrogate-text%
  3.         (define/override (put-file text sup directory default-name)
  4.           (parameterize ([finder:default-filters
  5.                           (list (list "Prolog (.prolog)" "*.prolog")
  6.                                 (list "Datalog (.datalog)" "*.datalog")
  7.                                 (list "Any" "*.*"))]
  8.                          [finder:default-extension "datalog"])
  9.             (sup directory default-name)))
  10.       
  11.         (super-make-object)))


Stephen
tool.rkt
info.rkt
Reply all
Reply to author
Forward
0 new messages