DataStoreService in NodeJS

Just wondering about this snippet here:


Is this usable, or would I have to basically poll?
image
When I try to use it ^

let DataStoreService = RBX.DataStoreService;
  let DataStore = DataStoreService.GetDataStore('Player_Stats')
  DataStore.OnUpdate("LordMerc", function(obj){
    console.log('got update')
    console.log(obj)
  })

I havenā€™t used this library or looked into it, so I donā€™t know itā€™s API, but public set tells me you should probably be assigning to the OnUpdate key.

const DataStoreService = RBX.DataStoreService;
const DataStore = DataStoreService.GetDataStore("Player_Stats")

DataStore.OnUpdate = (key, oldValue, newValue) => {
    console.dir("Got update", key, oldValue, newValue)
}
3 Likes

Wow! Really cool! It would be really useful for me in discord js, you could just update a value in DataStores with just running a command. Cool feature! :grin:

2 Likes

Iā€™d assume key can be set, unless itā€™s a placeholder for the updated info? Would like to pinpoint the key thats changed if possible.

1 Like

As I said, I donā€™t know the API of this library, having never used it or looked at the code.

Purely based on the screenshot you shared, Iā€™d say the OnUpdate function is called whenever the DataStore you connected to previously is updated.

The OnUpdate property of the DataStore should be assigned a callback function, which takes three parameters: Key, OldValue and NewValue.

What you choose to do with those values once you receive them is up to you. For example, if you wanted to watch for changes in the ā€œLordMercā€ key, your callback function might look like this:

if (key === "LordMerc") {
    console.dir("LordMerc key was updated:", oldValue, newValue)
}

Obviously I am not the best person to ask about this library, but hopefully Iā€™ve deduced it correctly from the screenshot, and hopefully @0x6e7367 (or someone else with experience with the library) will be able to give you a more accurate and correct answer.

2 Likes

Aye, I appreciate the help. I just saw that he included coverage of OnUpdate, albeit I know itā€™s deprecated and not really trustworthy. Wanted to see if thatā€™s the same case even using it outside of roblox.

1 Like

I just had a quick look at the source, and it appears the OnUpdate function is currently unimplemented; however, I would imagine itā€™d poll the DataStore endpoint automatically for you once implemented, and run the callback function you specify, as detailed above.

1 Like

So OnUpdate is a callback to be invoked on UpdateAsync sucess only (As I am only invoking it in .then, I will have one for .catch); it is deprecated but I plan to improve itā€™s performance, it has a private get, because you donā€™t need the callback.

@getsetop DataStore::OnUpdate<public set, private get>(variant<(string, Variant, Variant)> callback);

@RakNetProtocol How would I, for example, show a leaderboard VIA discord using this. An example:

        let DataStoreService = RDS.DataStoreService;
        let DataStore = DataStoreService.GetOrderedDataStore('LBS', 'global');

        let Data = DataStore.GetSortedAsync(false, 10)
        let Data_Pages = Data.GetCurrentPage() --It errors right here saying its not a function.

Also I love this API, its amazing.

anyone can help me with this error?

fss.forEach is not a function
    at setUpFLog (/home/runner/Bot/node_modules/@mfd/rbxdatastoreservice/lib/Tools/FastLogTool.js:263:13)

youā€™re not awaiting GetSortedAsync

A lot of issues will be fixed with the new version:

https://github.com/nikita-petko/RbxDataStoreService/tree/dev/v3