DocumentStore
Represents a collection of Documents, analagous to a DataStore.
warning
Multiple DocumentStores can be created for the same DataStore. You should avoid this, as they will return different Document objects in different sessions. If you need to access the same DocumentStore in multiple scripts, create a module and require that module. Do not use DocumentService with Actors or Parallel Luau.
Functions
new
Types
interface
DocumentStoreProps {
check:
(
unknown
)
→
(
boolean
,
T
)
--
A type check function for your data, errors if types are invalid
default:
T
&
{
}
--
Default values, which are set if keys are empty
lockSessions:
boolean
--
Should the documents be session locked?
bindToClose:
boolean?
--
Should the DocumentStore close all documents on BindToClose? [default=true] (This should always be true in production)
}
Creates a new DocumentStore.
warning
This should only be called once per server for each DataStore in a live game. If there are multiple instances of a DocumentStore for one key, any Documents will be treated as if they are from different sessions. This is useful for unit testing but can lead to weird bugs in production. DocumentStores should persist through an entire server's lifespan and are not garbage collected.
GetDocument
DocumentStore.
GetDocument
(
key:
string
) →
(
boolean
--
whether a new document was created
)
Gets the document for the key given, or creates one if it does not exist.
info
Documents are cached in a weak table, so once they are closed, they will be marked for garbage collection if you have no references to them. Be careful of references created by closures.
Documents that are not session locked will be garbage collected once there are no other references to them.
CloseAllDocuments
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. YieldsCloses all open documents as fast as possible. This runs on BindToClose already.
Will also wait for any documents that are opening to open, and then close them.
warning
Yields until all documents are closed. If there is a systematic error in your :Close, for example a hook errors, this could infinitely yield.
Closes documents asynchronously when request budget allows, and yields all open documents are closed.
isDocumentStore
DocumentStore.
isDocumentStore
(
instance:
metatable
) →
boolean
Checks if a metatable passed is a DocumentStore.