From 01621d74fe5a095546099fc9d45b66cb83e2a4e9 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 20 Feb 2017 01:21:45 +0000 Subject: [PATCH] Add websocket endpoint for sql text queries --- web/routes.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/web/routes.go b/web/routes.go index 3a0b650c..b7ff3f2a 100644 --- a/web/routes.go +++ b/web/routes.go @@ -117,6 +117,31 @@ func routes(s *fibre.Fibre) { return c.Send(200, res) }) + s.Get("/sql", func(c *fibre.Context) error { + + if err := c.Upgrade(); err != nil { + return err + } + + for { + + _, msg, err := c.Socket().Read() + if err != nil { + return err + } + + if res, err := db.Execute(c, msg, nil); err != nil { + c.Socket().SendText(err.Error()) + } else { + c.Socket().SendJSON(res) + } + + } + + return nil + + }) + // -------------------------------------------------- // Endpoints for manipulating multiple records // --------------------------------------------------