From 5b8b758c1aad015d882bc30b3eef19a4aedf16c8 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Wed, 3 Jun 2020 17:55:12 -0400 Subject: [PATCH] Add order-by clause --- structlog-mode.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/structlog-mode.el b/structlog-mode.el index 9102fe0..ec92b44 100644 --- a/structlog-mode.el +++ b/structlog-mode.el @@ -70,6 +70,9 @@ ":select [time event] :limit 100" "Default query for `structlog' command") +(defvar structlog-time-field 'time + "The structlog field designating the log timestamp") + (defun structlog--query-db (query) "Runs `query' against the database, returning a list of lists" (dolist (var '(structlog-db-username @@ -110,10 +113,14 @@ (let ((base (format "SELECT %s FROM %s" structlog-db-record-field structlog-db-table)) + (order-by (format "ORDER BY %s->'%s'" + structlog-db-record-field + structlog-time-field)) (limit (plist-get query :limit))) - (concat base + (concat base " " + order-by " " (when limit - (format " LIMIT %s" limit))))) + (format "LIMIT %s" limit))))) (defun structlog--make-list-entries () "Makes the tabulated-list-mode entries list for structlog"