|
41 | 41 | (conversion/v->slot! cursor new-value))))
|
42 | 42 |
|
43 | 43 | (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`." |
44 | 47 | [filename ^String open-mode]
|
45 | 48 | (let [core (if (= filename :memory)
|
46 | 49 | (CoreMemory. (RandomAccessMemory.))
|
|
58 | 61 | (conversion/v->slot! cursor v)))
|
59 | 62 |
|
60 | 63 | (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." |
62 | 69 | [db f & args]
|
63 | 70 | (let [history (db-history db)
|
64 | 71 | slot (.getSlot history -1)]
|
|
90 | 97 | (finally
|
91 | 98 | (.unlock lock)))))
|
92 | 99 |
|
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] |
94 | 103 | (let [core (-> db .-core)]
|
95 | 104 | (when (instance? CoreFile core)
|
96 | 105 | (.close ^RandomAccessFile (-> db .-core .file)))))
|
97 | 106 |
|
98 | 107 |
|
99 |
| -(defn ^ReadArrayList read-history [^Database db] |
| 108 | +(defn ^ReadArrayList read-history |
| 109 | + "Returns the read only transaction history array." |
| 110 | + [^Database db] |
100 | 111 | (ReadArrayList. (-> db .rootCursor)))
|
101 | 112 |
|
102 |
| -(defn history-index [xdb] |
| 113 | +(defn history-index |
| 114 | + "Returns the current size of the transaction history array." |
| 115 | + [xdb] |
103 | 116 | (.count (read-history (-> xdb .tldbro .get))))
|
104 | 117 |
|
105 | 118 | (deftype XITDBDatabase [tldbro rwdb lock]
|
|
143 | 156 | (apply xitdb-swap-with-lock! (concat [this f x y] args))))
|
144 | 157 |
|
145 | 158 | (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." |
147 | 164 | [filename]
|
148 | 165 | (if (= :memory filename)
|
149 | 166 | (let [memdb (open-database :memory "rw")
|
|
0 commit comments