mirror of https://github.com/logseq/logseq
fix: unable to build :default property for sqlite.build
Also add tests for different built-in cases and addressed related TODOexperiment/tanstack-table
parent
edb3dcd38d
commit
16248f0bd2
|
@ -80,20 +80,23 @@
|
||||||
{:block/content value}))
|
{:block/content value}))
|
||||||
sqlite-util/block-with-timestamps))
|
sqlite-util/block-with-timestamps))
|
||||||
|
|
||||||
;; TODO: Add support for types besides :default when needed by getting property types
|
|
||||||
;; and passing them to build-property-value-block
|
|
||||||
(defn build-property-values-tx-m
|
(defn build-property-values-tx-m
|
||||||
"Builds a map of property names to their property value blocks to be transacted, given a block
|
"Builds a map of property names to their property value blocks to be
|
||||||
and a properties map with raw property values"
|
transacted, given a block and a properties map with raw property values. The
|
||||||
|
properties map can have keys that are db-idents or they can be maps. If a map,
|
||||||
|
it should have :original-property-id and :db/ident keys. See
|
||||||
|
->property-value-tx-m for such an example"
|
||||||
[block properties]
|
[block properties]
|
||||||
;; Build :db/id out of uuid if block doesn't have one for tx purposes
|
;; Build :db/id out of uuid if block doesn't have one for tx purposes
|
||||||
(let [block' (if (:db/id block) block (assoc block :db/id [:block/uuid (:block/uuid block)]))]
|
(let [block' (if (:db/id block) block (assoc block :db/id [:block/uuid (:block/uuid block)]))]
|
||||||
(->> properties
|
(->> properties
|
||||||
(map (fn [[k v]]
|
(map (fn [[k v]]
|
||||||
[k
|
(let [property-map (if (map? k) k {:db/ident k})]
|
||||||
(if (set? v)
|
(assert (:db/ident property-map) "Key in map must have a :db/ident")
|
||||||
(set (map #(build-property-value-block block' {:db/ident k} %) v))
|
[(or (:original-property-id property-map) (:db/ident property-map))
|
||||||
(build-property-value-block block' {:db/ident k} v))]))
|
(if (set? v)
|
||||||
|
(set (map #(build-property-value-block block' property-map %) v))
|
||||||
|
(build-property-value-block block' property-map v))])))
|
||||||
(into {}))))
|
(into {}))))
|
||||||
|
|
||||||
(defn build-properties-with-ref-values
|
(defn build-properties-with-ref-values
|
||||||
|
|
|
@ -75,24 +75,27 @@
|
||||||
"Provides the next temp :db/id to use in a create-graph transact!"
|
"Provides the next temp :db/id to use in a create-graph transact!"
|
||||||
#(swap! current-db-id dec))
|
#(swap! current-db-id dec))
|
||||||
|
|
||||||
;; TODO: Use build-property-values-tx-m
|
|
||||||
(defn- ->property-value-tx-m
|
(defn- ->property-value-tx-m
|
||||||
"Given a new block and its properties, creates a map of properties which have values of property value tx.
|
"Given a new block and its properties, creates a map of properties which have values of property value tx.
|
||||||
This map is used for both creating the new property values and then adding them to a block"
|
This map is used for both creating the new property values and then adding them to a block"
|
||||||
[new-block properties properties-config all-idents]
|
[new-block properties properties-config all-idents]
|
||||||
(->> properties
|
(->> properties
|
||||||
(map (fn [[k v]]
|
(keep (fn [[k v]]
|
||||||
(when (and (db-property-type/value-ref-property-types (get-in properties-config [k :block/schema :type]))
|
(if-let [built-in-type (get-in db-property/built-in-properties [k :schema :type])]
|
||||||
;; TODO: Support translate-property-value without this hack
|
(when (and (db-property-type/value-ref-property-types built-in-type)
|
||||||
(not (vector? v)))
|
;; closed values are referenced by their :db/ident so no need to create values
|
||||||
(let [property-map {:db/ident (get-ident all-idents k)
|
(not (get-in db-property/built-in-properties [k :closed-values])))
|
||||||
:block/schema {:type (get-in properties-config [k :block/schema :type])}}]
|
(let [property-map {:db/ident k
|
||||||
[k (if (set? v)
|
:block/schema {:type built-in-type}}]
|
||||||
(->> v
|
[property-map v]))
|
||||||
(map #(db-property-build/build-property-value-block new-block property-map %))
|
(when (and (db-property-type/value-ref-property-types (get-in properties-config [k :block/schema :type]))
|
||||||
set)
|
;; TODO: Support translate-property-value without this hack
|
||||||
(db-property-build/build-property-value-block new-block property-map v))]))))
|
(not (vector? v)))
|
||||||
(into {})))
|
(let [property-map {:db/ident (get-ident all-idents k)
|
||||||
|
:original-property-id k
|
||||||
|
:block/schema {:type (get-in properties-config [k :block/schema :type])}}]
|
||||||
|
[property-map v])))))
|
||||||
|
(db-property-build/build-property-values-tx-m new-block)))
|
||||||
|
|
||||||
(defn- extract-content-refs
|
(defn- extract-content-refs
|
||||||
"Extracts basic refs from :block/content like `[[foo]]`. Adding more ref support would
|
"Extracts basic refs from :block/content like `[[foo]]`. Adding more ref support would
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
:where [?b :block/original-name "Jayson Tatum"]]
|
:where [?b :block/original-name "Jayson Tatum"]]
|
||||||
@conn)))
|
@conn)))
|
||||||
"Person class is created and correctly associated to a page")))
|
"Person class is created and correctly associated to a page")))
|
||||||
|
|
||||||
(deftest build-properties
|
(deftest build-properties-user
|
||||||
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||||
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||||
_ (sqlite-build/create-blocks
|
_ (sqlite-build/create-blocks
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
(is (= "Clutch defense"
|
(is (= "Clutch defense"
|
||||||
(->> @conn
|
(->> @conn
|
||||||
(d/q '[:find [(pull ?b [*]) ...]
|
(d/q '[:find [(pull ?b [*]) ...]
|
||||||
:where [?b :block/content "Jrue Holiday"]])
|
:where [?b :block/content "Jrue Holiday"]])
|
||||||
first
|
first
|
||||||
:user.property/description
|
:user.property/description
|
||||||
(db-property/ref->property-value-contents @conn)))
|
(db-property/ref->property-value-contents @conn)))
|
||||||
|
@ -46,8 +46,36 @@
|
||||||
(is (= "Awesome selfless basketball"
|
(is (= "Awesome selfless basketball"
|
||||||
(->> @conn
|
(->> @conn
|
||||||
(d/q '[:find [(pull ?b [*]) ...]
|
(d/q '[:find [(pull ?b [*]) ...]
|
||||||
:where [?b :block/original-name "Jayson Tatum"]])
|
:where [?b :block/original-name "Jayson Tatum"]])
|
||||||
first
|
first
|
||||||
:user.property/description
|
:user.property/description
|
||||||
(db-property/ref->property-value-contents @conn)))
|
(db-property/ref->property-value-contents @conn)))
|
||||||
"description property is created and correctly associated to a page")))
|
"description property is created and correctly associated to a page")))
|
||||||
|
|
||||||
|
(deftest build-properties-built-in
|
||||||
|
(let [conn (d/create-conn db-schema/schema-for-db-based-graph)
|
||||||
|
_ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
|
||||||
|
_ (sqlite-build/create-blocks
|
||||||
|
conn
|
||||||
|
[{:page {:block/original-name "page1"}
|
||||||
|
:blocks [{:block/content "some todo"
|
||||||
|
:build/properties {:logseq.task/status :logseq.task/status.doing}}
|
||||||
|
{:block/content "some slide"
|
||||||
|
:build/properties {:logseq.property/background-image "https://placekitten.com/200/300"}}]}])]
|
||||||
|
(is (= "Doing"
|
||||||
|
(->> @conn
|
||||||
|
(d/q '[:find [(pull ?b [*]) ...]
|
||||||
|
:where [?b :block/content "some todo"]])
|
||||||
|
first
|
||||||
|
:logseq.task/status
|
||||||
|
(db-property/ref->property-value-contents @conn)))
|
||||||
|
"built-in property with closed value is created and correctly associated to a block")
|
||||||
|
|
||||||
|
(is (= "https://placekitten.com/200/300"
|
||||||
|
(->> @conn
|
||||||
|
(d/q '[:find [(pull ?b [*]) ...]
|
||||||
|
:where [?b :block/content "some slide"]])
|
||||||
|
first
|
||||||
|
:logseq.property/background-image
|
||||||
|
(db-property/ref->property-value-contents @conn)))
|
||||||
|
"built-in :default property is created and correctly associated to a block")))
|
|
@ -26,6 +26,8 @@
|
||||||
page'
|
page'
|
||||||
(->> properties
|
(->> properties
|
||||||
(keep (fn [[k v]]
|
(keep (fn [[k v]]
|
||||||
|
;; TODO: Pass in property type in order to support property
|
||||||
|
;; types other than :default
|
||||||
(when (db-property-util/built-in-has-ref-value? k)
|
(when (db-property-util/built-in-has-ref-value? k)
|
||||||
[k v])))
|
[k v])))
|
||||||
(into {})))]
|
(into {})))]
|
||||||
|
|
Loading…
Reference in New Issue