Browse Source

feat: add query api

Tienson Qin 5 years ago
parent
commit
b8a7448d99
2 changed files with 20 additions and 4 deletions
  1. 15 0
      src/main/api.cljs
  2. 5 4
      src/main/frontend/core.cljs

+ 15 - 0
src/main/api.cljs

@@ -0,0 +1,15 @@
+(ns ^:no-doc api
+  (:require [frontend.db :as db]
+            [frontend.state :as state]
+            [datascript.core :as d]
+            [cljs.reader]))
+
+(defn ^:export query
+  [query & inputs]
+  (when-let [repo (state/get-current-repo)]
+    (when-let [conn (db/get-conn repo)]
+      (let [query (cljs.reader/read-string query)
+            result (apply d/q query conn inputs)]
+        (clj->js result)))))
+
+(def ^:export custom_query db/custom-query)

+ 5 - 4
src/main/frontend/core.cljs

@@ -7,7 +7,8 @@
             [frontend.spec]
             [frontend.log]
             [reitit.frontend :as rf]
-            [reitit.frontend.easy :as rfe]))
+            [reitit.frontend.easy :as rfe]
+            [api]))
 
 (defn set-router!
   []
@@ -20,7 +21,7 @@
 (defn display-welcome-message
   []
   (js/console.log
-    "
+   "
     Welcome to Logseq!
     If you encounter any problem, feel free to file an issue on GitHub (https://github.com/logseq/logseq)
     or join our Discord server (https://discord.gg/KpN4eHY).
@@ -30,7 +31,7 @@
     |    |__(  <_> ) /_/  >___ \\\\  ___< <_|  |
     |_______ \\____/\\___  /____  >\\___  >__   |
             \\/    /_____/     \\/     \\/   |__|
-     " ))
+     "))
 
 (defn start []
   (when-let [node (.getElementById js/document "root")]
@@ -49,7 +50,7 @@
   ;; (handler/request-notifications-if-not-asked)
 
   ;; (handler/run-notify-worker!)
-  )
+)
 
 (defn stop []
   ;; stop is called before any code is reloaded