diff --git a/addons/db/XEH_PREP.hpp b/addons/db/XEH_PREP.hpp index 1314a7f..9fcf7dc 100644 --- a/addons/db/XEH_PREP.hpp +++ b/addons/db/XEH_PREP.hpp @@ -3,15 +3,21 @@ PREP(delete); PREP(fetch); PREP(get); PREP(handler); +PREP(hashDelete); +PREP(hashDeleteId); PREP(hashGet); PREP(hashGetAll); PREP(hashGetAllId); +PREP(hashGetId); +PREP(hashRemove); +PREP(hashRemoveId); PREP(hashSet); PREP(hashSetBulk); PREP(hashSetId); PREP(hashSetIdBulk); PREP(init); PREP(listAdd); +PREP(listDelete); PREP(listGet); PREP(listLoad); PREP(listRemove); diff --git a/addons/db/functions/fnc_hashDelete.sqf b/addons/db/functions/fnc_hashDelete.sqf new file mode 100644 index 0000000..ad59fe6 --- /dev/null +++ b/addons/db/functions/fnc_hashDelete.sqf @@ -0,0 +1,31 @@ +#include "..\script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashDelete + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Remove hash table from DB. + * + * Arguments: + * N/A + * + * Return Value: + * N/A + * + * Examples: + * [] call ramdb_db_fnc_hashDelete (Server or Singleplayer Only) + * [] remoteExecCall ["ramdb_db_fnc_hashDelete", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +"ArmaRAMDb" callExtension ["hdel", []]; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashDeleteId.sqf b/addons/db/functions/fnc_hashDeleteId.sqf new file mode 100644 index 0000000..c54752c --- /dev/null +++ b/addons/db/functions/fnc_hashDeleteId.sqf @@ -0,0 +1,39 @@ +#include "..\script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashDeleteId + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Remove hash table from DB. + * + * Arguments: + * 0: Name of stored hash table (default: "") + * + * Return Value: + * N/A + * + * Examples: + * ["myKey"] call ramdb_db_fnc_hashDeleteId (Server or Singleplayer Only) + * ["myKey"] remoteExecCall ["ramdb_db_fnc_hashDeleteId", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]]]; + +diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashDeleteId' Key: '%1'", _key]; + +if (_key == "") exitWith { + diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashDeleteId' Invalid Input for Key '%1'", _key]; +}; + +"ArmaRAMDb" callExtension ["hdelid", [_key]]; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashRemove.sqf b/addons/db/functions/fnc_hashRemove.sqf new file mode 100644 index 0000000..e20683d --- /dev/null +++ b/addons/db/functions/fnc_hashRemove.sqf @@ -0,0 +1,39 @@ +#include "..\script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashRemove + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Remove field from hash stored at key from DB. + * + * Arguments: + * 0: Name of stored hash key field (default: "") + * + * Return Value: + * N/A + * + * Examples: + * ["myField"] call ramdb_db_fnc_hashRemove (Server or Singleplayer Only) + * ["myField"] remoteExecCall ["ramdb_db_fnc_hashRemove", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_keyField", "", [""]]]; + +diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashRemove' KeyField: '%1'", _keyField]; + +if (_keyField == "") exitWith { + diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashRemove' Invalid Input for KeyField '%1'", _keyField]; +}; + +"ArmaRAMDb" callExtension ["hrem", [_keyField]]; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashRemoveId.sqf b/addons/db/functions/fnc_hashRemoveId.sqf new file mode 100644 index 0000000..5780873 --- /dev/null +++ b/addons/db/functions/fnc_hashRemoveId.sqf @@ -0,0 +1,40 @@ +#include "..\script_component.hpp" + +/* + * Function: ramdb_db_fnc_hashRemoveId + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Remove field from hash stored at key from DB. + * + * Arguments: + * 0: Name of stored key with hash (default: "") + * 1: Name of stored hash key field (default: "") + * + * Return Value: + * N/A + * + * Examples: + * ["myKey", "myField"] call ramdb_db_fnc_hashRemoveId (Server or Singleplayer Only) + * ["myKey", "myField"] remoteExecCall ["ramdb_db_fnc_hashRemoveId", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]], ["_keyField", "", [""]]]; + +diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashRemoveId' Key: '%1', KeyField: '%2'", _key, _keyField]; + +if (_key == "" || _keyField == "") exitWith { + diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashRemoveId' Invalid Input for Key '%1' or KeyField '%2'", _key, _keyField]; +}; + +"ArmaRAMDb" callExtension ["hremid", [_key, _keyField]]; \ No newline at end of file diff --git a/addons/db/functions/fnc_hashSet.sqf b/addons/db/functions/fnc_hashSet.sqf index 78c5890..5e4b14f 100644 --- a/addons/db/functions/fnc_hashSet.sqf +++ b/addons/db/functions/fnc_hashSet.sqf @@ -29,7 +29,7 @@ * Public: Yes */ -params [["_keyField", "", [""]], ["_data", [], [[], "", 0, false, objNull, grpNull, createHashMap]]]; +params [["_keyField", "", [""]], ["_data", [], [[]]]]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSet' KeyField: '%1', Data: '%2'", _keyField, _data]; diff --git a/addons/db/functions/fnc_hashSetBulk.sqf b/addons/db/functions/fnc_hashSetBulk.sqf index 704c123..eeefefc 100644 --- a/addons/db/functions/fnc_hashSetBulk.sqf +++ b/addons/db/functions/fnc_hashSetBulk.sqf @@ -22,13 +22,13 @@ * N/A * * Examples: - * ["loadout", [getUnitLoadout player], "position", [getPosASLVisual player]] call ramdb_db_fnc_hashSetBulk (Server or Singleplayer Only) - * ["loadout", [getUnitLoadout player], "position", [getPosASLVisual player]] remoteExecCall ["ramdb_db_fnc_hashSetBulk", 2, false] (Multiplayer Only) + * [["loadout", [getUnitLoadout player], "position", [getPosASLVisual player]]] call ramdb_db_fnc_hashSetBulk (Server or Singleplayer Only) + * [["loadout", [getUnitLoadout player], "position", [getPosASLVisual player]]] remoteExecCall ["ramdb_db_fnc_hashSetBulk", 2, false] (Multiplayer Only) * * Public: Yes */ -params [["_data", [], [[], "", 0, false, objNull, grpNull, createHashMap]]]; +params [["_data", [], [[]]]]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSetBulk' Data: %1", _data]; diff --git a/addons/db/functions/fnc_hashSetId.sqf b/addons/db/functions/fnc_hashSetId.sqf index 0004bbc..11b99d4 100644 --- a/addons/db/functions/fnc_hashSetId.sqf +++ b/addons/db/functions/fnc_hashSetId.sqf @@ -30,7 +30,7 @@ * Public: Yes */ -params [["_key", "", [""]], ["_keyField", "", [""]], ["_data", [], [[], "", 0, false, objNull, grpNull, createHashMap]]]; +params [["_key", "", [""]], ["_keyField", "", [""]], ["_data", [], [[]]]]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSetId' Key: '%1', KeyField: '%2', Data: '%3'", _key, _keyField, _data]; diff --git a/addons/db/functions/fnc_hashSetIdBulk.sqf b/addons/db/functions/fnc_hashSetIdBulk.sqf index db0e54f..9dfde72 100644 --- a/addons/db/functions/fnc_hashSetIdBulk.sqf +++ b/addons/db/functions/fnc_hashSetIdBulk.sqf @@ -22,13 +22,13 @@ * N/A * * Examples: - * [getPlayerUID player, "loadout", [getUnitLoadout player], "position", [getPosASLVisual player]] call ramdb_db_fnc_hashSetIdBulk (Server or Singleplayer Only) - * [getPlayerUID player, "loadout", [getUnitLoadout player], "position", [getPosASLVisual player]] remoteExecCall ["ramdb_db_fnc_hashSetIdBulk", 2, false] (Multiplayer Only) + * [[getPlayerUID player, "loadout", [getUnitLoadout player], "position", [getPosASLVisual player]]] call ramdb_db_fnc_hashSetIdBulk (Server or Singleplayer Only) + * [[getPlayerUID player, "loadout", [getUnitLoadout player], "position", [getPosASLVisual player]]] remoteExecCall ["ramdb_db_fnc_hashSetIdBulk", 2, false] (Multiplayer Only) * * Public: Yes */ -params [["_data", [], [[], "", 0, false, objNull, grpNull, createHashMap]]]; +params [["_data", [], [[]]]]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSetIdBulk' Data: %1", _data]; diff --git a/addons/db/functions/fnc_listAdd.sqf b/addons/db/functions/fnc_listAdd.sqf index 38746a6..f188a66 100644 --- a/addons/db/functions/fnc_listAdd.sqf +++ b/addons/db/functions/fnc_listAdd.sqf @@ -29,7 +29,7 @@ * Public: Yes */ -params [["_key", "", [""]], ["_data", [], [[], "", 0, false, objNull, grpNull, createHashMap]]]; +params [["_key", "", [""]], ["_data", [], [[]]]]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_listAdd' Key: '%1', Data: '%2'", _key, _data]; diff --git a/addons/db/functions/fnc_listDelete.sqf b/addons/db/functions/fnc_listDelete.sqf new file mode 100644 index 0000000..9e85639 --- /dev/null +++ b/addons/db/functions/fnc_listDelete.sqf @@ -0,0 +1,39 @@ +#include "..\script_component.hpp" + +/* + * Function: ramdb_db_fnc_listDelete + * Author: Creedcoder, J.Schmidt + * Edit: 07.15.2024 + * Copyright © 2024 Creedcoder, J.Schmidt, All rights reserved + * + * Do not edit without permission! + * + * This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. + * To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, + * PO Box 1866, Mountain View, CA 94042 + * + * [Description] + * Delete a list from DB. + * + * Arguments: + * 0: Name of stored key (default: "") + * + * Return Value: + * N/A + * + * Examples: + * ["events"] call ramdb_db_fnc_listDelete (Server or Singleplayer Only) + * ["events"] remoteExecCall ["ramdb_db_fnc_listDelete", 2, false] (Multiplayer Only) + * + * Public: Yes + */ + +params [["_key", "", [""]]]; + +diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_listDelete' Key: '%1'", _key]; + +if (_key == "") exitWith { + diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_listDelete' Invalid Input for Key '%1'", _key]; +}; + +"ArmaRAMDb" callExtension ["listdel", [_key]]; \ No newline at end of file diff --git a/addons/db/functions/fnc_listSet.sqf b/addons/db/functions/fnc_listSet.sqf index 342f417..215ef4d 100644 --- a/addons/db/functions/fnc_listSet.sqf +++ b/addons/db/functions/fnc_listSet.sqf @@ -30,7 +30,7 @@ * Public: Yes */ -params [["_key", "", [""]], ["_index", -1, [0]], ["_data", [], [[], "", 0, false, objNull, grpNull, createHashMap]]]; +params [["_key", "", [""]], ["_index", -1, [0]], ["_data", [], [[]]]]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_listSet' Key: '%1', Index: '%2', Data: '%3'", _key, _index, _data]; diff --git a/addons/db/functions/fnc_set.sqf b/addons/db/functions/fnc_set.sqf index 2ca5022..124d4a2 100644 --- a/addons/db/functions/fnc_set.sqf +++ b/addons/db/functions/fnc_set.sqf @@ -29,7 +29,7 @@ * Public: Yes */ -params [["_key", "", [""]], ["_data", "", [[], "", 0, false, objNull, grpNull, createHashMap]]]; +params [["_key", "", [""]], ["_data", "", [[]]]]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_set' Key: '%1', Data: '%2'", _key, _data]; diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..3516d52 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,148 @@ +# ArmaRAMDb Documentation + +This documentation provides details on all functions available in `ArmaRAMDb`. These functions allow you to interact with the in-memory database system for Arma 3. + +## Function Categories + +The functions are categorized by their purpose: + +### Core Functions +- [init](core/init.md) - Initialize the database system +- [handler](core/handler.md) - Handle callbacks from the extension +- [processQueue](core/processQueue.md) - Process queued database operations +- [scheduler](core/scheduler.md) - Schedule database operations +- [addTask](core/addTask.md) - Add a task to the scheduler +- [printAddonName](core/printAddonName.md) - Print the addon name +- [test](core/test.md) - Test the database connection + +### Basic Data Operations +- [get](basic/get.md) - Get a value from the database +- [set](basic/set.md) - Set a value in the database +- [delete](basic/delete.md) - Delete a value from the database +- [save](basic/save.md) - Save the database to disk +- [load](basic/load.md) - Load the database from disk +- [fetch](basic/fetch.md) - Fetch a value from the database + +### Hash Operations +- [hashDelete](hash/hashDelete.md) - Delete a hash +- [hashDeleteId](hash/hashDeleteId.md) - Delete a hash for a specific ID +- [hashGet](hash/hashGet.md) - Get a field from a hash +- [hashGetAll](hash/hashGetAll.md) - Get all fields from a hash +- [hashGetAllId](hash/hashGetAllId.md) - Get all fields from a hash for a specific ID +- [hashGetId](hash/hashGetId.md) - Get a field from a hash for a specific ID +- [hashRemove](hash/hashRemove.md) - Remove a field from a hash +- [hashRemoveId](hash/hashRemoveId.md) - Remove a field from a hash for a specific ID +- [hashSet](hash/hashSet.md) - Set a field in a hash +- [hashSetBulk](hash/hashSetBulk.md) - Set multiple fields in a hash in one operation +- [hashSetId](hash/hashSetId.md) - Set a field in a hash for a specific ID +- [hashSetIdBulk](hash/hashSetIdBulk.md) - Set multiple fields in a hash for a specific ID in one operation + +### List Operations +- [listAdd](list/listAdd.md) - Add an item to a list +- [listDelete](list/listDelete.md) - Delete a list +- [listGet](list/listGet.md) - Get items from a list +- [listLoad](list/listLoad.md) - Load a list from the database +- [listRemove](list/listRemove.md) - Remove an item from a list +- [listSet](list/listSet.md) - Set an item in a list + +## Usage Examples + +### Basic Usage +```sqf +// Initialize the database +[] call ramdb_db_fnc_init; + +// Set a value +["myKey", ["myValue"]] call ramdb_db_fnc_set; + +// Get a value +["myKey", "myFunction"] call ramdb_db_fnc_get; + +// Delete a key +["myKey"] call ramdb_db_fnc_delete; +``` + +### Hash Operations +```sqf +// Set a hash field (context mode) +["myField", [myValue]] call ramdb_db_fnc_hashSet; + +// Get a hash field (context mode) +["myField", "myFunction"] call ramdb_db_fnc_hashGet; + +// Get all hash fields (context mode) +["myFunction"] call ramdb_db_fnc_hashGetAll; + +// Set multiple hash fields (context mode) +[[ + "loadout", [getUnitLoadout player], + "position", [getPosASL player], + "direction", [getDir player], + "stance", [stance player] +]] call ramdb_db_fnc_hashSetBulk; + +// Remove a hash field (context mode) +["myField"] call ramdb_db_fnc_hashRemove; + +// Delete a hash table (context mode) +[] call ramdb_db_fnc_hashDelete; +``` +```sqf +// Set a hash field for specific ID +["myHash", "myField", [myValue]] call ramdb_db_fnc_hashSetId; + +// Get a hash field for specific ID +["myHash", "myField", "myFunction"] call ramdb_db_fnc_hashGetId; + +// Get all hash fields for specific ID +["myHash"] call ramdb_db_fnc_hashGetAllId; + +// Set multiple hash fields for specific ID +[[ + getPlayerUID player, + "loadout", [getUnitLoadout player], + "position", [getPosASL player], + "direction", [getDir player], + "stance", [stance player] +]] call ramdb_db_fnc_hashSetIdBulk; + +// Remove a hash field for specific ID +["myHash", "myField"] call ramdb_db_fnc_hashRemoveId; + +// Delete a hash table for specific ID +["myHash"] call ramdb_db_fnc_hashDeleteId; +``` + +### List Operations +```sqf +// Add an item to a list +["myList", ["myItem"]] call ramdb_db_fnc_listAdd; + +// Set an item from a list +["myList", 0, [myNewValue]] call ramdb_db_fnc_listSet; + +// Get an item from a list +["myList", 0, "myFunction"] call ramdb_db_fnc_listGet; + +// Get items from a list +["myList", "myFunction"] call ramdb_db_fnc_listLoad; + +// Remove an item from a list +["myList", 0] call ramdb_db_fnc_listRemove; + +// Delete a list +["myList"] call ramdb_db_fnc_listDelete; +``` + +## Function Documentation Structure + +Each function documentation includes: +- Function name and purpose +- Parameters +- Return value +- Examples +- Notes and warnings + +## License +This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. +To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons,
PO Box 1866, Mountain View, CA 94042 \ No newline at end of file diff --git a/extension/src/ListStore.cs b/extension/src/ListStore.cs index 39d3f31..0f6d656 100644 --- a/extension/src/ListStore.cs +++ b/extension/src/ListStore.cs @@ -35,6 +35,14 @@ namespace ArmaRAMDb } } + public static async Task ListDeleteAsync(string listName) + { + await Task.Yield(); + bool result = _lists.TryRemove(listName, out _); + + Main.Log($"ListDelete: {listName} - Success: {result}", "debug"); + } + public static async Task ListIndexAsync(string listName, string index, string function, string uniqueId, string entity = null, string call = "false", int bufferSize = Main.ARDB_BUFFERSIZE) { await Task.Yield(); diff --git a/extension/src/Main.cs b/extension/src/Main.cs index 29f949c..d0f84ed 100644 --- a/extension/src/Main.cs +++ b/extension/src/Main.cs @@ -249,7 +249,7 @@ namespace ArmaRAMDb WriteOutput(output, $"[\"{_id}_get\",{args[0]}]"); return 100; case "hdel": - HandleHDelOperation(args, argc); + HandleHDelOperation(); WriteOutput(output, "Async"); return 200; case "hdelid": @@ -295,6 +295,10 @@ namespace ArmaRAMDb HandleListAddOperation(args, argc); WriteOutput(output, "Async"); return 200; + case "listdel": + HandleListDelOperation(args, argc); + WriteOutput(output, "Async"); + return 200; case "listidx": HandleListIdxOperation(_id, args, argc); WriteOutput(output, $"[\"{_id}_listindex\",{args[0]}]"); @@ -401,7 +405,7 @@ namespace ArmaRAMDb } #pragma warning disable IDE0060 // Remove unused parameter - private static void HandleHDelOperation(List args, int argc) + private static void HandleHDelOperation() #pragma warning restore IDE0060 // Remove unused parameter { Task.Run(async () => @@ -602,6 +606,14 @@ namespace ArmaRAMDb }); } + private static void HandleListDelOperation(List args, int argc) + { + Task.Run(async () => + { + await ListStore.ListDeleteAsync(args[0].Trim('"')); + }); + } + #pragma warning disable IDE0060 // Remove unused parameter private static void HandleListRemOperation(List args, int argc) #pragma warning restore IDE0060 // Remove unused parameter