Skip to content

Commit c424c77

Browse files
committed
Update docstrings
1 parent 673c0ef commit c424c77

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
*.iml
55
*.db
66
.DS_Store
7-
*.xdb
7+
*.xdb
8+
target/

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
## Overview
1616

17-
`xitdb-clj` is a database for efficiently storing and retrieving immutable, persistent data structures.
17+
`xitdb-clj` is a embedded database for efficiently storing and retrieving immutable, persistent data structures.
1818

1919
It is a Clojure interface for [xitdb-java](https://github.com/radarroark/xitdb-java),
2020
itself a port of [xitdb](https://github.com/radarroark/xitdb), written in Zig.
@@ -26,12 +26,11 @@ itself a port of [xitdb](https://github.com/radarroark/xitdb), written in Zig.
2626
- Embeddable, tiny library.
2727
- Supports writing to a file as well as purely in-memory use.
2828
- Each transaction (done via `swap!`) efficiently creates a new "copy" of the database, and past copies can still be read from.
29-
- Reading/Writing to the database is extremely efficient, only the necessary nodes are read or written.
29+
- Reading/Writing to the database is efficient, only the necessary nodes are read or written.
3030
- Thread safe. Multiple readers, one writer.
3131
- Append-only. The data you are writing is invisible to any reader until the very last step, when the top-level history header is updated.
32-
- No dependencies besides `clojure.core` and [xitdb-java](https://github.com/radarroark/xitdb-java).
3332
- All heavy lifting done by the bare-to-the-jvm java library.
34-
- Database files accessible from many other languages - all JVM based or languages which can natively interface with Zig (C, C++, Python, Rust, Go, etc)
33+
- Database files can be used from other languages, via [xitdb Java library](https://github.com/radarroark/xitdb-java) or the [xitdb Zig library](https://github.com/radarroark/xitdb)
3534

3635
## Architecture
3736

@@ -175,10 +174,7 @@ values of the database, by setting the `*return-history?*` binding to `true`.
175174
Add to your `deps.edn`:
176175

177176
```clojure
178-
{:deps {org.clojure/clojure {:mvn/version "1.12.0"}
179-
io.github.radarroark/xitdb {:mvn/version "0.20.0"}
180-
;; Add your local xitdb-clj dependency here
181-
}}
177+
{:deps {io.github.codeboost/xitdb-clj {:mvn/version "0.1.0"}}}
182178
```
183179

184180
## Examples

src/xitdb/db.clj

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
(conversion/v->slot! cursor new-value))))
4242

4343
(defn open-database
44+
"Opens database `filename`.
45+
If `filename` is `:memory`, returns a memory based db.
46+
open-mode can be `r` or `rw`."
4447
[filename ^String open-mode]
4548
(let [core (if (= filename :memory)
4649
(CoreMemory. (RandomAccessMemory.))
@@ -58,7 +61,11 @@
5861
(conversion/v->slot! cursor v)))
5962

6063
(defn xitdb-swap!
61-
"Returns history index."
64+
"Starts a new transaction and calls `f` with the value at root.
65+
`f` will receive a XITDBWrite* type (db) and `args`.
66+
Actions on the XITDBWrite* type (like `assoc`) will mutate it.
67+
Return value of `f` is written at (root) cursor.
68+
Returns the transaction history index."
6269
[db f & args]
6370
(let [history (db-history db)
6471
slot (.getSlot history -1)]
@@ -90,16 +97,22 @@
9097
(finally
9198
(.unlock lock)))))
9299

93-
(defn- close-db-internal! [^Database db]
100+
(defn- close-db-internal!
101+
"Closes the db file. Does nothing if it's a memory db"
102+
[^Database db]
94103
(let [core (-> db .-core)]
95104
(when (instance? CoreFile core)
96105
(.close ^RandomAccessFile (-> db .-core .file)))))
97106

98107

99-
(defn ^ReadArrayList read-history [^Database db]
108+
(defn ^ReadArrayList read-history
109+
"Returns the read only transaction history array."
110+
[^Database db]
100111
(ReadArrayList. (-> db .rootCursor)))
101112

102-
(defn history-index [xdb]
113+
(defn history-index
114+
"Returns the current size of the transaction history array."
115+
[xdb]
103116
(.count (read-history (-> xdb .tldbro .get))))
104117

105118
(deftype XITDBDatabase [tldbro rwdb lock]
@@ -143,7 +156,11 @@
143156
(apply xitdb-swap-with-lock! (concat [this f x y] args))))
144157

145158
(defn xit-db
146-
""
159+
"Returns a new XITDBDatabase which can be used to query and transact data.
160+
`filename` can be `:memory` or the name of a file on the filesystem.
161+
If the file does not exist, it will be created.
162+
The returned database handle can be used from multiple threads.
163+
Reads can run in parallel, transactions (eg. `swap!`) will only allow one writer at a time."
147164
[filename]
148165
(if (= :memory filename)
149166
(let [memdb (open-database :memory "rw")

0 commit comments

Comments
 (0)