results are stale
Closed this issue · 3 comments
hi! thanks for this project - this is exactly what I was looking for :D
any idea why my results appear to be stale? I have only one logseq
graph, which I've already set as my default:
; ~/.lq/config.edn
{:default-options {:graph "logseq"}}
running a sq
on the command line:
$ lq sq -C '[[?b :block/refs ?bp] [?bp :block/name "my-tag"] (not (task ?b #{"DONE" "CANCELED" "WAITING"}))]'
- TODO item 1 [[my-tag]]
- TODO item 2 [[my-tag]]
- TODO item 3 [[my-tag]]
but when I look in my logseq
"item 3" is very clearly already marked as DONE
:/
also no idea if the extra newline after "item 2" is relevant - it doesn't appear to exist on the block in logseq
, even opening up the journal in a text editor shows that there's no newline in that "item 2" block
going into the logseq app & running a re-index fixed the problem - but then how did the graph get out of sync in the first place? ideally I wouldn't have to re-index before running a query
looks like this was addressed in the nbb-logseq
project: logseq/nbb-logseq#1 - now looking into making a script that will parse the graph every time
in any case this issue is obsolete!
here's the script I hacked up in case it helps anyone else
(ns query
"Script that queries a local graph with given query"
(:require [datascript.core :as d]
[clojure.pprint :as pprint]
[clojure.edn :as edn]
[nbb.core :as nbb]
[logseq.db.rules :as rules]
[logseq.graph-parser.cli :as gp-cli]))
(defn -main
[args]
(if-not (= 2 (count args))
(println "Usage: $0 GRAPH-DIR QUERY")
(let [[graph-dir query] args
query' (edn/read-string query)
add-rules-where? (not (contains? (set query') :where))
add-rules-find? (not (contains? (set query') :find))
add-rules-in? (not (contains? (set query') :in))
query'' (if add-rules-where? (into [:where] query') query')
query''' (if add-rules-find? (into query'' [:find '(pull ?b [*])]) query'')
query'''' (if add-rules-in? (into query''' [:in '$ '%]) query''')
{:keys [conn]} (gp-cli/parse-graph graph-dir {:verbose false})
results (map first (apply d/q query'''' @conn [(vals rules/query-dsl-rules)]))]
(pprint/pprint results))))
(when (= nbb/*file* (:file (meta #'-main)))
(-main *command-line-args*))