fix: query function for db graphs

This commit is contained in:
Gabriel Horner
2024-06-06 10:56:50 -04:00
parent 7e6f5878d6
commit 3d9c606899
3 changed files with 37 additions and 38 deletions

View File

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