1
0
Эх сурвалжийг харах

Add existing db attributes to properties

To bring more power to dsl query `(property db-attribute value)`.
Tienson Qin 1 жил өмнө
parent
commit
7785655062

+ 2 - 1
deps/db/src/logseq/db/frontend/malli_schema.cljs

@@ -117,7 +117,8 @@
                                       ;; This allows block types like property-value-block to require properties in
                                       ;; their schema that they depend on
                                       (not= :logseq.property/created-from-property k)
-                                      (d/entity db k))]
+                                      (d/entity db k)
+                                      (not (db-property/db-attribute-properties k)))]
                  (update m :block/properties (fnil conj [])
                          ;; use explicit call to be nbb compatible
                          [(let [closed-values (entity-plus/lookup-kv-then-entity property :property/closed-values)]

+ 90 - 1
deps/db/src/logseq/db/frontend/property.cljs

@@ -38,6 +38,90 @@
                                    :cardinality :many
                                    :public? true
                                    :classes #{:logseq.class/Root}}}
+   :kv/value             {:title "KV value"
+                          :attribute :kv/value
+                          :schema {:type :any
+                                   :public? false
+                                   :hide? true}}
+   :block/type           {:title "Node type"
+                          :attribute :block/type
+                          :schema {:type :string
+                                   :public? false
+                                   :hide? true}}
+   :block/schema         {:title "Node schema"
+                          :attribute :block/schema
+                          :schema {:type :map
+                                   :public? false
+                                   :hide? true}}
+   :block/parent         {:title "Node parent"
+                          :attribute :block/parent
+                          :schema {:type :entity
+                                   :public? false
+                                   :hide? true}}
+   :block/order          {:title "Node order"
+                          :attribute :block/order
+                          :schema {:type :string
+                                   :public? false
+                                   :hide? true}}
+   :block/collapsed?     {:title "Node collapsed?"
+                          :attribute :block/collapsed?
+                          :schema {:type :checkbox
+                                   :public? false
+                                   :hide? true}}
+   :block/page           {:title "Node page"
+                          :attribute :block/page
+                          :schema {:type :entity
+                                   :public? false
+                                   :hide? true}}
+   :block/refs           {:title "Node references"
+                          :attribute :block/refs
+                          :schema {:type :entity
+                                   :cardinality :many
+                                   :public? false
+                                   :hide? true}}
+   :block/path-refs      {:title "Node path references"
+                          :attribute :block/path-refs
+                          :schema {:type :entity
+                                   :cardinality :many
+                                   :public? false
+                                   :hide? true}}
+   :block/link           {:title "Node links to"
+                          :attribute :block/link
+                          :schema {:type :entity
+                                   :public? false
+                                   :hide? true}}
+   :block/title          {:title "Node title"
+                          :attribute :block/title
+                          :schema {:type :string
+                                   :public? false
+                                   :hide? true}}
+   :block/closed-value-property  {:title "Closed value property"
+                                  :attribute :block/closed-value-property
+                                  :schema {:type :entity
+                                           :public? false
+                                           :hide? true}}
+   :block/created-at     {:title "Node created at"
+                          :attribute :block/created-at
+                          :schema {:type :datetime
+                                   :public? false
+                                   :hide? true}}
+   :block/updated-at     {:title "Node updated at"
+                          :attribute :block/updated-at
+                          :schema {:type :datetime
+                                   :public? false
+                                   :hide? true}}
+   :property/schema.classes      {:title "Property classes"
+                                  :attribute :property/schema.classes
+                                  :schema {:type :entity
+                                           :cardinality :many
+                                           :public? false
+                                           :hide? true}}
+   :property.value/content       {:title "Property value"
+                                  :attribute :property.value/content
+                                  :schema {:type :any
+                                           :public? false
+                                           :hide? true}}
+
    :logseq.property.node/display-type {:title "Node Display Type"
                                        :schema {:type :keyword
                                                 :public? false
@@ -282,7 +366,12 @@
 
 (def db-attribute-properties
   "Internal properties that are also db schema attributes"
-  #{:block/alias :block/tags})
+  #{:block/alias :block/tags :kv/value :block/type :block/schema :block/parent
+    :block/order :block/collapsed? :block/page
+    :block/refs :block/path-refs :block/link
+    :block/title :block/closed-value-property
+    :block/created-at :block/updated-at
+    :property/schema.classes :property.value/content})
 
 (def read-only-properties
   "Property values that shouldn't be updated"

+ 1 - 1
deps/db/src/logseq/db/frontend/schema.cljs

@@ -2,7 +2,7 @@
   "Main datascript schemas for the Logseq app"
   (:require [clojure.set :as set]))
 
-(def version 35)
+(def version 36)
 
 ;; A page is a special block, a page can corresponds to multiple files with the same ":block/name".
 (def ^:large-vars/data-var schema

+ 11 - 8
src/main/frontend/components/views.cljs

@@ -146,13 +146,16 @@
                         [:div.block-content (asset-cp (assoc config :disable-resize? true) row)]))
               :disable-hide? true})]
           (keep
-           (fn [property]
-             (let [ident (or (:db/ident property) (:id property))]
-               (when-not (or (contains? #{:logseq.property/built-in? :logseq.property.asset/checksum :logseq.property.class/properties} ident)
-                             (contains? #{:map :entity} (get-in property [:block/schema :type])))
-                 (let [property (if (de/entity? property)
-                                  property
-                                  (or (db/entity ident) property))
+           (fn [column]
+             (let [ident (or (:db/ident column) (:id column))]
+               (when-not (or (contains? #{:logseq.property/built-in? :logseq.property.asset/checksum :logseq.property.class/properties
+                                          :block/created-at :block/updated-at :block/order}
+                                        ident)
+                             (and with-object-name? (= :block/title ident))
+                             (contains? #{:map :entity} (get-in column [:block/schema :type])))
+                 (let [property (if (de/entity? column)
+                                  column
+                                  (or (db/entity ident) column))
                        get-value (or (:get-value property)
                                      (when (de/entity? property)
                                        (fn [row] (get-property-value-for-search row property))))
@@ -171,7 +174,7 @@
                                                 (get-value row)
                                                 (get row ident))))]
                    {:id ident
-                    :name (or (:name property)
+                    :name (or (:name column)
                               (:block/title property))
                     :header (or (:header property)
                                 header-cp)

+ 7 - 1
src/main/frontend/worker/db/migrate.cljs

@@ -328,7 +328,13 @@
    [32 {:properties [:logseq.property.asset/last-visit-page]}]
    [33 {:properties [:logseq.property.pdf/hl-image]}]
    [34 {:properties [:logseq.property.asset/resize-metadata]}]
-   [35 {:fix add-card-view}]])
+   [35 {:fix add-card-view}]
+   [36 {:properties [:kv/value :block/type :block/schema :block/parent
+                     :block/order :block/collapsed? :block/page
+                     :block/refs :block/path-refs :block/link
+                     :block/title :block/closed-value-property
+                     :block/created-at :block/updated-at
+                     :property/schema.classes :property.value/content]}]])
 
 (let [max-schema-version (apply max (map first schema-version->updates))]
   (assert (<= db-schema/version max-schema-version))