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 requestedcallbackThe callback function to be executed when the Get operation is completedisSuccessThis parameter indicates if the request has been successfulmessageIf the request has not been successful, you will get an error messagevalueThe value in the datastore with the given keyinfoDatastoreKeyInfo 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 setvalueThe 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 completedisSuccessThis parameter indicates if the setting has been successfulmessageIf the setting has not been successful, you will get an error messagevalueThe latest value in the datastore with the given keyinfoDatastoreKeyInfo 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 updateddeltaThe amount to be added to the current valuecallbackThe callback function to be executed when the Increment operation is completedisSuccessThis parameter indicates if the addition has been successfulmessageIf the addition has not been successful, you will get an error messagevalueThe latest value in the datastore with the given keyinfoDatastoreKeyInfo 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 removedcallbackThe callback function to be executed when the Remove operation is completedisSuccessThis parameter indicates if the Remove operation has been successfulmessageIf the operation has not been successful, you will get an error messagevalueThe value in the datastore prior to the deletioninfoDatastoreKeyInfo 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 requestedversionThe version for which the value is requestedcallbackThe callback function to be executed when the Get operation is completedisSuccessThis parameter indicates if the request has been successfulmessageIf the request has not been successful, you will get an error messagevalueThe specified value for the given key and versioninfoDatastoreKeyInfo 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 completedisSuccessThis parameter indicates if the enumeration has been successfulmessageIf the enumeration has not been successful, you will get an error messageDatastoreKeyPagesDatastoreKeyPages 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: 10offsetOptional parameter. Specifies the page offset. Default value: 0excludeDeletedOptional 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 requestedcallbackThe callback to be executed when the enumeration is completedisSuccessThis 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 orderpageSize(Optional) Specifies the length of each page. Default value: 10offset(Optional) Specifies the page offset. Default value: 0minDate(Optional) If set, the creation time earlier than the minDate will be excluded. Default value: 0maxDate(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 removedversionThe version number of the key to removecallbackThe callback function to be executed when the Remove operation is completedisSuccessThis parameter indicates if the Remove operation has been successfulmessageIf 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 | |