Store
Types
StoreInfo
type
StoreInfo =
{
Name:
string
,
Scope:
string?
}
Table format for a store's info in .GetStore().
unreleasedHandler
Used to determine how to handle an session locked Keep.
INFO
Check LoadMethod for more info.
StoreBase
type
StoreBase =
{
}
MockStore
MockStores are used to mirror the real store, but doesn't save data.
Store
Stores are used to load and save Keeps from a DataStoreService:GetDataStore().
Properties
Mock
Store.Mock:
MockStore
Same as Store but it operates on a fake datastore.
local store = DataKeep.GetStore("TestStore", {}, {}):expect()
local keep = store.Mock:LoadKeep("TestKey"):expect()
keep:Release():await()
-- must be used when done with the keep on live servers
store.Mock:RemoveKeep("TestKey")
validate
Store.validate:
(
{
[
string
]
:
any
}
)
→
true
|
(
false
&
string
)
Used to validate data before saving. Ex. type guards.
store.validate = function(data)
for key, value in data do
local dataTempVersion = dataTemplate[key]
if typeof(data[key]) ~= typeof(dataTempVersion) then
return false, `Invalid type for key: {key}`
end
end
return true
end
Functions
Identify
Store:
Identify
(
) →
string
Returns the string identifier for the Store.
LoadKeep
Loads a Keep from the store and returns a Keep object.
store:LoadKeep(`Player_{player.UserId}`, function()
return DataKeep.Enums.LoadMethod.ForceLoad
end)):andThen(function(keep)
print(`Loaded {keep:Identify()}!`)
end):catch(function()
player:Kick("Data failed to load")
end)
INFO
Keeps are cached, that way you can call :LoadKeep() multiple times and get the same Keeps.
ViewKeep
Loads a Keep from the store and returns a Keep object, but doesn't save it.
View-only Keeps have the same functions as normal Keeps, but cannot operate on data.
store:ViewKeep(`Player_{player.UserId}`):andThen(function(viewOnlyKeep)
print(`Viewing {viewOnlyKeep:Identify()}!`)
end):catch(function(err)
warn(`Something went wrong! {err}`)
end)
DANGER
View-only Keeps are not cached!
DANGER
Keep:Destroy() must be called when view-only Keep is not needed anymore.
RemoveKeep
Removes the key
from the DataStore.
INFO
Calling :RemoveKeep()
on the loaded Keep will release it (.Releasing signal will be fired) before removing.
WARNING
In live servers :RemoveKeep()
must be used on Keeps created through mock stores.
PreLoad
Store:
PreLoad
(
callback:
(
{
[
string
]
:
any
}
)
→
{
[
string
]
:
any
}
) →
(
)
Runs before loading a Keep, allowing you to modify the data before, like decompressing compressed data.
Decompression example:
store:PreLoad(function(data)
local newData = {}
for key, value in data do
newData[key] = HttpService:JSONDecode(value)
end
return newData
end)
WARNING
Callback must return a new data table.
DANGER
:PreLoad()
can only be set once.
PreSave
Store:
PreSave
(
callback:
(
{
[
string
]
:
any
}
)
→
{
[
string
]
:
any
}
) →
(
)
Runs before saving a Keep, allowing you to modify the data before, like compressing data.
Compression example:
store:PreSave(function(data)
local newData = {}
for key, value in data do
newData[key] = HttpService:JSONEncode(value)
end
return newData
end)
WARNING
Callback must return a new data table.
DANGER
:PreSave()
can only be set once.
PostGlobalUpdate
Posts a global update to a Keep.
store:PostGlobalUpdate(`Player_{player.UserId}`, function(globalUpdates)
globalUpdates:AddGlobalUpdate({
Hello = "World!",
}):andThen(function(updateId)
print("Added Global Update!")
end)
end)
INFO
Check GlobalUpdates for more info.
DANGER
Yielding inside updateHandler
is not allowed.