Skip to main content

DataStoreStage

This item only works when running on the server. Server

Provides a data storage facility with an ability to get sub-stores. So you can write directly to this store, overwriting all children, or you can have more partial control at children level. This minimizes accidently overwriting. The big cost here is that we may leave keys that can't be removed.

Layers in priority order:

  1. Save data
  2. Substores
  3. Base layer

Functions​

new​

DataStoreStage.new(
loadName: string,
loadParent: DataStoreStage?
) → DataStoreStage

Constructs a new DataStoreStage to load from. Prefer to use DataStore because this doesn't have any way to retrieve this.

See DataStore, GameDataStoreService, and PlayerDataStoreService.

-- Data store inherits from DataStoreStage
local dataStore = serviceBag:GetService(PlayerDataStoreService):PromiseDataStore(player):Yield()

Store​

DataStoreStage.Store(
key: string,
value: any
) → ()

Stores the value, firing off events and queuing the item for save.

dataStore:Store("money", 25)

Load​

DataStoreStage.Load(
key: DataStoreStageKey?,
defaultValue: T?
) → Promise<T>

Loads the data at the key and returns a promise with that value

dataStore:Load():Then(function(data)
	print(data)
end)

LoadAll​

DataStoreStage.LoadAll(
defaultValue: any
) → Promise<any>

Promises the full content for the datastore

dataStore:LoadAll():Then(function(data)
	print(data)
end)

GetSubStore​

DataStoreStage.GetSubStore(
key: DataStoreStageKey
) → DataStoreStage

Gets a sub-datastore that will write at the given key. This will have the same helper methods as any other data store object.

local dataStore = DataStore.new()

local saveslot = dataStore:GetSubStore("saveslot0")
saveslot:Store("Money", 0)

Delete​

DataStoreStage.Delete(
key: DataStoreStageKey
) → ()

Explicitely deletes data at the key

Wipe​

DataStoreStage.Wipe(self: DataStoreStage) → ()

Queues up a wipe of all values. This will completely set the data to nil.

Observe​

DataStoreStage.Observe(
key: DataStoreStageKey?,
defaultValue: T?
) → Observable<T>

Observes the current value for the stage itself

If no key is passed than it will observe the whole view snapshot

AddSavingCallback​

DataStoreStage.AddSavingCallback(
callback: function--

May return a promise

) → () → ()--

Call to remove

Adds a callback to be called before save. This may return a promise.

RemoveSavingCallback​

DataStoreStage.RemoveSavingCallback(
callback: function
) → ()

Removes a saving callback from the data store stage

GetTopLevelDataStoredSignal​

DataStoreStage.GetTopLevelDataStoredSignal(self: DataStoreStage) → Signal

Gets an event that will fire off whenever something is stored at this level

GetFullPath​

DataStoreStage.GetFullPath(self: DataStoreStage) → string

Retrieves the full path of this datastore stage for diagnostic purposes.

PromiseKeyList​

DataStoreStage.PromiseKeyList(self: DataStoreStage) → Promise<{string}>

Promises a list of keys in the data store stage

PromiseKeySet​

DataStoreStage.PromiseKeySet(self: DataStoreStage) → Promise<{[string]: true}>

Promises a set of keys in the data store stage

MergeDiffSnapshot​

DataStoreStage.MergeDiffSnapshot(
diffSnapshot: any
) → ()

This will always prioritize our own view of the world over incoming data.

TIP

This is a helper method that helps load diff data into the data store.

MarkDataAsSaved​

DataStoreStage.MarkDataAsSaved(
parentWriter: DataStoreWriter
) → ()

Updates the base data to the saved / written data.

This will always prioritize our own view of the world over incoming data.

PromiseViewUpToDate​

DataStoreStage.PromiseViewUpToDate(self: DataStoreStage) → Promise

Helper method that promises the latest data view.

TIP

This is a helper method. You probably want DataStoreStage.LoadAll instead.

Overwrite​

DataStoreStage.Overwrite(
data: any
) → ()

Overwrites the full stage with the data specified.

TIP

Use this method carefully as it can lead to data loss in ways that a specific :Store() call on the right stage would do better.

OverwriteMerge​

DataStoreStage.OverwriteMerge(
data: any
) → ()

Ovewrites the full stage with the data specified. However, it will merge the data to help prevent data-loss.

TIP

Use this method carefully as it can lead to data loss in ways that a specific :Store() call on the right stage would do better.

StoreOnValueChange​

DataStoreStage.StoreOnValueChange(
name: string | number,
valueObj: Instance--

ValueBase object to store on

) → MaidTask--

Cleanup to remove this writer and free the key.

Whenever the ValueObject changes, stores the resulting value in that entry.

HasWritableData​

DataStoreStage.HasWritableData(self: DataStoreStage) → boolean

If there is data not yet written then this will return true

GetNewWriter​

DataStoreStage.GetNewWriter(self: DataStoreStage) → DataStoreWriter

Constructs a writer which provides a snapshot of the current data state to write.

TIP

This is automatically invoked during saving and is public so DataStore can invoke it.

PromiseInvokeSavingCallbacks​

DataStoreStage.PromiseInvokeSavingCallbacks(self: DataStoreStage) → Promise

Invokes all saving callbacks

TIP

This is automatically invoked before saving and is public so DataStore can invoke it.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Constructs a new DataStoreStage to load from. Prefer to use DataStore because this doesn't\nhave any way to retrieve this.\n\nSee [DataStore], [GameDataStoreService], and [PlayerDataStoreService].\n\n```lua\n-- Data store inherits from DataStoreStage\nlocal dataStore = serviceBag:GetService(PlayerDataStoreService):PromiseDataStore(player):Yield()\n```",
            "params": [
                {
                    "name": "loadName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "loadParent",
                    "desc": "",
                    "lua_type": "DataStoreStage?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "DataStoreStage"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 79,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "Store",
            "desc": "Stores the value, firing off events and queuing the item for save.\n\n```lua\ndataStore:Store(\"money\", 25)\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "key",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 114,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "Load",
            "desc": "Loads the data at the `key` and returns a promise with that value\n\n```lua\ndataStore:Load():Then(function(data)\n\tprint(data)\nend)\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "key",
                    "desc": "",
                    "lua_type": "DataStoreStageKey?"
                },
                {
                    "name": "defaultValue",
                    "desc": "",
                    "lua_type": "T?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 144,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "LoadAll",
            "desc": "Promises the full content for the datastore\n\n```lua\ndataStore:LoadAll():Then(function(data)\n\tprint(data)\nend)\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "defaultValue",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<any>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 177,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "GetSubStore",
            "desc": "Gets a sub-datastore that will write at the given key. This will have the same\nhelper methods as any other data store object.\n\n```lua\nlocal dataStore = DataStore.new()\n\nlocal saveslot = dataStore:GetSubStore(\"saveslot0\")\nsaveslot:Store(\"Money\", 0)\n```",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "key",
                    "desc": "",
                    "lua_type": "DataStoreStageKey"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "DataStoreStage"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 201,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "Delete",
            "desc": "Explicitely deletes data at the key",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "key",
                    "desc": "",
                    "lua_type": "DataStoreStageKey"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 256,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "Wipe",
            "desc": "Queues up a wipe of all values. This will completely set the data to nil.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 265,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "Observe",
            "desc": "Observes the current value for the stage itself\n\nIf no key is passed than it will observe the whole view snapshot",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "key",
                    "desc": "",
                    "lua_type": "DataStoreStageKey?"
                },
                {
                    "name": "defaultValue",
                    "desc": "",
                    "lua_type": "T?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 278,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "AddSavingCallback",
            "desc": "Adds a callback to be called before save. This may return a promise.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "callback",
                    "desc": "May return a promise",
                    "lua_type": "function"
                }
            ],
            "returns": [
                {
                    "desc": "Call to remove",
                    "lua_type": "() -> ()"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 339,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "RemoveSavingCallback",
            "desc": "Removes a saving callback from the data store stage",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "callback",
                    "desc": "",
                    "lua_type": "function"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 355,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "GetTopLevelDataStoredSignal",
            "desc": "Gets an event that will fire off whenever something is stored at this level",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Signal"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 369,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "GetFullPath",
            "desc": "Retrieves the full path of this datastore stage for diagnostic purposes.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 378,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "PromiseKeyList",
            "desc": "Promises a list of keys in the data store stage",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<{ string }>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 397,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "PromiseKeySet",
            "desc": "Promises a set of keys in the data store stage",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<{ [string]: true }>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 412,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "MergeDiffSnapshot",
            "desc": "This will always prioritize our own view of the world over\nincoming data.\n\n:::tip\nThis is a helper method that helps load diff data into the data store.\n:::",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "diffSnapshot",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 432,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "MarkDataAsSaved",
            "desc": "Updates the base data to the saved / written data.\n\nThis will always prioritize our own view of the world over\nincoming data.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "parentWriter",
                    "desc": "",
                    "lua_type": "DataStoreWriter"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 449,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "PromiseViewUpToDate",
            "desc": "Helper method that promises the latest data view.\n\n:::tip\nThis is a helper method. You probably want [DataStoreStage.LoadAll] instead.\n:::",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 519,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "Overwrite",
            "desc": "Overwrites the full stage with the data specified.\n\n:::tip\nUse this method carefully as it can lead to data loss in ways that a specific :Store() call\non the right stage would do better.\n:::",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "data",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 540,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "OverwriteMerge",
            "desc": "Ovewrites the full stage with the data specified. However, it will merge the data\nto help prevent data-loss.\n\n:::tip\nUse this method carefully as it can lead to data loss in ways that a specific :Store() call\non the right stage would do better.\n:::",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "data",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 593,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "StoreOnValueChange",
            "desc": "Whenever the ValueObject changes, stores the resulting value in that entry.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                },
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string | number"
                },
                {
                    "name": "valueObj",
                    "desc": "ValueBase object to store on",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "Cleanup to remove this writer and free the key.",
                    "lua_type": "MaidTask"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 615,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "HasWritableData",
            "desc": "If there is data not yet written then this will return true",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 645,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "GetNewWriter",
            "desc": "Constructs a writer which provides a snapshot of the current data state to write.\n\n:::tip\nThis is automatically invoked during saving and is public so [DataStore] can invoke it.\n:::",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "DataStoreWriter"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 673,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        },
        {
            "name": "PromiseInvokeSavingCallbacks",
            "desc": "Invokes all saving callbacks\n\n:::tip\nThis is automatically invoked before saving and is public so [DataStore] can invoke it.\n:::",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "DataStoreStage"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 709,
                "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "DataStoreStage",
    "desc": "Provides a data storage facility with an ability to get sub-stores. So you can write\ndirectly to this store, overwriting all children, or you can have more partial control\nat children level. This minimizes accidently overwriting.\nThe big cost here is that we may leave keys that can't be removed.\n\nLayers in priority order:\n\n1. Save data\n2. Substores\n3. Base layer",
    "realm": [
        "Server"
    ],
    "source": {
        "line": 17,
        "path": "src/datastore/src/Server/Modules/DataStoreStage.lua"
    }
}