-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9543d5d
commit ea0a8c9
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Storage Collections | ||
DATEX allows the usage of native Set and Map objects. Those types are stored in RAM and may impact performance when it's data is getting to large. | ||
For this reason DATEX provides special storage collections that allow the handling of massive amounts of data more efficiently. | ||
|
||
The API is similar to the native JavaScript collections with the major difference that their instance methods are asynchronous. | ||
To get the size of the collection it is recommended to use the asynchronous `getSize` method. | ||
|
||
> [!NOTE] | ||
> The storage collections are not stored persistently by default. To store persistent data refer to [Eternal Pointers](./05%20Eternal%20Pointers.md). | ||
## StorageSet | ||
```ts | ||
import "datex-core-legacy/types/storage-set.ts"; | ||
const mySet = new StorageSet<number>(); | ||
await mySet.add(123); // Add 123 to the StorageSet | ||
|
||
for await (const entry of mySet) { // Iterate over values | ||
console.log(entry); | ||
} | ||
|
||
await mySet.getSize(); // Returns the size of the StorageSet (1) | ||
await mySet.clear(); // Clear StorageSet | ||
``` | ||
|
||
## StorageMap | ||
```ts | ||
import "datex-core-legacy/types/storage-map.ts"; | ||
const myMap = new StorageMap<string, number>(); | ||
await myMap.set("myKey", 123); // Add key 'myKey' with value 123 to the StorageMap | ||
|
||
for await (const [key, value] of myMap) { // Iterate over entries | ||
console.log(key, value); | ||
} | ||
|
||
await mySet.getSize(); // Returns the size of the StorageMap (1) | ||
await myMap.clear(); // Clear StorageMap | ||
``` |