Skip to content

Commit a15258f

Browse files
committed
feat: adds datalevin schema and test transaction
1 parent 018f525 commit a15258f

File tree

3 files changed

+237
-151
lines changed

3 files changed

+237
-151
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
(ns codes.clj.docs.extractor.datalevin
2+
(:require [clojure.pprint :as pprint]
3+
[datalevin.core :as d]))
4+
5+
;; TODO: add id :db.unique/identity and ref :db.type/ref
6+
7+
(def project-schema
8+
{;:project/id {:db/valueType :db.type/string :unique :db.unique/identity}
9+
:project/name {:db/valueType :db.type/string
10+
:db/fulltext true}
11+
:project/group {:db/valueType :db.type/string}
12+
:project/artifact {:db/valueType :db.type/string}
13+
:project/paths {:db/valueType :db.type/string
14+
:db/cardinality :db.cardinality/many}
15+
:project/url {:db/valueType :db.type/string}
16+
:project/tag {:db/valueType :db.type/string}
17+
:project/sha {:db/valueType :db.type/string}
18+
:project/manifest {:db/valueType :db.type/keyword}})
19+
20+
(def library-schema
21+
{;:library/id {:db/valueType :db.type/string :unique :db.unique/identity}
22+
:library/name {:db/valueType :db.type/string
23+
:db/fulltext true}
24+
:library/project {:db/valueType :db.type/string} ;todo change to ref
25+
;:library/project {:db/valueType :db.type/ref}
26+
:library/group {:db/valueType :db.type/string}
27+
:library/artifact {:db/valueType :db.type/string}
28+
:library/doc {:db/valueType :db.type/string
29+
:db/fulltext true}
30+
:library/author {:db/valueType :db.type/string}
31+
:library/filename {:db/valueType :db.type/string}
32+
:library/git-source {:db/valueType :db.type/string}
33+
:library/added {:db/valueType :db.type/string}
34+
:library/row {:db/valueType :db.type/long}
35+
:library/col {:db/valueType :db.type/long}})
36+
37+
(def definition-schema
38+
{;:definition/id {:db/valueType :db.type/string :unique :db.unique/identity}
39+
:definition/name {:db/valueType :db.type/string
40+
:db/fulltext true}
41+
:definition/library {:db/valueType :db.type/string} ;todo change to ref
42+
;:definition/library {:db/valueType :db.type/ref}
43+
:definition/project {:db/valueType :db.type/string} ;todo change to ref
44+
;:definition/project {:db/valueType :db.type/ref}
45+
:definition/group {:db/valueType :db.type/string}
46+
:definition/artifact {:db/valueType :db.type/string}
47+
:definition/doc {:db/valueType :db.type/string
48+
:db/fulltext true}
49+
:definition/filename {:db/valueType :db.type/string}
50+
:definition/git-source {:db/valueType :db.type/string}
51+
:definition/arglist-strs {:db/valueType :db.type/string
52+
:db/cardinality :db.cardinality/many}
53+
:definition/varargs-min-arity {:db/valueType :db.type/long}
54+
:definition/added {:db/valueType :db.type/string}
55+
:definition/macro {:db/valueType :db.type/boolean}
56+
:definition/row {:db/valueType :db.type/long}
57+
:definition/col {:db/valueType :db.type/long}})
58+
59+
(def db-schemas
60+
(merge project-schema library-schema definition-schema))
61+
62+
(comment
63+
(require '[codes.clj.docs.extractor.fixtures.analysis :as fix])
64+
65+
(let [conn (d/get-conn "/tmp/mydb" db-schemas)
66+
db (d/db conn)]
67+
(d/transact! conn (concat fix/projects-adapted
68+
fix/libraries-adapted
69+
fix/definitions-adapted))
70+
(pprint/pprint (d/q '[:find (pull ?e [*])
71+
:in $ ?q
72+
:where [?e :project/name ?q]]
73+
db
74+
"org.clojure/clojure"))
75+
(d/close conn)))
Lines changed: 7 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,20 @@
11
(ns codes.clj.docs.extractor.adapters-test
22
(:require [clojure.test :refer [deftest is testing]]
33
[codes.clj.docs.extractor.adapters :as adapters]
4+
[codes.clj.docs.extractor.fixtures.analysis :as fixtures.analysis]
45
[matcher-combinators.test :refer [match?]]))
56

6-
(def analysis-fixture
7-
[{:project {:git/url "https://github.com/clojure/clojure"
8-
:git/tag "clojure-1.11.1"
9-
:git/sha "ce55092f2b2f5481d25cff6205470c1335760ef6"
10-
:deps/manifest :pom
11-
:deps/root "/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6"
12-
:parents #{[]}
13-
:paths ["/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/main/java"
14-
"/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/main/clojure"
15-
"/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/resources"
16-
"/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/clj"]
17-
:project-name "org.clojure/clojure"}
18-
:libraries [{:end-row 39
19-
:meta {}
20-
:name-end-col 19
21-
:name-end-row 37
22-
:name-row 37
23-
:added "1.2"
24-
:name 'clojure.pprint
25-
:author "Tom Faulhaber"
26-
:filename "/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/clj/clojure/pprint.clj"
27-
:col 1
28-
:name-col 5
29-
:end-col 40
30-
:doc "A Pretty Printer for Clojure\n\nclojure.pprint implements a flexible system for printing structured data\nin a pleasing easy-to-understand format. Basic use of the pretty printer is \nsimple just call pprint instead of println. More advanced users can use \nthe building blocks provided to create custom output formats. \n\nOut of the box pprint supports a simple structured format for basic data \nand a specialized format for Clojure source code. More advanced formats \nincluding formats that don't look like Clojure data at all like XML and \nJSON can be rendered by creating custom dispatch functions. \n\nIn addition to the pprint function this module contains cl-format a text \nformatting function which is fully compatible with the format function in \nCommon Lisp. Because pretty printing directives are directly integrated with\ncl-format it supports very concise custom dispatch. It also provides\na more powerful alternative to Clojure's standard format function.\n\nSee documentation for pprint and cl-format for more information or \ncomplete documentation on the Clojure web site on GitHub."
31-
:row 14}]
32-
:definitions [{:end-row 109
33-
:meta {}
34-
:name-end-col 30
35-
:name-end-row 109
36-
:name-row 109
37-
:ns 'clojure.pprint
38-
:name 'format-simple-number
39-
:defined-by 'clojure.core/declare
40-
:filename "/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/clj/clojure/pprint/pprint_base.clj"
41-
:col 1
42-
:name-col 10
43-
:end-col 31
44-
:row 109}
45-
{:end-row 327
46-
:meta {:arglists '[[options* body]]}
47-
:name-end-col 31
48-
:name-end-row 302
49-
:name-row 302
50-
:added "1.2"
51-
:ns 'clojure.pprint
52-
:name 'pprint-logical-block
53-
:defined-by 'clojure.core/defmacro
54-
:filename "/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/clj/clojure/pprint/pprint_base.clj"
55-
:macro true
56-
:col 1
57-
:name-col 11
58-
:end-col 16
59-
:arglist-strs ["[& args]"]
60-
:varargs-min-arity 0
61-
:doc
62-
"Execute the body as a pretty printing logical block with output to *out* which \nmust be a pretty printing writer. When used from pprint or cl-format this can be \nassumed. \n\nThis function is intended for use when writing custom dispatch functions.\n\nBefore the body the caller can optionally specify options: :prefix :per-line-prefix \nand :suffix."
63-
:row 302}
64-
{:fixed-arities #{1 2}
65-
:end-row 35
66-
:meta {}
67-
:name-end-col 18
68-
:name-end-row 11
69-
:name-row 11
70-
:added "1.3"
71-
:ns 'clojure.pprint
72-
:name 'print-table
73-
:defined-by 'clojure.core/defn
74-
:filename "/Users/username/.gitlibs/libs/org.clojure/clojure/ce55092f2b2f5481d25cff6205470c1335760ef6/src/clj/clojure/pprint/print_table.clj"
75-
:col 1
76-
:name-col 7
77-
:end-col 51
78-
:arglist-strs ["[ks rows]" "[rows]"]
79-
:doc "Prints a collection of maps in a textual table. Prints table headings\n ks and then a line of output for each row corresponding to the keys\n in ks. If ks are not specified use the keys of the first item in rows."
80-
:row 11}]}])
81-
827
(deftest analysis->projects-test
838
(testing "analysis -> project"
84-
(is (match? [#:project{:name "org.clojure/clojure"
85-
:group "org.clojure"
86-
:artifact "clojure"
87-
:paths ["/src/main/java"
88-
"/src/main/clojure"
89-
"/src/resources"
90-
"/src/clj"]
91-
:url "https://github.com/clojure/clojure"
92-
:tag "clojure-1.11.1"
93-
:sha "ce55092f2b2f5481d25cff6205470c1335760ef6"
94-
:manifest :pom}]
95-
(adapters/analysis->projects analysis-fixture)))))
9+
(is (match? fixtures.analysis/projects-adapted
10+
(adapters/analysis->projects fixtures.analysis/raw)))))
9611

9712
(deftest analysis->libraries-test
9813
(testing "analysis -> libraries"
99-
(is (match? [#:library{:project "org.clojure/clojure"
100-
:artifact "clojure"
101-
:name-end-col 19
102-
:added "1.2"
103-
:group "org.clojure"
104-
:end-col 40
105-
:end-row 39
106-
:git-source "https://github.com/clojure/clojure/blob/clojure-1.11.1/src/clj/clojure/pprint.clj#L14"
107-
:name-row 37
108-
:meta {}
109-
:row 14
110-
:name-col 5
111-
:author "Tom Faulhaber"
112-
:col 1
113-
:name "clojure.pprint"
114-
:doc "A Pretty Printer for Clojure\n\nclojure.pprint implements a flexible system for printing structured data\nin a pleasing easy-to-understand format. Basic use of the pretty printer is \nsimple just call pprint instead of println. More advanced users can use \nthe building blocks provided to create custom output formats. \n\nOut of the box pprint supports a simple structured format for basic data \nand a specialized format for Clojure source code. More advanced formats \nincluding formats that don't look like Clojure data at all like XML and \nJSON can be rendered by creating custom dispatch functions. \n\nIn addition to the pprint function this module contains cl-format a text \nformatting function which is fully compatible with the format function in \nCommon Lisp. Because pretty printing directives are directly integrated with\ncl-format it supports very concise custom dispatch. It also provides\na more powerful alternative to Clojure's standard format function.\n\nSee documentation for pprint and cl-format for more information or \ncomplete documentation on the Clojure web site on GitHub."
115-
:name-end-row 37
116-
:filename "/src/clj/clojure/pprint.clj"}]
117-
(adapters/analysis->libraries analysis-fixture)))))
14+
(is (match? fixtures.analysis/libraries-adapted
15+
(adapters/analysis->libraries fixtures.analysis/raw)))))
11816

11917
(deftest analysis->definitions-test
12018
(testing "analysis -> definitions"
121-
(is (match? [#:definition{:defined-by "clojure.core/defmacro"
122-
:library "clojure.pprint"
123-
:filename "/src/clj/clojure/pprint/pprint_base.clj"
124-
:macro true
125-
:project "org.clojure/clojure"
126-
:row 302
127-
:varargs-min-arity 0
128-
:added "1.2"
129-
:arglist-strs ["[& args]"]
130-
:col 1
131-
:name-col 11
132-
:end-col 16
133-
:doc "Execute the body as a pretty printing logical block with output to *out* which \nmust be a pretty printing writer. When used from pprint or cl-format this can be \nassumed. \n\nThis function is intended for use when writing custom dispatch functions.\n\nBefore the body the caller can optionally specify options: :prefix :per-line-prefix \nand :suffix."
134-
:git-source "https://github.com/clojure/clojure/blob/clojure-1.11.1/src/clj/clojure/pprint/pprint_base.clj#L302"
135-
:name-end-row 302
136-
:name-row 302
137-
:group "org.clojure"
138-
:meta {:arglists '[[options* body]]}
139-
:artifact "clojure"
140-
:name-end-col 31
141-
:end-row 327
142-
:name "pprint-logical-block"}
143-
#:definition{:defined-by "clojure.core/defn"
144-
:library "clojure.pprint"
145-
:filename "/src/clj/clojure/pprint/print_table.clj"
146-
:project "org.clojure/clojure"
147-
:row 11
148-
:added "1.3"
149-
:arglist-strs ["[ks rows]" "[rows]"]
150-
:col 1
151-
:name-col 7
152-
:end-col 51
153-
:doc "Prints a collection of maps in a textual table. Prints table headings\n ks and then a line of output for each row corresponding to the keys\n in ks. If ks are not specified use the keys of the first item in rows."
154-
:git-source "https://github.com/clojure/clojure/blob/clojure-1.11.1/src/clj/clojure/pprint/print_table.clj#L11"
155-
:fixed-arities #{1 2}
156-
:name-end-row 11
157-
:name-row 11
158-
:group "org.clojure"
159-
:meta {}
160-
:artifact "clojure"
161-
:name-end-col 18
162-
:end-row 35
163-
:name "print-table"}]
164-
(adapters/analysis->definitions analysis-fixture)))))
19+
(is (match? fixtures.analysis/definitions-adapted
20+
(adapters/analysis->definitions fixtures.analysis/raw)))))

0 commit comments

Comments
 (0)