Skip to content

Commit 6b2d5fe

Browse files
Merge pull request #6 from clj-codes/feat/better-playground-and-more-libs
feat: better playground and new libs
2 parents 6dc6840 + 54c6e04 commit 6b2d5fe

File tree

3 files changed

+81
-31
lines changed

3 files changed

+81
-31
lines changed

deps.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
:exec-args {:uber-file "target/extractor.jar"}}
1515

1616
:dev {:extra-paths ["dev" "test" "test-resources"]
17-
:extra-deps {lambdaisland/kaocha {:mvn/version "1.82.1306"}
17+
:extra-deps {clj-http/clj-http {:mvn/version "3.12.3"}
18+
lambdaisland/kaocha {:mvn/version "1.82.1306"}
1819
lambdaisland/kaocha-cloverage {:mvn/version "1.1.89"}
1920
nubank/mockfn {:mvn/version "0.7.0"}
2021
nubank/matcher-combinators {:mvn/version "3.8.5"}}}

dev/playground.clj

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
11
(ns dev.playground
2-
(:require [codes.clj.docs.extractor.core :as core]
2+
(:require [clj-http.client :as http]
3+
[clojure.java.io :as io]
4+
[codes.clj.docs.extractor.core :as core]
35
[codes.clj.docs.extractor.datalevin :as datalevin]
46
[datalevin.core :as d]
5-
[datalevin.util :as util]))
7+
[datalevin.util :as util])
8+
(:import [java.io File]))
9+
10+
(defn get-url [git-url]
11+
(-> (http/get git-url {:as :json})
12+
:body))
13+
14+
(defn download-unzip [dir url]
15+
(let [stream (-> (http/get url {:as :byte-array})
16+
:body
17+
io/input-stream
18+
java.util.zip.ZipInputStream.)]
19+
(loop [file-data (.getNextEntry stream)]
20+
(when file-data
21+
(let [file-path (str dir File/separatorChar (.getName file-data))
22+
saveFile (File. file-path)]
23+
(if (.isDirectory file-data)
24+
(when-not (.exists saveFile)
25+
(.mkdirs saveFile))
26+
(let [parentDir (File. (.substring file-path 0 (.lastIndexOf file-path (int File/separatorChar))))]
27+
(when-not (.exists parentDir)
28+
(.mkdirs parentDir))
29+
(io/copy stream saveFile))))
30+
(recur (.getNextEntry stream))))))
631

732
(comment
8-
; reset database
33+
; reset database & download unzip from releases
34+
(let [dir "target/docs-db"]
35+
(println "deleting")
36+
(try (util/delete-files dir) (catch Exception _))
37+
(println "downloading")
38+
(->> "https://api.github.com/repos/clj-codes/docs.extractor/releases/latest"
39+
get-url
40+
:tag_name
41+
(format "https://github.com/clj-codes/docs.extractor/releases/download/%s/docs-db.zip")
42+
(download-unzip dir)))
43+
44+
; reset database & generate new database
945
(let [dir "target/docs-db"]
1046
(println "deleting")
1147
(try (util/delete-files dir) (catch Exception _))
@@ -31,7 +67,8 @@
3167
:definition/name
3268
:definition/group
3369
:definition/artifact
34-
:definition/namespace]) ...]
70+
:definition/namespace
71+
:definition/git-source]) ...]
3572
:in $ ?q
3673
:where
3774
[(str ".*" ?q ".*") ?pattern]
@@ -52,29 +89,21 @@
5289
(let [conn (d/get-conn "target/docs-db" datalevin/db-schemas)
5390
db (d/db conn)
5491
result (doall (d/q '[:find (count ?e)
55-
:in $ ?q
92+
:in $
5693
:where [?e]]
57-
db
58-
"assoc"))]
94+
db))]
5995
(d/close conn)
6096
result)
6197

62-
; tests with temporary database
63-
(let [db (-> (d/empty-db "/tmp/mydb"
64-
{:text {:db/valueType :db.type/string}})
65-
(d/db-with
66-
[{:db/id 1 :text "assoc!"}
67-
{:db/id 2 :text "assoc"}
68-
{:db/id 3 :text "assoc-in"}
69-
{:db/id 4 :text "assoc-dom"}
70-
{:db/id 5 :text "assoc-meta"}
71-
{:db/id 6 :text "associative?"}]))]
72-
(d/q '[:find (pull ?e [*])
73-
:in $ ?q
74-
:where ;[(fulltext $ ?q) [[?e ?a ?v]]]
75-
[(str ".*" ?q ".*") ?pattern]
76-
[(re-pattern ?pattern) ?regex]
77-
[(re-matches ?regex ?name)]
78-
[?e :text ?name]]
79-
db
80-
"assoc")))
98+
; tests with fulltext search
99+
(let [conn (d/get-conn "target/docs-db" datalevin/db-schemas)
100+
db (d/db conn)
101+
result (doall (d/q '[:find ?e ?name ?a ?v
102+
:in $ ?q
103+
:where
104+
[(fulltext $ ?q) [[?e ?a ?v]]]
105+
[?e :definition/name ?name]]
106+
db
107+
"assoc"))]
108+
(d/close conn)
109+
result))

resources/config.edn

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,27 @@
77
{:git/url "https://github.com/clojure/core.logic"
88
:git/tag "v1.0.1"
99
:git/sha "d854548a1eb0706150bd5f5d939c7bca162c07fb"}
10-
org.clojure/clojurescript
11-
{:git/url "https://github.com/clojure/clojurescript"
12-
:git/tag "r1.11.60"
13-
:git/sha "e7cdc70d0371a26e07e394ea9cd72d5c43e5e363"}}}
10+
org.clojure/core.async
11+
{:git/url "https://github.com/clojure/core.async"
12+
:git/tag "v1.6.673"
13+
:git/sha "96adc333bb02c8fc60bd51306950b3ad291b3460"}
14+
org.clojure/core.cache
15+
{:git/url "https://github.com/clojure/core.cache"
16+
:git/tag "v1.0.225"
17+
:git/sha "b9b3192fd7beda68a06af7de4b6d4c2a54515094"}
18+
org.clojure/core.memoize
19+
{:git/url "https://github.com/clojure/core.memoize"
20+
:git/tag "v1.0.257"
21+
:git/sha "30adac08491ab6dd23db452215dd0c38ea0a42f4"}
22+
org.clojure/data.csv
23+
{:git/url "https://github.com/clojure/data.csv"
24+
:git/tag "v1.0.1"
25+
:git/sha "80c94ef6592f07d62c489359e8535343689d8135"}
26+
org.clojure/data.xml
27+
{:git/url "https://github.com/clojure/data.xml"
28+
:git/tag "v0.2.0-alpha8"
29+
:git/sha "4fbff240e0e4d57537b616fc4c2b7f28f6555e20"}
30+
org.clojure/data.json
31+
{:git/url "https://github.com/clojure/data.json"
32+
:git/tag "v2.4.0"
33+
:git/sha "43c122e91c5c5e46dc58dc7e8fcbb64bb9f88a14"}}}

0 commit comments

Comments
 (0)