|
@@ -4,17 +4,17 @@
|
|
|
|
|
|
|
|
```typescript
|
|
```typescript
|
|
|
// DSL Query - Logseq's query language
|
|
// DSL Query - Logseq's query language
|
|
|
-const results = await logseq.DB.q('[[page-name]]')
|
|
|
|
|
|
|
+const results0 = await logseq.DB.q('[[page-name]]')
|
|
|
const todos = await logseq.DB.q('(task TODO DOING)')
|
|
const todos = await logseq.DB.q('(task TODO DOING)')
|
|
|
|
|
|
|
|
// Datascript Query - Datalog syntax (more powerful)
|
|
// Datascript Query - Datalog syntax (more powerful)
|
|
|
-const results = await logseq.DB.datascriptQuery(`
|
|
|
|
|
|
|
+const results1 = await logseq.DB.datascriptQuery(`
|
|
|
[:find (pull ?b [*])
|
|
[:find (pull ?b [*])
|
|
|
:where [?b :block/marker "TODO"]]
|
|
:where [?b :block/marker "TODO"]]
|
|
|
`)
|
|
`)
|
|
|
|
|
|
|
|
// Query with parameters
|
|
// Query with parameters
|
|
|
-const results = await logseq.DB.datascriptQuery(`
|
|
|
|
|
|
|
+const results2 = await logseq.DB.datascriptQuery(`
|
|
|
[:find (pull ?b [*])
|
|
[:find (pull ?b [*])
|
|
|
:in $ ?name
|
|
:in $ ?name
|
|
|
:where
|
|
:where
|
|
@@ -40,7 +40,7 @@ logseq.DB.onBlockChanged(uuid, (block, txData) => {
|
|
|
#### 2.1 Basic Structure
|
|
#### 2.1 Basic Structure
|
|
|
|
|
|
|
|
```clojure
|
|
```clojure
|
|
|
-[: find <return-value> ;; what to return
|
|
|
|
|
|
|
+[:find <return-value> ;; what to return
|
|
|
:in $ <params... > ;; input parameters ($ = database)
|
|
:in $ <params... > ;; input parameters ($ = database)
|
|
|
:where <clauses...>] ;; query conditions
|
|
:where <clauses...>] ;; query conditions
|
|
|
```
|
|
```
|
|
@@ -49,20 +49,20 @@ logseq.DB.onBlockChanged(uuid, (block, txData) => {
|
|
|
|
|
|
|
|
```clojure
|
|
```clojure
|
|
|
;; Return entity IDs
|
|
;; Return entity IDs
|
|
|
-[:find ?b : where ...]
|
|
|
|
|
|
|
+[:find ?b :where ...]
|
|
|
|
|
|
|
|
;; Return multiple values
|
|
;; Return multiple values
|
|
|
-[:find ?b ? name :where ...]
|
|
|
|
|
|
|
+[:find ?b ?name :where ...]
|
|
|
|
|
|
|
|
;; Return full entity (commonly used)
|
|
;; Return full entity (commonly used)
|
|
|
[:find (pull ?b [*]) :where ...]
|
|
[:find (pull ?b [*]) :where ...]
|
|
|
|
|
|
|
|
;; Return specific attributes
|
|
;; Return specific attributes
|
|
|
-[:find (pull ?b [: block/uuid :block/content]) :where ...]
|
|
|
|
|
|
|
+[:find (pull ?b [:block/uuid :block/content]) :where ...]
|
|
|
|
|
|
|
|
;; Aggregate functions
|
|
;; Aggregate functions
|
|
|
-[:find (count ? b) :where ...]
|
|
|
|
|
-[:find (min ? d) (max ?d) :where ...]
|
|
|
|
|
|
|
+[:find (count ?b) :where ...]
|
|
|
|
|
+[:find (min ?d) (max ?d) :where ...]
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
#### 2.3 :where Clause - Data Patterns
|
|
#### 2.3 :where Clause - Data Patterns
|
|
@@ -75,7 +75,7 @@ logseq.DB.onBlockChanged(uuid, (block, txData) => {
|
|
|
|
|
|
|
|
;; Multiple conditions (implicit AND)
|
|
;; Multiple conditions (implicit AND)
|
|
|
[?b :block/marker "TODO"]
|
|
[?b :block/marker "TODO"]
|
|
|
-[?b : block/page ?p]
|
|
|
|
|
|
|
+[?b :block/page ?p]
|
|
|
[?p :block/journal? true] ;; all three must be satisfied
|
|
[?p :block/journal? true] ;; all three must be satisfied
|
|
|
```
|
|
```
|
|
|
|
|
|
|
@@ -98,7 +98,7 @@ logseq.DB.onBlockChanged(uuid, (block, txData) => {
|
|
|
:where
|
|
:where
|
|
|
[?b :block/marker ?marker]
|
|
[?b :block/marker ?marker]
|
|
|
[? p :block/name ?page-name]
|
|
[? p :block/name ?page-name]
|
|
|
- [?b : block/page ?p]]
|
|
|
|
|
|
|
+ [?b :block/page ?p]]
|
|
|
|
|
|
|
|
;; Collection parameter (match multiple values)
|
|
;; Collection parameter (match multiple values)
|
|
|
[:find (pull ?b [*])
|
|
[:find (pull ?b [*])
|
|
@@ -129,7 +129,6 @@ logseq.DB.onBlockChanged(uuid, (block, txData) => {
|
|
|
| `:block/properties` | ✅ | ❌ | Map | Properties as key-value map |
|
|
| `:block/properties` | ✅ | ❌ | Map | Properties as key-value map |
|
|
|
| `:block/tags` | ✅ | ✅ | Ref[] | Tag references |
|
|
| `:block/tags` | ✅ | ✅ | Ref[] | Tag references |
|
|
|
| `:block/link` | ❌ | ✅ | Ref | Link to class/tag in DB Graph |
|
|
| `:block/link` | ❌ | ✅ | Ref | Link to class/tag in DB Graph |
|
|
|
-| `:block/tx-id` | ❌ | ✅ | Int | Transaction ID |
|
|
|
|
|
| `:block/created-at` | ✅ | ❌ | Int | Creation timestamp (File Graph) |
|
|
| `:block/created-at` | ✅ | ❌ | Int | Creation timestamp (File Graph) |
|
|
|
| `:block/updated-at` | ✅ | ❌ | Int | Update timestamp (File Graph) |
|
|
| `:block/updated-at` | ✅ | ❌ | Int | Update timestamp (File Graph) |
|
|
|
|
|
|
|
@@ -394,7 +393,7 @@ const results = await logseq.DB.datascriptQuery(`
|
|
|
[(not= ?v "value")]
|
|
[(not= ?v "value")]
|
|
|
|
|
|
|
|
;; String operations
|
|
;; String operations
|
|
|
-[(clojure.string/includes? ? s "text")]
|
|
|
|
|
|
|
+[(clojure.string/includes? ?s "text")]
|
|
|
[(clojure.string/starts-with? ?s "prefix")]
|
|
[(clojure.string/starts-with? ?s "prefix")]
|
|
|
[(clojure.string/ends-with? ?s "suffix")]
|
|
[(clojure.string/ends-with? ?s "suffix")]
|
|
|
[(clojure.string/blank? ?s)]
|
|
[(clojure.string/blank? ?s)]
|
|
@@ -418,7 +417,7 @@ const results = await logseq.DB.datascriptQuery(`
|
|
|
|
|
|
|
|
```clojure
|
|
```clojure
|
|
|
;; NOT - exclude conditions
|
|
;; NOT - exclude conditions
|
|
|
-[: find (pull ?b [*])
|
|
|
|
|
|
|
+[:find (pull ?b [*])
|
|
|
:where
|
|
:where
|
|
|
[? b :block/marker ? m]
|
|
[? b :block/marker ? m]
|
|
|
(not [?b :block/priority "C"])]
|
|
(not [?b :block/priority "C"])]
|
|
@@ -427,7 +426,7 @@ const results = await logseq.DB.datascriptQuery(`
|
|
|
[:find (pull ?b [*])
|
|
[:find (pull ?b [*])
|
|
|
:where
|
|
:where
|
|
|
(or [?b :block/marker "TODO"]
|
|
(or [?b :block/marker "TODO"]
|
|
|
- [?b : block/marker "DOING"])]
|
|
|
|
|
|
|
+ [?b :block/marker "DOING"])]
|
|
|
|
|
|
|
|
;; OR with AND (or-join)
|
|
;; OR with AND (or-join)
|
|
|
[:find (pull ?b [*])
|
|
[:find (pull ?b [*])
|