mirror of https://github.com/logseq/logseq
Merge branch 'master' of github.com:logseq/logseq
commit
da06b40793
|
@ -32,29 +32,28 @@
|
||||||
(when db
|
(when db
|
||||||
(.prepare db sql)))
|
(.prepare db sql)))
|
||||||
|
|
||||||
;; (defn add-triggers!
|
(defn add-triggers!
|
||||||
;; [db]
|
[db]
|
||||||
;; (let [triggers ["CREATE TRIGGER blocks_ai AFTER INSERT ON blocks
|
(let [triggers ["CREATE TRIGGER IF NOT EXISTS blocks_ad AFTER DELETE ON blocks
|
||||||
;; BEGIN
|
BEGIN
|
||||||
;; INSERT INTO blocks_fts (id, text)
|
DELETE from blocks_fts where rowid = old.id;
|
||||||
;; VALUES (new.id, new.text);
|
END;"
|
||||||
;; END;
|
"CREATE TRIGGER IF NOT EXISTS blocks_ai AFTER INSERT ON blocks
|
||||||
;; "
|
BEGIN
|
||||||
;; "CREATE TRIGGER blocks_ad AFTER DELETE ON blocks
|
INSERT INTO blocks_fts (rowid, uuid, content)
|
||||||
;; BEGIN
|
VALUES (new.id, new.uuid, new.content);
|
||||||
;; INSERT INTO blocks_fts (blocks_fts, id, text)
|
END;
|
||||||
;; VALUES ('delete', old.id, old.text);
|
"
|
||||||
;; END;"
|
"CREATE TRIGGER IF NOT EXISTS blocks_au AFTER UPDATE ON blocks
|
||||||
;; "CREATE TRIGGER blocks_au AFTER UPDATE ON blocks
|
BEGIN
|
||||||
;; BEGIN
|
DELETE from blocks_fts where rowid = old.id;
|
||||||
;; INSERT INTO blocks_fts (blocks_fts, id, text)
|
INSERT INTO blocks_fts (rowid, uuid, content)
|
||||||
;; VALUES ('delete', old.id, old.text);
|
VALUES (new.id, new.uuid, new.content);
|
||||||
;; INSERT INTO blocks_fts (id, text)
|
END;"
|
||||||
;; VALUES (new.id, new.text);
|
]]
|
||||||
;; END;"]]
|
(doseq [trigger triggers]
|
||||||
;; (doseq [trigger triggers]
|
(let [stmt (prepare db trigger)]
|
||||||
;; (let [stmt (prepare db trigger)]
|
(.run ^object stmt)))))
|
||||||
;; (.run ^object stmt)))))
|
|
||||||
|
|
||||||
(defn create-blocks-table!
|
(defn create-blocks-table!
|
||||||
[db]
|
[db]
|
||||||
|
@ -66,7 +65,7 @@
|
||||||
|
|
||||||
(defn create-blocks-fts-table!
|
(defn create-blocks-fts-table!
|
||||||
[db]
|
[db]
|
||||||
(let [stmt (prepare db "CREATE VIRTUAL TABLE blocks_fts USING fts5(id, uuid, content)")]
|
(let [stmt (prepare db "CREATE VIRTUAL TABLE IF NOT EXISTS blocks_fts USING fts5(uuid, content)")]
|
||||||
(.run ^object stmt)))
|
(.run ^object stmt)))
|
||||||
|
|
||||||
(defn get-search-dir
|
(defn get-search-dir
|
||||||
|
@ -88,7 +87,10 @@
|
||||||
[db-name]
|
[db-name]
|
||||||
(let [[db-name db-full-path] (get-db-full-path db-name)
|
(let [[db-name db-full-path] (get-db-full-path db-name)
|
||||||
db (sqlite3 db-full-path nil)
|
db (sqlite3 db-full-path nil)
|
||||||
_ (create-blocks-table! db)]
|
_ (create-blocks-table! db)
|
||||||
|
_ (create-blocks-fts-table! db)
|
||||||
|
_ (add-triggers! db)
|
||||||
|
]
|
||||||
(swap! databases assoc db-name db)))
|
(swap! databases assoc db-name db)))
|
||||||
|
|
||||||
(defn open-dbs!
|
(defn open-dbs!
|
||||||
|
@ -133,29 +135,40 @@
|
||||||
[repo q limit]
|
[repo q limit]
|
||||||
(when-let [database (get-db repo)]
|
(when-let [database (get-db repo)]
|
||||||
(when-not (string/blank? q)
|
(when-not (string/blank? q)
|
||||||
(let [limit (or limit 20)
|
(let [match? (or
|
||||||
stmt (prepare database
|
(string/includes? q " and ")
|
||||||
"select id, uuid, content from blocks where content like ? limit ?")]
|
(string/includes? q " & ")
|
||||||
(js->clj (.all ^object stmt (str "%" q "%") limit) :keywordize-keys true)))))
|
(string/includes? q " or ")
|
||||||
|
(string/includes? q " | ")
|
||||||
|
;; (string/includes? q " not ")
|
||||||
|
)
|
||||||
|
q (if match?
|
||||||
|
(-> q
|
||||||
|
(string/replace " and " " AND ")
|
||||||
|
(string/replace " & " " AND ")
|
||||||
|
(string/replace " or " " OR ")
|
||||||
|
(string/replace " | " " OR ")
|
||||||
|
(string/replace " not " " NOT "))
|
||||||
|
q)
|
||||||
|
limit (or limit 20)
|
||||||
|
[sql input] (if match?
|
||||||
|
["select rowid, uuid, content from blocks_fts where content match ? order by rank limit ?"
|
||||||
|
q]
|
||||||
|
(let [q (string/replace q #"\s+" "%")]
|
||||||
|
["select rowid, uuid, content from blocks_fts where content like ? limit ?"
|
||||||
|
(str "%" q "%")]))
|
||||||
|
stmt (prepare database sql)]
|
||||||
|
(js->clj (.all ^object stmt input limit) :keywordize-keys true)))))
|
||||||
|
|
||||||
(defn truncate-blocks-table!
|
(defn truncate-blocks-table!
|
||||||
[repo]
|
[repo]
|
||||||
(when-let [database (get-db repo)]
|
(when-let [database (get-db repo)]
|
||||||
(let [stmt (prepare database
|
(let [stmt (prepare database
|
||||||
"delete from blocks;")]
|
"delete from blocks;")
|
||||||
(.run ^object stmt))))
|
_ (.run ^object stmt)
|
||||||
|
stmt (prepare database
|
||||||
(defn drop-blocks-table!
|
"delete from blocks_fts;")]
|
||||||
[repo]
|
(.run ^object stmt))))
|
||||||
(when-let [database (get-db repo)]
|
|
||||||
(let [stmt (prepare database
|
|
||||||
"drop table blocks;")
|
|
||||||
_ (.run ^object stmt)
|
|
||||||
;; stmt (prepare @database
|
|
||||||
;; "drop table blocks_fts;")
|
|
||||||
]
|
|
||||||
;; (.run ^object stmt)
|
|
||||||
)))
|
|
||||||
|
|
||||||
(defn delete-db!
|
(defn delete-db!
|
||||||
[repo]
|
[repo]
|
||||||
|
@ -165,29 +178,16 @@
|
||||||
(println "Delete search indice: " db-full-path)
|
(println "Delete search indice: " db-full-path)
|
||||||
(fs/unlinkSync db-full-path))))
|
(fs/unlinkSync db-full-path))))
|
||||||
|
|
||||||
|
(defn query
|
||||||
|
[repo sql]
|
||||||
|
(when-let [database (get-db repo)]
|
||||||
|
(let [stmt (prepare database sql)]
|
||||||
|
(.all ^object stmt))))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(open-db!)
|
(def repo (first (keys @databases)))
|
||||||
|
(query repo
|
||||||
|
"select * from blocks_fts")
|
||||||
|
|
||||||
(add-blocks! (clj->js [{:id "a"
|
(delete-db! repo)
|
||||||
:uuid ""
|
|
||||||
:content "hello world"}
|
|
||||||
{:id "b"
|
|
||||||
:uuid ""
|
|
||||||
:content "foo bar"}]))
|
|
||||||
|
|
||||||
(time
|
|
||||||
(let [blocks (for [i (range 10000)]
|
|
||||||
{:id (str i)
|
|
||||||
:uuid ""
|
|
||||||
:content (rand-nth ["hello" "world" "nice"])})]
|
|
||||||
(add-blocks! (clj->js blocks))))
|
|
||||||
|
|
||||||
(get-all-blocks)
|
|
||||||
|
|
||||||
(search-blocks "hello")
|
|
||||||
|
|
||||||
(def block {:id 16, :uuid "5f713e91-8a3c-4b04-a33a-c39482428e2d", :content "Hello, I'm a block!"})
|
|
||||||
|
|
||||||
(add-blocks! (clj->js [block]))
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -74,6 +74,8 @@
|
||||||
|
|
||||||
.resize {
|
.resize {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
|
/* Fix chrome missing resize handle issue. Ref: https://github.com/logseq/logseq/pull/1692/files */
|
||||||
|
transform: translate3d(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
.draw [aria-labelledby="shapes-title"] {
|
.draw [aria-labelledby="shapes-title"] {
|
||||||
|
|
|
@ -117,7 +117,7 @@
|
||||||
(when (state/sub :ui/left-sidebar-open?)
|
(when (state/sub :ui/left-sidebar-open?)
|
||||||
(sidebar-nav route-match nil))]
|
(sidebar-nav route-match nil))]
|
||||||
[:div#main-content-container.w-full.flex.justify-center
|
[:div#main-content-container.w-full.flex.justify-center
|
||||||
{:margin-top (if global-graph-pages? 0 "2rem")}
|
{:style {:margin-top (if global-graph-pages? 0 "2rem")}}
|
||||||
[:div.cp__sidebar-main-content
|
[:div.cp__sidebar-main-content
|
||||||
{:data-is-global-graph-pages global-graph-pages?
|
{:data-is-global-graph-pages global-graph-pages?
|
||||||
:data-is-full-width (or global-graph-pages?
|
:data-is-full-width (or global-graph-pages?
|
||||||
|
|
Loading…
Reference in New Issue