mirror of
https://github.com/logseq/logseq.git
synced 2026-05-25 05:04:24 +00:00
Move handler.common.repo fn into sqlite-util
This makes create-graph* namespaces independent of frontend as they should be to be used externally
This commit is contained in:
@@ -11,9 +11,7 @@
|
||||
[datascript.core :as d]
|
||||
["fs" :as fs]
|
||||
["path" :as node-path]
|
||||
[nbb.classpath :as cp]
|
||||
;; TODO: Move this namespace to more stable deps/ namespaces
|
||||
[frontend.handler.common.repo :as repo-common-handler]))
|
||||
[nbb.classpath :as cp]))
|
||||
|
||||
(defn- find-on-classpath [rel-path]
|
||||
(some (fn [dir]
|
||||
@@ -29,7 +27,7 @@
|
||||
(let [config-content (or (some-> (find-on-classpath "templates/config.edn") fs/readFileSync str)
|
||||
(do (println "Setting graph's config to empty since no templates/config.edn was found.")
|
||||
"{}"))]
|
||||
(d/transact! conn (repo-common-handler/build-db-initial-data config-content))))
|
||||
(d/transact! conn (sqlite-util/build-db-initial-data config-content))))
|
||||
|
||||
(defn init-conn
|
||||
"Create sqlite DB, initialize datascript connection and sync listener and then
|
||||
@@ -86,7 +84,7 @@
|
||||
(into {}))
|
||||
page-uuids (->> pages-and-blocks
|
||||
(map :page)
|
||||
(map (juxt #(or (:block/name %) (string/lower-case (:block/original-name %)))
|
||||
(map (juxt #(or (:block/name %) (sqlite-util/sanitize-page-name (:block/original-name %)))
|
||||
:block/uuid))
|
||||
(into {}))
|
||||
block-uuids (->> pages-and-blocks
|
||||
@@ -173,7 +171,7 @@
|
||||
:block/schema (merge {:type :default}
|
||||
(get-in properties [prop-name :block/schema]))
|
||||
:block/original-name (name prop-name)
|
||||
:block/name (string/lower-case (name prop-name))
|
||||
:block/name (sqlite-util/sanitize-page-name (name prop-name))
|
||||
:block/type "property"
|
||||
:block/created-at created-at
|
||||
:block/updated-at created-at}
|
||||
@@ -191,7 +189,7 @@
|
||||
[(merge (dissoc page :properties)
|
||||
{:db/id page-id
|
||||
:block/original-name (or (:block/original-name page) (string/capitalize (:block/name page)))
|
||||
:block/name (or (:block/name page) (string/lower-case (:block/original-name page)))
|
||||
:block/name (or (:block/name page) (sqlite-util/sanitize-page-name (:block/original-name page)))
|
||||
:block/created-at created-at
|
||||
:block/updated-at created-at}
|
||||
(when (seq (:properties page))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"Script that generates all the permutations of property types and cardinality.
|
||||
Also creates a page of queries that exercises most properties"
|
||||
(:require [logseq.tasks.db-graph.create-graph :as create-graph]
|
||||
[logseq.db.sqlite.util :as sqlite-util]
|
||||
[clojure.string :as string]
|
||||
[datascript.core :as d]
|
||||
["path" :as node-path]
|
||||
@@ -11,7 +12,7 @@
|
||||
(defn- date-journal-title [date]
|
||||
(let [title (.toLocaleString date "en-US" #js {:month "short" :day "numeric" :year "numeric"})
|
||||
suffixes {1 "st" 21 "st" 31 "st" 2 "nd" 22 "nd" 3 "rd" 23 "rd" 33 "rd"}]
|
||||
(string/lower-case
|
||||
(sqlite-util/sanitize-page-name
|
||||
(string/replace-first title #"(\d+)" (str "$1" (suffixes (.getDate date) "th"))))))
|
||||
|
||||
(defn- date-journal-day [date]
|
||||
@@ -78,7 +79,7 @@
|
||||
(println "Generating" (count (filter :block/name blocks-tx)) "pages and"
|
||||
(count (filter :block/content blocks-tx)) "blocks ...")
|
||||
(d/transact! conn blocks-tx)
|
||||
(println "Created graph" (str db-name "!"))))
|
||||
(println "Created graph" (str db-name " with " (count (d/datoms @conn :eavt)) " datoms!"))))
|
||||
|
||||
(when (= nbb/*file* (:file (meta #'-main)))
|
||||
(-main *command-line-args*))
|
||||
@@ -9,6 +9,7 @@
|
||||
type logseq doesnt' support yet
|
||||
* schema.org assumes no cardinality. For now, only :object properties are given a :cardinality :many"
|
||||
(:require [logseq.tasks.db-graph.create-graph :as create-graph]
|
||||
[logseq.db.sqlite.util :as sqlite-util]
|
||||
[clojure.string :as string]
|
||||
[datascript.core :as d]
|
||||
["path" :as node-path]
|
||||
@@ -133,7 +134,7 @@
|
||||
[property-ids class-ids {:keys [verbose]}]
|
||||
(let [conflicts
|
||||
(->> (concat property-ids class-ids)
|
||||
(group-by (comp string/lower-case first))
|
||||
(group-by (comp sqlite-util/sanitize-page-name first))
|
||||
(filter #(> (count (val %)) 1))
|
||||
vals)
|
||||
;; If this assertion fails then renamed-classes approach to resolving
|
||||
|
||||
Reference in New Issue
Block a user