DataStore

Show Deprecated
Not Creatable
Not Replicated

Summary

Properties

Events

Methods

GetVersionAsync(key: string, version: string): Tuple  YIELDS

Retrieves the specified key version.

ListKeysAsync(prefix: string, pageSize: number): DataStoreKeyPages  YIELDS

Returns a DataStoreKeyPages object for enumerating through keys of a data store.

ListVersionsAsync(key: string, sortDirection: SortDirection, minDate: number, maxDate: number, pageSize: number): DataStoreVersionPages  YIELDS

Enumerates all versions of a key.

RemoveVersionAsync(key: string, version: string): nil  YIELDS

Permanently deletes the specified version of a key.

Properties

Events

Methods

GetVersionAsync

Yields

This function retrieves the specified key version as well as a DataStoreKeyInfo instance. A version identifier can be found through DataStore:ListVersionsAsync() or alternatively be the identifier returned by GlobalDataStore:SetAsync().

Parameters

key: string

Key name for which the version info is requested. If DataStoreOptions.AllScopes was set to true when accessing the data store through DataStoreService:GetDataStore(), this key name must be prepended with the original scope as in "scope/key".

version: string

Version number of the key for which the version info is requested.


Returns

The value of the key at the specified version and a DataStoreKeyInfo instance that includes the version number, date and time the version was created, and functions to retrieve UserIds and metadata.

ListKeysAsync

Yields

This function returns a DataStoreKeyPages object for enumerating through keys of a data store. It accepts an optional prefix parameter to only locate keys whose names start with the provided prefix.

If DataStoreOptions.AllScopes was set to true when accessing the data store through DataStoreService:GetDataStore(), keys will be returned with all scopes as prefixes.

Parameters

prefix: string

(Optional) Prefix to use for locating keys.

Default Value: ""
pageSize: number

(Optional) Number of items to be returned in each page.

Default Value: "0"

Returns

A DataStoreKeyPages instance that enumerates the keys as DataStoreKey instances.

ListVersionsAsync

Yields

This function enumerates versions of the specified key in either ascending or descending order specified by a SortDirection parameter. It can optionally filter the returned versions by minimum and maximum timestamp.

Parameters

key: string

Key name for the versions to list. If DataStoreOptions.AllScopes was set to true when accessing the data store through DataStoreService:GetDataStore(), this key name must be prepended with the original scope as in "scope/key".

sortDirection: SortDirection

Enum specifying ascending or descending sort order.

Default Value: "Ascending"
minDate: number

Date after which the versions should be listed.

Default Value: "0"
maxDate: number

Date up to which the versions should be listed.

Default Value: "0"
pageSize: number

Number of items to be returned in each page.

Default Value: "0"

Returns

A DataStoreVersionPages instance that enumerates all the versions of the key as DataStoreObjectVersionInfo instances.

Code Samples

Retrieving DataStore Versions With A Date Filter

1local DataStoreService = game:GetService("DataStoreService")
2
3local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
4
5local time = DateTime.fromUniversalTime(2020, 10, 09, 01, 42)
6
7local listSuccess, pages = pcall(function()
8 return experienceStore:ListVersionsAsync("User_1234", nil, time.UnixTimestampMillis)
9end)
10
11if listSuccess then
12 local items = pages:GetCurrentPage()
13
14 for key, info in pairs(items) do
15 print("Key:", key, "; Version:", info.Version, "; Created:", info.CreatedTime, "; Deleted:", info.IsDeleted)
16 end
17end

RemoveVersionAsync

Yields

This function permanently deletes the specified version of a key. Version identifiers can be found through DataStore:ListVersionsAsync().

Unlike GlobalDataStore:RemoveAsync(), this function does not create a new "tombstone" version and the removed value cannot be retrieved later.

Parameters

key: string

Key name for which a version is to be removed. If DataStoreOptions.AllScopes was set to true when accessing the data store through DataStoreService:GetDataStore(), this key name must be prepended with the original scope as in "scope/key".

version: string

Version number of the key to remove.


Returns

No return.