Datastore¶
Datastore is a powerful storage system designed to persistently store user and game data, such as items and leaderboards.
It ensures data consistency across sessions and games, allowing different servers to access and modify the same set of data.
This Datastore struct contains a set of functions for manipulating data.Functions¶
void GetAsync(string key, function callback<boolean, string, string, DatastoreKeyInfo?>)¶
SERVER ONLY 
Get the latest value and its associated datastoreKeyInfo with the provided key, and call the callback function when the Get operation is completed
 Returns 'nil' if the key does not exist or if the latest value has been deleted
- keyThe key for which the value is requested
- callbackThe callback function to be executed when the Get operation is completed- isSuccessThis parameter indicates if the request has been successful
- messageIf the request has not been successful, you will get an error message
- valueThe value in the datastore with the given key
- infoDatastoreKeyInfo includes the version number, date and time the version was created, and metadata if it exists
 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |  | 
void SetAsync(string key, string value, function callback<boolean, string, string, DatastoreKeyInfo?>, [string metadata])¶
SERVER ONLY 
Set the latest value for the provided key, and call the callback function when the Set operation is completed
- keyThe key for which the value should be set
- valueThe value that will be set to. Note that you can send values of any type, including bool, string, number, and lua table.
- callbackThe callback function to be executed when the Set operation is completed- isSuccessThis parameter indicates if the setting has been successful
- messageIf the setting has not been successful, you will get an error message
- valueThe latest value in the datastore with the given key
- infoDatastoreKeyInfo includes the version number, date and time the version was created, and metadata if it exists
 
- metadataOptional parameter. If set, it will upload the set metadata. The metadata must be a Lua table and its keys must be string
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |  | 
void IncAsync(string key, number delta, function callback<boolean, string, string, DatastoreKeyInfo?>, [string metadata])¶
SERVER ONLY 
Increment the value of a key by the provided amount (both must be integers), and call the callback function when the Increment operation is completed
- keyThe key for which the value should be updated
- deltaThe amount to be added to the current value
- callbackThe callback function to be executed when the Increment operation is completed- isSuccessThis parameter indicates if the addition has been successful
- messageIf the addition has not been successful, you will get an error message
- valueThe latest value in the datastore with the given key
- infoDatastoreKeyInfo includes the version number, date and time the version was created, and metadata if it exists
 
- metadataOptional parameter. If set, it will upload the set metadata. The metadata must be a Lua table and its keys must be string
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |  | 
void RemoveAsync(string key, function callback<boolean, string, string, DatastoreKeyInfo?>)¶
SERVER ONLY 
Remove the value for the provided key, and call the callback function when the Remove operation is completed. Note that this function does not delete the data.
 If needed, removed values can be retrieved using Datastore:GetVersionAsync(). Removed objects will be permanently deleted after 30 days.
- keyThe key for which the value should be removed
- callbackThe callback function to be executed when the Remove operation is completed- isSuccessThis parameter indicates if the Remove operation has been successful
- messageIf the operation has not been successful, you will get an error message
- valueThe value in the datastore prior to the deletion
- infoDatastoreKeyInfo includes the version number, date and time the version was created, and metadata if it exists.
 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |  | 
void GetVersionAsync(string key, string version, function callback<boolean, string, string, DatastoreKeyInfo?>)¶
SERVER ONLY 
Get the specified value and its datastoreKeyInfo with the provided key and version, and call the callback function when the Get operation is completed
- keyThe key for which the value is requested
- versionThe version for which the value is requested
- callbackThe callback function to be executed when the Get operation is completed- isSuccessThis parameter indicates if the request has been successful
- messageIf the request has not been successful, you will get an error message
- valueThe specified value for the given key and version
- infoDatastoreKeyInfo includes the version number, date and time the version was created, and metadata if it exists
 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |  | 
void ListKeysAsync(function callback<boolean, string, DatastoreKeyPages?>, [string prefix], [number pageSize], [number offset], [boolean excludeDeleted])¶
SERVER ONLY 
Enumerate through all keys of a datastore and call the callback function when the enumeration is completed
 
prefix is used to restrict the keyName results. excludeDeleted is used to filter out deleted keys.
 PageSize and Offset are used for pagination, where the former refers length of each page and the latter indicates the page offset
- callbackThe callback function to be executed when the List operation is completed- isSuccessThis parameter indicates if the enumeration has been successful
- messageIf the enumeration has not been successful, you will get an error message
- DatastoreKeyPagesDatastoreKeyPages displays all the keys stored in the datastore, presented in a paginated format
 
- prefixOptional parameter. Restricts the keyName results to those that match the given prefix. Default Value: ""
- pageSizeOptional parameter. Specifies the length of each page. Default value: 10
- offsetOptional parameter. Specifies the page offset. Default value: 0
- excludeDeletedOptional parameter. Filters out deleted keys. Default value: false
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |  | 
void ListVersionsAsync(string key, function callback<boolean, string, DatastoreVersionPages?>, [boolean ascending], [number pageSize], [number offset], [number minDate], [number maxDate])¶
SERVER ONLY 
Enumerate all histories of a specific key and call the callback function when the enumeration is completed
- keyThe key for which all histories are requested
- callbackThe callback to be executed when the enumeration is completed- isSuccessThis parameter indicates if the request was success.
- messageIf the request was not success, you will get error message.
- DatastoreVersionPagesDatastoreVersionPages displays the history of a specific key, presented in a paginated format.
 
- ascending(Optional) Determines whether the pages are sorted in ascending order. Default value: false, meaning the descending sort order
- pageSize(Optional) Specifies the length of each page. Default value: 10
- offset(Optional) Specifies the page offset. Default value: 0
- minDate(Optional) If set, the creation time earlier than the minDate will be excluded. Default value: 0
- maxDate(Optional) If set, the creation time later than the maxDate will be excluded. Default value: INT_MAX
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |  | 
void RemoveVersionAsync(string key, string version, function callback<boolean, string>)¶
SERVER ONLY 
Remove the specified value permanently, and call the callback function after the Remove operation is completed
- keyThe key name for which a version is to be removed
- versionThe version number of the key to remove
- callbackThe callback function to be executed when the Remove operation is completed- isSuccessThis parameter indicates if the Remove operation has been successful
- messageIf the Remove operation has not been successful, you will get an error message
 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |  |