mirror of
https://github.com/logseq/logseq.git
synced 2026-04-29 00:24:51 +00:00
fix: query function for db graphs
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
Some fns like lookup and get-property were written to easily be backwards
|
||||
compatible with file graphs"
|
||||
(:require [frontend.state :as state]
|
||||
[frontend.db :as db]
|
||||
[logseq.db.sqlite.util :as sqlite-util]
|
||||
[frontend.db.conn :as conn]
|
||||
[frontend.db.utils :as db-utils]
|
||||
[logseq.db.frontend.property :as db-property]
|
||||
[logseq.db.frontend.property.util :as db-property-util]))
|
||||
|
||||
@@ -14,22 +14,23 @@
|
||||
(let [repo (state/get-current-repo)]
|
||||
(db-property-util/lookup repo coll key)))
|
||||
|
||||
(defn lookup-by-name
|
||||
"Get the value of coll's (a map) by name. Only use this
|
||||
for file graphs or for db graphs when user properties are involved"
|
||||
[coll key]
|
||||
(let [repo (state/get-current-repo)
|
||||
property-name (if (keyword? key) (name key) key)]
|
||||
(if (sqlite-util/db-based-graph? repo)
|
||||
(when-let [property (db/get-case-page property-name)]
|
||||
(get coll (:block/uuid property)))
|
||||
(get coll key))))
|
||||
(defn properties-by-name
|
||||
"Given a block from a query result, returns a map of its properties indexed by property names"
|
||||
[repo block]
|
||||
(->> (db-property/properties block)
|
||||
(map (fn [[k v]]
|
||||
[(:block/original-name (db-utils/entity k))
|
||||
(or (some->> (:db/id v)
|
||||
(db-utils/entity repo)
|
||||
db-property/get-property-value-name)
|
||||
v)]))
|
||||
(into {})))
|
||||
|
||||
(defn get-block-property-value
|
||||
"Get the value of a built-in block's property by its db-ident"
|
||||
[block db-ident]
|
||||
(let [repo (state/get-current-repo)
|
||||
db (db/get-db repo)]
|
||||
db (conn/get-db repo)]
|
||||
(db-property-util/get-block-property-value repo db block db-ident)))
|
||||
|
||||
(defn get-pid
|
||||
@@ -47,11 +48,11 @@
|
||||
(defn shape-block?
|
||||
[block]
|
||||
(let [repo (state/get-current-repo)
|
||||
db (db/get-db repo)]
|
||||
db (conn/get-db repo)]
|
||||
(db-property-util/shape-block? repo db block)))
|
||||
|
||||
(defn get-closed-property-values
|
||||
[property-id]
|
||||
(let [repo (state/get-current-repo)
|
||||
db (db/get-db repo)]
|
||||
db (conn/get-db repo)]
|
||||
(db-property/get-closed-property-values db property-id)))
|
||||
|
||||
Reference in New Issue
Block a user