Add order-by clause

This commit is contained in:
Jeremy Dormitzer 2020-06-03 17:55:12 -04:00
parent e86983d522
commit 5b8b758c1a

View File

@ -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"