Skip to content

How to use Data Store

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.

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.

Warning

The key-value needs to be set up in a one-dimensional JSON string that includes a simple string or backslash().

The followings are sample codes to add data of a key-value pair.

API Reference: DataStore .set

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    
         }    
});
#include "HiveDataStore.h"

FString Key = TEXT("your data key");
FString Value = TEXT("your data value");

FHiveDataStore::Set(Key, Value, FHiveDataStoreOnSetDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // API call successful 
        } else {
                // Call failed. See error code below
        }
}));

API Reference: DataStore ::set

#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

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

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

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

#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

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 successfull    
         } else {    
             // Call failed. See error code below    
         }    
});
#include "HiveDataStore.h"

TMap<FString, FString> Data;
Data.Emplace(TEXT("key1"), TEXT("value1"));
Data.Emplace(TEXT("key2"), TEXT("value2"));
Data.Emplace(TEXT("key3"), TEXT("value3"));

FHiveDataStore::Set(Data, FHiveDataStoreOnSetDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // call successfull
        } else {
                // Call failed. See error code below
        }
}));

API Reference: DataStore ::set

#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

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

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

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

#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

using hive;    
    string key = "your data key";    

    DataStore.get(key, (ResultAPI result, string data) => {    
         if (result.isSuccess()) {    
             // call successfull    
         } else {    
             // Call failed. See error code below    
         }    
});
#include "HiveDataStore.h"

FString Key = TEXT("your data key");
FHiveDataStore::Get(Key, FHiveDataStoreOnGetDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FString& Data) {
        if (Result.IsSuccess()) {
                // API call successfull
        } else {
                // Call failed. See error code below
        }
}));

API Reference: DataStore ::get

#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

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

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

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

#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

using hive;    
    DataStore.getMyData((ResultAPI result, Dictionary<string, string> myData) => {    
         if (result.isSuccess()) {    
             // call successfull    
             // myData: the added key-value map    
         } else {    
             // Call failed. See error code below    
         }    
});
#include "HiveDataStore.h"

FHiveDataStore::GetMyData(FHiveDataStoreOnMyDataDelegate::CreateLambda([this](const FHiveResultAPI& Result, const DataStoreData& MyData) {

        if (Result.IsSuccess()) {
                // API  call successfull
                // myData: the added key-value map  
        } else {
                // Call failed. See error code below
        }
}));

API Reference: DataStore .getMyData

#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

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

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

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

#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

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    
         }    
});
#include "HiveDataStore.h"

FString Key = TEXT("your data key");
FHiveDataStore::GetUsersData(Key, FHiveDataStoreOnUsersDataDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FString& Key, const DataStoreUsersData& 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

#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

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

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

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

#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