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
key
The key for which the value is requestedcallback
The callback function to be executed when the Get operation is completedisSuccess
This parameter indicates if the request has been successfulmessage
If the request has not been successful, you will get an error messagevalue
The value in the datastore with the given keyinfo
DatastoreKeyInfo 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
key
The key for which the value should be setvalue
The value that will be set to. Note that you can send values of any type, including bool, string, number, and lua table.callback
The callback function to be executed when the Set operation is completedisSuccess
This parameter indicates if the setting has been successfulmessage
If the setting has not been successful, you will get an error messagevalue
The latest value in the datastore with the given keyinfo
DatastoreKeyInfo includes the version number, date and time the version was created, and metadata if it exists
metadata
Optional 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
key
The key for which the value should be updateddelta
The amount to be added to the current valuecallback
The callback function to be executed when the Increment operation is completedisSuccess
This parameter indicates if the addition has been successfulmessage
If the addition has not been successful, you will get an error messagevalue
The latest value in the datastore with the given keyinfo
DatastoreKeyInfo includes the version number, date and time the version was created, and metadata if it exists
metadata
Optional 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.
key
The key for which the value should be removedcallback
The callback function to be executed when the Remove operation is completedisSuccess
This parameter indicates if the Remove operation has been successfulmessage
If the operation has not been successful, you will get an error messagevalue
The value in the datastore prior to the deletioninfo
DatastoreKeyInfo 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
key
The key for which the value is requestedversion
The version for which the value is requestedcallback
The callback function to be executed when the Get operation is completedisSuccess
This parameter indicates if the request has been successfulmessage
If the request has not been successful, you will get an error messagevalue
The specified value for the given key and versioninfo
DatastoreKeyInfo 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
callback
The callback function to be executed when the List operation is completedisSuccess
This parameter indicates if the enumeration has been successfulmessage
If the enumeration has not been successful, you will get an error messageDatastoreKeyPages
DatastoreKeyPages displays all the keys stored in the datastore, presented in a paginated format
prefix
Optional parameter. Restricts the keyName results to those that match the given prefix. Default Value: ""pageSize
Optional parameter. Specifies the length of each page. Default value: 10offset
Optional parameter. Specifies the page offset. Default value: 0excludeDeleted
Optional 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
key
The key for which all histories are requestedcallback
The callback to be executed when the enumeration is completedisSuccess
This parameter indicates if the request was success.message
If the request was not success, you will get error message.DatastoreVersionPages
DatastoreVersionPages 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
key
The key name for which a version is to be removedversion
The version number of the key to removecallback
The callback function to be executed when the Remove operation is completedisSuccess
This parameter indicates if the Remove operation has been successfulmessage
If 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 |
|