Skip to content

Commit a5d2f1c

Browse files
authored
Enhance README with usage examples for AstraDB
Added sections for adding a key and value, retrieving values, and listening for real-time updates.
1 parent d6bbd1f commit a5d2f1c

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ npm install @bitxenia/astradb
3939

4040
Using the `createAstradb` init function you can create and connect the node to a database.
4141

42+
4243
```ts
4344
import { createAstradb } from "@bitxenia/astradb";
4445

@@ -50,9 +51,45 @@ const keyList = await node.getAllKeys();
5051
console.log(keyList);
5152
```
5253

54+
### Add a Key and Value
55+
56+
You can add a new value under a specific key.
57+
Each addition is stored as a new event in the key’s history.
58+
59+
60+
```ts
61+
await node.add("article:001", "First version of the article");
62+
console.log("Value added successfully");
63+
```
64+
65+
### Get Values from a Key
66+
67+
Retrieve all stored values for a specific key.
68+
Each value represents an event in the order it was added.
69+
70+
```ts
71+
const values = await node.get("article:001");
72+
console.log(values);
73+
// → ["First version of the article"]
74+
```
75+
76+
### Listen for Real-Time Updates
77+
78+
AstraDB emits events whenever a new value is added to a key that was previously fetched.
79+
The event name follows the format `{dbname}::{key}`.
80+
81+
```ts
82+
const astraDb = await createAstradb({ dbName: "mydb" });
83+
const values = await astraDb.get("exampleKey");
84+
85+
astraDb.events.on("mydb::exampleKey", async (value) => {
86+
console.log(`New value for exampleKey: ${value}`);
87+
});
88+
```
89+
5390
## Documentation
5491

55-
You can find more advanced topics, such as a detailed explanation of AstraDB’s architecture and internal components in our [docs](https://github.com/bitxenia/docs/tree/main/ipfs/application).
92+
You can find more advanced topics, such as a detailed explanation of AstraDB’s architecture and internal components, in our [docs](https://github.com/bitxenia/docs/tree/main/ipfs/application).
5693

5794
## Development
5895

0 commit comments

Comments
 (0)