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.
API Reference: DataStore .set
1 2 3 4 5 6 7 8 9 10 11 12 |
using hive; string key = "your data key"; string value = "your data value"; DataStore.set(key, value, (ResultAPI result) => { if (result.isSuccess()) { // call successful } else { // Call failed. See error code below } }); |
API Reference: DataStore ::set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <HIVE_SDK_Plugin/HIVE_CPP.h> 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()) { // call successful } else { // Call failed. See error code below } }); |
API Reference: DataStore.set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import com.hive.DataStore import com.hive.ResultAPI val key = "your data key" val value = "your data value" DataStore.set(key, value, object : DataStore.DataStoreSetListener { override fun onDataStoreSet(result: ResultAPI) { if (result.isSuccess) { // call successful } else { // Call failed. See error code below } } }) |
API Reference: DataStore.INSTANCE .set
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import com.hive.DataStore; import com.hive.ResultAPI; String key = "your data key"; String value = "your data value"; DataStore.INSTANCE.set(key, value, result -> { if (result.isSuccess()) { // call successful } else { // Call failed. See error code below } }); |
API Reference: DataStoreInterface.set
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import HIVEService let key = "your data key" let value = "your data value" DataStoreInterface.set(key, value: value) { result in if result.isSuccess() { // call successful } else { // Call failed. See error code below } } |
API Reference: HIVEDataStore set
1 2 3 4 5 6 7 8 9 10 11 12 |
#import <HIVEService/HIVEService-Swift.h> NSString *key = @"your data key"; NSString *value = @"your data value"; [HIVEDataStore set: key value: value handler: ^(HIVEResultAPI *result) { if ([result isSuccess]) { // call successful } else { // Call failed. See error code below } }]; |
The followings are sample codes to add data of Map formatted.
API Reference: DataStore .set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
using hive; Dictionary<string, string> map = new Dictionary<string, string> { {"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"} }; DataStore.set(map, (ResultAPI result) => { if (result.isSuccess()) { // call successful } else { // Call failed. See error code below } }); |
API Reference: DataStore ::set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
#include <HIVE_SDK_Plugin/HIVE_CPP.h> using namespace std; using namespace hive; map<string, string> map = { {"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"} }; DataStore::set(map, [=](ResultAPI const & result) { if (result.isSuccess()) { // call successful } else { // Call failed. See error code below } }); |
API Reference: DataStore.set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import com.hive.DataStore import com.hive.ResultAPI 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) { // call successful } else { // Call failed. See error code below } } }) |
API Reference: DataStore.INSTANCE .set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import com.hive.DataStore; import com.hive.ResultAPI; Map<String, String> map = new HashMap<>(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); DataStore.INSTANCE.set(map, result -> { if (result.isSuccess()) { // call successful } else { // Call failed. See error code below } }); |
API Reference: DataStoreInterface.set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import HIVEService let map: [String: String] = [ "key1" : "value1", "key2" : "value2", "key3" : "value3" ] DataStoreInterface.set(map) { result in if result.isSuccess() { // call successful } else { // Call failed. See error code below } } |
API Reference: HIVEDataStore set
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#import <HIVEService/HIVEService-Swift.h> NSDictionary<NSString *, NSString *> *map = @{ @"key1" : @"value1", @"key2" : @"value2", @"key3" : @"value3" }; [HIVEDataStore set: map handler: ^(HIVEResultAPI *result) { if ([result isSuccess]) { // call successful } else { // Call failed. See error code below } }]; |
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.
API Reference: DataStore .get
1 2 3 4 5 6 7 8 9 10 11 |
using hive; string key = "your data key"; DataStore.get(key, (ResultAPI result, string data) => { if (result.isSuccess()) { // call successful } else { // Call failed. See error code below } }); |
API Reference: DataStore ::get
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <HIVE_SDK_Plugin/HIVE_CPP.h> using namespace std; using namespace hive; string key = "your data key"; DataStore::get(key, [=](ResultAPI const & result, string data) { if (result.isSuccess()) { // call successful } else { // Call failed. See error code below } }); |
API Reference: DataStore.get
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import com.hive.DataStore import com.hive.ResultAPI val key = "your data key" DataStore.get(key, object : DataStore.DataStoreGetListener { override fun onDataStoreGet(result: ResultAPI, data: String?) { if (result.isSuccess) { // call successful } else { // Call failed. See error code below } } }) |
API Reference: DataStore.INSTANCE .get
1 2 3 4 5 6 7 8 9 10 11 12 |
import com.hive.DataStore; import com.hive.ResultAPI; String key = "your data key"; DataStore.INSTANCE.get(key, (result, data) -> { if (result.isSuccess()) { // call successful } else { // Call failed. See error code below } }); |
API Reference: DataStoreInterface.get
1 2 3 4 5 6 7 8 9 10 11 |
import HIVEService let key = "your data key" DataStoreInterface.get(key) { result, data in if result.isSuccess() { // call successful } else { // Call failed. See error code below } } |
API Reference: HIVEDataStore get
1 2 3 4 5 6 7 8 9 10 11 |
#import <HIVEService/HIVEService-Swift.h> NSString* key = @"your data key"; [HIVEDataStore get: key handler: ^(HIVEResultAPI *result, NSString *data) { if ([result isSuccess]) { // call successful } else { // Call failed. See error code below } }]; |
The followings are sample codes to get all my data.
API Reference: DataStore .getMyData
1 2 3 4 5 6 7 8 9 10 |
using hive; DataStore.getMyData((ResultAPI result, Dictionary<string, string> myData) => { if (result.isSuccess()) { // call successful // myData: the added key-value map } else { // Call failed. See error code below } }); |
API Reference: DataStore .getMyData
1 2 3 4 5 6 7 8 9 10 11 12 |
#include <HIVE_SDK_Plugin/HIVE_CPP.h> using namespace std; using namespace hive; DataStore.getMyData([=](ResultAPI const & result, map<string, string> const & myData) { if (result.isSuccess()) { // call successful // myData: the added key-value map } else { // Call failed. See error code below } }); |
API Reference: DataStore.getMyData
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import com.hive.DataStore import com.hive.ResultAPI DataStore.getMyData(object : DataStore.DataStoreMyDataListener { override fun onDataStoreMyData(result: ResultAPI, myData: Map<String, String>) { if (result.isSuccess) { // call successful // myData: the added key-value map } else { // Call failed. See error code below } } }) |
API Reference: DataStore.INSTANCE .getMyData
1 2 3 4 5 6 7 8 9 10 11 |
import com.hive.DataStore import com.hive.ResultAPI DataStore.INSTANCE.getMyData((result, myData) -> { if (result.isSuccess()) { // call successful // myData: the added key-value map } else { // Call failed. See error code below } }); |
API Reference: DataStoreInterface .getMyData
1 2 3 4 5 6 7 8 9 10 |
import HIVEService DataStoreInterface.getMyData() { result, myData in if result.isSuccess() { // call successful // myData: the added key-value map } else { // Call failed. See error code below } } |
API Reference: HIVEDataStore getMyData
1 2 3 4 5 6 7 8 9 10 |
#import <HIVEService/HIVEService-Swift.h> [HIVEDataStore getMyData: ^(HIVEResultAPI *result, NSDictionary<NSString *, NSString *> *myData) { if ([result isSuccess]) { // call successful // myData: the added key-value map } else { // Call failed. See error code below } }]; |
The followings are sample codes to get all data using key.
API Reference: DataStore .getUsersData
1 2 3 4 5 6 7 8 9 10 11 12 13 |
using hive; string key = "your data key"; DataStore.getUsersData(key, (ResultAPI result, string key, Dictionary<long, string> usersData) => { if (result.isSuccess()) { // call successful // key: Entered key // usersData: Map in PlayerId-value format. Be careful about the long key type. } else { // Call failed. See error code below } }); |
API Reference: DataStore ::getUsersData
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include <HIVE_SDK_Plugin/HIVE_CPP.h> 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()) { // call successful // key: Entered key // usersData: Map in PlayerId-value format. Be careful that the key is of long long type. } else { // Call failed. See error code below } }); |
API Reference: DataStore.getUsersData
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import com.hive.DataStore import com.hive.ResultAPI val key = "your data key" DataStore.getUsersData(key, object : DataStore.DataStoreUsersDataListener { override fun onDataStoreUsersData(result: ResultAPI, key: String?, usersData: Map<Long, String>) { if (result.isSuccess) { // call successful // key: Entered key // usersData: Map in PlayerId-value format. Be careful about the long type. } else { // Call failed. See error code below } } }) |
API Reference: DataStore.INSTANCE .getUsersData
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import com.hive.DataStore; import com.hive.ResultAPI; String key = "your data key"; DataStore.INSTANCE.getUsersData(key, (result, key1, usersData) -> { if (result.isSuccess()) { // call successful // key: Entered key // usersData: Map in PlayerId-value format. Be careful about the long type. } else { // Call failed. See error code below } }); |
API Reference: DataStoreInterface.getUsersData
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import HIVEService let key = "your data key" DataStoreInterface.getUsersData(key) { result, key, usersData in if result.isSuccess() { // call successful // key: Entered key // usersData: Map in PlayerId-value format. Note that the key is of type Int64. } else { // Call failed. See error code below } } |
API Reference: HIVEDataStore getUsersData
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#import <HIVEService/HIVEService-Swift.h> NSString* key = @"your data key"; [HIVEDataStore getUsersData: key handler: ^(HIVEResultAPI *result, NSString *key, NSDictionary<NSNumber *, NSString *> *usersData) { if ([result isSuccess]) { // success // key: Entered key // usersData: Map in PlayerId-value format. Note that the key is of type NSNumber *. } else { // Call failed. See error code below } }]; |
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 |
RESPONSE_FAIL | DataStoreGameIsBeingInspected | Datastore of the game is under maintenance |
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 |