Hive Data Store uses NoSQL Cloud Database to synchronize and store the data for use on the client, such as the components of the game and the settings information. Using this service is a good solution for the games based on the client or if it needs real-time updates between clients.
Hive Data Store has the following features:
- The data is stored in the storage separately of each game.
- All data is encrypted and delivered safely.
- Unlike SQL database, NoSQL Cloud Database has no tables and rows, and the data is stored in documents consisting of collections.
- Stores and documented data as key-value pairs.
- Optimizes for storing the collection that consists of multiple documents.
- For the precautions of designing key-value, see the Operation > Game Data Store guide from Hive Developers.
Add Data
You can add data to the Data Store in one pair of a key-value or multiple pairs of map format at once. After a request, true
or false
is returned.
The followings are sample codes to add data of a key-value pair.
1 2 3 4 5 6 7 8 9 10 11 |
// Data store - Add data string key = "your data key"; string value = "your data value"; DataStore.set(key, value, (ResultAPI result)=>{ if (result.isSuccess()) { // success } else { // error handling // Refer to the following error code } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Data store - Add data using namespace std; using namespace hive; string key = "your data key"; string value = "your data value"; DataStore::set(key, value, [=](ResultAPI const & result)=>{ if (result.isSuccess()) { // success } else { // error handling // Refer to the following error code } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// Data store - Add data val key: String = "your data key" val value: String = "your data value" DataStore.set(key, value, object : DataStore.DataStoreSetListener { override fun onDataStoreSet(result: ResultAPI) { if (result.isSuccess()) { // success } else { // error handling // Refer to the following error code } } }) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// Data store - Add data NSString* key = @"your data key"; NSString* value = @"your data value"; [HIVEDataStore set:key value:value handler:^(HIVEResultAPI* result){ if ([result isSuccess]) { // success } else { // error handling // Refer to the following error code } }]; |
The followings are sample codes to add data of Map formatted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Data store - Add data Dictionary<string, string> map = new Dictionary<string, string> { {"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"} }; DataStore.set(map, (ResultAPI result)=>{ if (result.isSuccess()) { // success } else { // error handling // Refer to the following error code } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Data store - Add data using namespace std; using namespace hive; map<strnig, string> map = { {"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"} }; DataStore::set(map, [=](ResultAPI const & result) { if (result.isSuccess()) { // success } else { // error handling // Refer to the following error code } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// Data store - Add data val map = mapOf( key1 to value1, key2 to value2, key3 to value3, ) DataStore.set(map, object : DataStore.DataStoreSetListener { override fun onDataStoreSet(result: ResultAPI) { if (result.isSuccess()) { // success } else { // error handling // Refer to the following error code } } }) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Data store - Add data NSDictionary<NSString*, NSString*>* map = @{ @"key1" : @"value1", @"key2" : @"value2", @"key3" : @"value3" }; [HIVEDataStore set:map handler:^(HIVEResultAPI* result){ if ([result isSuccess]) { // success } else { // error handling // Refer to the following error code } }]; |
Get Data
There are two ways to get your data one or all at once, and you also can get all user data corresponding to a key you requested. The three ways of getting data are as follows:
-
- Get one of my data
- Get all my data
- Get all data using key
Check out the following sample codes for each way.
The followings are sample codes to get one of my data.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// Data store - Get one of my data string key = "your data key"; DataStore.get(key, (ResultAPI result, string data) => { if (result.isSuccess()) { // success } else { // error handling // Refer to the following error code } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// Data store - Get one of my data using namespace std; using namespace hive; string key = "your data key"; DataStore::get(key, [=](ResultAPI const & result, string data) { if (result.isSuccess()) { // success } else { // error handling // Refer to the following error code } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// Data store - Get one of my data val key: String = "your data key" DataStore.get(key, object : DataStore.DataStoreGetListener { override fun onDataStoreGet(result: ResultAPI, data: String?) { if (result.isSuccess()) { // success } else { // error handling // Refer to the following error code } } }) |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// Data store - Get one of my data NSString* key = @"your data key"; [HIVEDataStore get:key handler:^(HIVEResultAPI* result, NSString* data) { if ([result isSuccess]) { // success } else { // error handling // Refer to the following error code } }]; |
The followings are sample codes to get all my data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// Data store - Get all my data string key = "your data key"; DataStore.getMyData((ResultAPI result, Dictionary<string, string> myData) => { if (result.isSuccess()) { // success // myData : A map formatted a key-value you added } else { // error handling // Refer to the following error code } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Data store - Get all my data using namepace std; using namespace hive; string key = "your data key"; DataStore.getMyData([=](ResultAPI const & result, map<string, string> const & myData) { if (result.isSuccess()) { // success // myData : A map formatted a key-value you added } else { // error handling // Refer to the following error code } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// Data store - Get all my data val key: String = "your data key" DataStore.getMyData(object : DataStore.DataStoreMyDataListener { override fun onDataStoreMyData(result: ResultAPI, myData: Map<String, String>) { if (result.isSuccess()) { // success // myData : A map formatted a key-value you added } else { // error handling // Refer to the following error code } } }) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// Data store - Get all my data NSString* key = @"your data key"; [HIVEDataStore getMyData:^(HIVEResultAPI* result, NSDictionary<NSString*, NSString*>* myData) { if ([result isSuccess]) { // success // myData : A map formatted a key-value you added } else { // error handling // Refer to the following error code } }]; |
The followings are sample codes to get all data using key.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// Data store - Get data of all users matching the key string key = "your data key"; DataStore.getUsersData(key, (ResultAPI result, string key, Dictionary<long, string> usersData) => { if (result.isSuccess()) { // success // key : The key the user entered // usersData : A map formatted . Be aware of the key is a long type. } else { // error handling // Refer to the following error code } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// Data store - Get data of all users matching the key using namespace std; using namespace hive; string key = "your data key"; DataStore::getUsersData(key, [=](ResultAPI const & result, string key, map const & usersData) { if (result.isSuccess()) { // success // key : The key the user entered // usersData : A map formatted . Be aware of the key is a long long type. } else { // error handling // Refer to the following error code } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Data store - Get data of all users matching the key val key: String = "your data key" DataStore.getUsersData(key, object : DataStore.DataStoreUsersDataListener { override fun onDataStoreUsersData(result: ResultAPI, key: String?, usersData: Map<Long, String>) { if (result.isSuccess()) { // success // key : The key the user entered // usersData : A map formatted . Be aware of the key is a long type. } else { // error handling // Refer to the following error code } } }) |
1 2 3 4 5 6 7 8 9 10 11 12 |
// Data store - Get data of all users matching the key NSString* key = @"your data key"; [HIVEDataStore getUsersData:key handler:^(ResultAPI* result, NSString* key, NSDictionary<NSNumber*, NSString*>* usersData) { if ([result isSuccess]) { // success // key : The key the user entered // usersData : A map formatted . Be aware of the key is a NSNumber* type. } else { // error handling // Refer to the following error code } }]; |
Error Code
Error Code | Message | Description |
RESPONSE_FAIL | DataStoreNotExistKey | Not exist the key on the server |
RESPONSE_FAIL | DataStoreNotExistColumn | Not exist Column Family(table) on the server |
DEVELOPER_ERROR | DataStoreNotExistPublicKey | Not exist the puclic key. Need to check the settings on Hive console. |
NEED_INITIALIZE | DataStoreNotInitialized | Not done for SDK setup (AuthV4.setup) |
INVALID_SESSION | DataStoreNeedSignIn | Not signed in. Need to sign in. |
DEVELOPER_ERROR | DataStoreDisabled | Set Data Store to Not Used. Need to check the settings on Hive console. |
RESPONSE_FAIL | DataStoreResponseError | Success connection to the server but error returned. Need to check the error message. |
INVALID_PARAM | DataStoreInvalidParam | Failed to call the set() API because of the invalid parameter |