fix(dev): script fails on -h

Also minor db scripts cleanup
This commit is contained in:
Gabriel Horner
2025-03-06 16:21:21 -05:00
parent 9828b15b51
commit c6a2ea6959
5 changed files with 10 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
(ns query
"An example script that queries any db graph from the commandline e.g.
"A script that queries any db graph from the commandline e.g.
$ yarn -s nbb-logseq script/query.cljs db-name '[:find (pull ?b [:block/name :block/title]) :where [?b :block/created-at]]'"
(:require [datascript.core :as d]
@@ -44,8 +44,8 @@
:desc "Lookup entities instead of query"}})
(defn -main [args]
(let [[graph-dir & args'] args
options (cli/parse-opts args' {:spec spec})
(let [{options :opts args' :args} (cli/parse-args args {:spec spec})
[graph-dir & args''] args'
_ (when (or (nil? graph-dir) (:help options))
(println (str "Usage: $0 GRAPH-NAME [& ARGS] [OPTIONS]\nOptions:\n"
(cli/format-opts {:spec spec})))
@@ -60,7 +60,7 @@
(update :block/properties (fn [props] (map (fn [m] (into {} m)) props)))))
(:entity options))
;; assumes no :in are in queries
(let [query (into (edn/read-string (first args')) [:in '$ '%])
(let [query (into (edn/read-string (first args'')) [:in '$ '%])
res (d/q query @conn (rules/extract-rules rules/db-query-dsl-rules))]
;; Remove nesting for most queries which just have one :find binding
(if (= 1 (count (first res))) (mapv first res) res)))]