Skip to content

Commit 34fd08c

Browse files
committed
Update README , add indices.md, remove CLAUDE.md
1 parent 120fb7c commit 34fd08c

File tree

4 files changed

+78
-49
lines changed

4 files changed

+78
-49
lines changed

CLAUDE.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
> **⚠️ Alpha Software - Work in Progress**
2+
>
3+
> This project is in early development and rapidly evolving.
4+
> Expect breaking changes, rough edges, and incomplete documentation.
5+
>
6+
> **🤝 Help Wanted!** If you find this useful, please consider contributing:
7+
> - Report bugs and issues you encounter
8+
> - Suggest improvements or new features
9+
> - Submit pull requests for fixes or enhancements
10+
> - Share your configuration patterns and workflows
11+
> - Help improve documentation and examples
12+
>
13+
> Your feedback and contributions will help make this tool better for the entire Clojure community!
14+
115
## Overview
216

317
`xitdb-clj` is a database for efficiently storing and retrieving immutable, persistent data structures.
@@ -7,10 +21,6 @@ itself a port of [xitdb](https://github.com/radarroark/xitdb), written in Zig.
721

822
`xitdb-clj` provides atom-like semantics when working with the database from Clojure.
923

10-
### Experimental
11-
12-
Code is still in early stages of 'alpha', things might change or break in future versions.
13-
1424
## Main characteristics
1525

1626
- Embeddable, tiny library.
@@ -61,6 +71,27 @@ For the programmer, a `xitdb` database behaves exactly like a Clojure atom.
6171
(get-in @db [:users "alice" :age])
6272
;; => 31
6373
```
74+
One important distinction to the Clojure atom is that inside a transaction (eg. a `swap!`),
75+
'change' operations on the received db argument are mutating it.
76+
77+
```clojure
78+
(with-db [db (xdb/xit-db :memory)]
79+
(reset! db {})
80+
(swap! db (fn [db]
81+
(let [db1 (assoc db :foo :bar)]
82+
(println "db1:" db1)
83+
(println "db:" db)))))
84+
```
85+
prints
86+
```
87+
db1: {:foo :bar}
88+
db: {:foo :bar}
89+
```
90+
As you can see, `(assoc db :foo :bar)` changed the value of `db`, in contrast
91+
to how it works with a Clojure persistent map. This is because, inside `swap!`,
92+
`db` is referencing a WriteCursor, which writes the value to the underlying
93+
ArrayList or HashMap objects inside `xit-db-java`.
94+
The value will actually be commited to the database when the `swap!` function returns.
6495

6596
## Data structures are read lazily from the database
6697

doc/indices.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Using indices with xitdb
2+
3+
There's no built-in support for indices, because...
4+
Indices are yet another data structure which you can store in the database.
5+
6+
```clojure
7+
8+
(defn records->index-set
9+
"Returns a map keyed by `k` and valued by a `set` of ids."
10+
[records k & {:keys [id] :or {id :id}}]
11+
(->> records
12+
(group-by k)
13+
(map (fn [[k songs]]
14+
[k (->> songs (map id) set)]))
15+
(into {})))
16+
17+
(defn update-index
18+
"Updates an index in `m`.
19+
All indices are stored in the 'index' map (eg. songs-index).
20+
Eg:
21+
`{:songs-index {:artist {'foo' #{8 9}}}`
22+
The songs-index contains an index which groups the songs by artist name -> set of song ids.
23+
k represents the `key` on which the `records` are going to be grouped and
24+
then merged into the `k` index."
25+
[m index k records]
26+
(let [k->song-id-set (records->index-set records k)]
27+
(update-in m [index k] #(merge-with into % k->song-id-set))))
28+
29+
(defn insert-songs! [db songs]
30+
(let [id->song (into {} (map (juxt :id identity)) songs)]
31+
(swap! db (fn [m]
32+
(-> m
33+
(update :songs merge id->song)
34+
(update-index :songs-indices :artist songs)
35+
(update-index :songs-indices :tag songs)
36+
(update-index :songs-indices :year songs))))))
37+
```
38+
39+
40+
# External indices
41+
Indices can be stored in a separate database file.
42+
In fact, you might not need all indices in your 'live' database, but you might
43+
need some indices for analytics or reporting.

doc/performance.md

Whitespace-only changes.

0 commit comments

Comments
 (0)