Collection<T>¶
A collection is a class that contains the DataStore, and exposes methods to interact with it.
Collection:Select()¶
Collection:Select(
key: string
): (T, Error?)
public function Select(
key: string
): [T, Error | undefined];
Parameters:
keystring— Unique key for the requested data.
Returns:
T— Found value in the DataStore, orCollectionOptions.Defaultif an error occurs.Error?— An error value ornilif succeeded.
Description:
- Uses
DataStore:GetAsync()to fetch the data from the DataStore.- Retries
CollectionOptions.MaxRetriestimes with aCollectionOptions.RetryDelaySecondsdelay if thepcall()has resulted in a failure.
- Retries
- Uses
CollectionOptions.Defaultto set the default value if the key does not exist yet. - Uses
CollectionOptions.Migrationsto migrate data of previous versions. - Uses
CollectionOptions.Validatefunction to validate the data. Forcefully returnsnilif the validation fails.
Collection:Update()¶
Collection:Update(
key: string,
data: T,
userIds: { number }
): Error?
public function Update(
key: string,
data: T,
userIds: number[]
): Error | undefined;
Parameters:
keystring— Unique key for the requested data.
Returns:
Description:
- Uses
CollectionOptions.Validatefunction to validate the given data. Rejects the update if the given data has failed validation. - Uses
DataStore:UpdateAsync()to fetch the data from the DataStore, reject the new update ifDataStorecontains a newer version, and set the new value if it has verified that it's newer.- Retries
CollectionOptions.MaxRetriestimes with aCollectionOptions.RetryDelaySecondsdelay if thepcall()has resulted in a failure.
- Retries