Interface: Dictionary<T>
Extends
Type Parameters
| Type Parameter |
|---|
T |
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
createdAt |
readonly |
Date |
In UTC. |
options? |
readonly |
CollectionOptions |
- |
updatedAt |
readonly |
Date |
In UTC. |
Methods
[asyncIterator]()
asyncIterator: AsyncIterator<KeyValuePair<T>>;
Enables for-await-of iteration.
Returns
AsyncIterator<KeyValuePair<T>>
Example
Iterate through a large append log
// Ensure you import DataPowers
import { DataPowers, CollectionType, CollectionExpirationMode } from "@andi/powers";
type FiSkillLog = {
data: string;
};
const skillLogs = await DataPowers.getOrCreateCollection<FiSkillLog>(CollectionType.Dictionary, "log", { expiry: { expireMode: CollectionExpirationMode.Never } });
// Sometimes the logs may grow beyond what's performant to load all at once in memory. Use an async iterator to process each log, line by line
for await (const log of skillLogs) {
// granular processing
}
Inherited from
clear()
clear(): Promise<boolean>;
WARNING: Removes all data for collection.
Cannot be undone.
Returns
Promise<boolean>
delete()
delete(key): Promise<boolean>;
Cannot be undone.
Parameters
| Parameter | Type |
|---|---|
key |
string |
Returns
Promise<boolean>
Throws
when key is not a string.
Throws
when key length is >512 length
entries()
entries(): Promise<KeyValuePair<T>[]>;
Fetch all values for collection
WARNING: For >100 MB of total data, consider using for-await-of iteration to process items one by one.
Returns
Promise<KeyValuePair<T>[]>
get()
get(key): Promise<T>;
Parameters
| Parameter | Type |
|---|---|
key |
string |
Returns
Promise<T>
Throws
when key is not a string.
Throws
when key length is >512 length
getEntry()
getEntry(key): Promise<KeyValuePair<T>>;
Parameters
| Parameter | Type |
|---|---|
key |
string |
Returns
Promise<KeyValuePair<T>>
Throws
when key is not a string.
Throws
when key length is >512 length
getSize()
getSize(): Promise<number>;
Returns
Promise<number>
Inherited from
has()
has(key): Promise<boolean>;
Parameters
| Parameter | Type |
|---|---|
key |
string |
Returns
Promise<boolean>
Throws
when key is not a string.
Throws
when key length is >512 length
keys()
keys(): Promise<string[]>;
Returns
Promise<string[]>
set()
set(key, value): Promise<void>;
Parameters
| Parameter | Type |
|---|---|
key |
string |
value |
T |
Returns
Promise<void>
Throws
when key is not a string.
Throws
when key length is >512 length
Throws
when value size exceeds 8 MB (serialized).
values()
values(): Promise<T[]>;
Fetch all values for collection
WARNING: For >100 MB of total data, consider using for-await-of iteration to process items one by one.
Returns
Promise<T[]>