-
Notifications
You must be signed in to change notification settings - Fork 0
Sys Data
h1. Sys data
Provides a data handler object to persist module state to an external database.
h2. Creating a data handler for your module
GVAR(datahandler) = [nil, "create"] call ALIVE_fnc_Data; [GVAR(datahandler),"storeType",true] call ALIVE_fnc_Data;
storeType = use this if you will be restoring data and need to convert from string to SQF variable. Essentially stores the variable type to the data dictionary. Set to true by default.
h2. Writing a single document/record to the database
Writing to DB should occur when the server is disconnecting, unless live data is required in the DB (then ensure you set async to true).
_async = false; // Wait for response from server _recordID = format["%1_%2", ALIVE_sys_data_GROUP_ID, missionName]; // Example - id needs to be unique within your module records _result = [GVAR(datahandler), "write", ["YOUR_MODULE_NAME",YOUR_CBA_HASH, _async, _recordID] ] call ALIVE_fnc_Data;
If are writing data that was previously restored, ensure you maintain the _rev value returned within the data restored. This is required if you are updating/appending a record.
returns a string of the result (contains "error" if there is an issue)
h2. Writing multiple documents/records to the database
For when multiple records/documents are held within a single hash (i.e. hashes within a hash)
_missionName = format["%1_%2", ALIVE_sys_data_GROUP_ID, missionName]; // must include group_id to ensure mission reference is unique across groups _result = [GVAR(datahandler), "save", ["YOUR_MODULE_NAME",YOUR_CBA_HASH, _missionName, _async]] call ALIVE_fnc_Data;
Each "document/record" (CBA_HASH) within YOUR_CBA_HASH should have a unique key.
returns a string of the result (contains "error" if there is an issue)
h2. Reading a single document/record from the database
Reading should occur during module init.
_response = [GVAR(datahandler), "read", ["YOUR_MODULE_NAME", [], _recordID]] call ALIVE_fnc_Data;
returns a CBA_HASH if successful, string "ERROR" if not.
h2. Reading multiple documents/records from the database
Reading should occur during module init. Async should be set to false.
_result = [GVAR(datahandler), "load", ["YOUR_MODULE_NAME", _missionName, _async]] call ALIVE_fnc_Data;
returns a CBA_HASH, string "ERROR" if not.
h2. Examples