feat: Added list deletion functionality and improved parameter handling
All checks were successful
Build / Build (push) Successful in 30s

This commit introduces the ability to delete lists within the ArmaRAMDb extension.  It also refactors the parameter handling in several sqf functions to improve consistency and remove unnecessary data structures.

Specifically, the following changes were made:

*   **Extension (C#):**
    *   Added `ListDeleteAsync` to `ListStore.cs` to handle list deletion.
    *   Added a "listdel" case to `Main.cs` to call the new `HandleListDelOperation` function.
    *   Created `HandleListDelOperation` to call `ListStore.ListDeleteAsync`.
    *   Removed unused parameters from `HandleHDelOperation`.
*   **SQF Functions:**
    *   Updated `fnc_hashSetIdBulk.sqf`, `fnc_hashSetBulk.sqf`, `fnc_hashSetId.sqf`, `fnc_listSet.sqf`, `fnc_hashSet.sqf`, `fnc_listAdd.sqf`, and `fnc_set.sqf` to use a simpler parameter structure.  Specifically, the `_data` parameter is now expected to be a simple array instead of an array containing a default value.
*   **XEH_PREP.hpp:**
    *   Added a few new functions to register.
*   **Examples:**
    *   Updated examples in `fnc_hashSetIdBulk.sqf` and `fnc_hashSetBulk.sqf` to reflect the parameter changes.

This change enhances the functionality of ArmaRAMDb by providing a mechanism to remove lists and improves the overall code quality and consistency.
This commit is contained in:
Jacob Schmidt 2025-03-22 12:55:09 -05:00
parent 3490bbf901
commit 3bb2bec8d9
16 changed files with 375 additions and 13 deletions

View File

@ -3,15 +3,21 @@ PREP(delete);
PREP(fetch); PREP(fetch);
PREP(get); PREP(get);
PREP(handler); PREP(handler);
PREP(hashDelete);
PREP(hashDeleteId);
PREP(hashGet); PREP(hashGet);
PREP(hashGetAll); PREP(hashGetAll);
PREP(hashGetAllId); PREP(hashGetAllId);
PREP(hashGetId);
PREP(hashRemove);
PREP(hashRemoveId);
PREP(hashSet); PREP(hashSet);
PREP(hashSetBulk); PREP(hashSetBulk);
PREP(hashSetId); PREP(hashSetId);
PREP(hashSetIdBulk); PREP(hashSetIdBulk);
PREP(init); PREP(init);
PREP(listAdd); PREP(listAdd);
PREP(listDelete);
PREP(listGet); PREP(listGet);
PREP(listLoad); PREP(listLoad);
PREP(listRemove); PREP(listRemove);

View File

@ -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", []];

View File

@ -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 <STRING> (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]];

View File

@ -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 <STRING> (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]];

View File

@ -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 <STRING> (default: "")
* 1: Name of stored hash key field <STRING> (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]];

View File

@ -29,7 +29,7 @@
* Public: Yes * 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]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSet' KeyField: '%1', Data: '%2'", _keyField, _data];

View File

@ -22,13 +22,13 @@
* N/A * N/A
* *
* Examples: * Examples:
* ["loadout", [getUnitLoadout player], "position", [getPosASLVisual player]] call ramdb_db_fnc_hashSetBulk (Server or Singleplayer 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) * [["loadout", [getUnitLoadout player], "position", [getPosASLVisual player]]] remoteExecCall ["ramdb_db_fnc_hashSetBulk", 2, false] (Multiplayer Only)
* *
* Public: Yes * Public: Yes
*/ */
params [["_data", [], [[], "", 0, false, objNull, grpNull, createHashMap]]]; params [["_data", [], [[]]]];
diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSetBulk' Data: %1", _data]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSetBulk' Data: %1", _data];

View File

@ -30,7 +30,7 @@
* Public: Yes * 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]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSetId' Key: '%1', KeyField: '%2', Data: '%3'", _key, _keyField, _data];

View File

@ -22,13 +22,13 @@
* N/A * N/A
* *
* Examples: * 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]]] 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]]] remoteExecCall ["ramdb_db_fnc_hashSetIdBulk", 2, false] (Multiplayer Only)
* *
* Public: Yes * Public: Yes
*/ */
params [["_data", [], [[], "", 0, false, objNull, grpNull, createHashMap]]]; params [["_data", [], [[]]]];
diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSetIdBulk' Data: %1", _data]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_hashSetIdBulk' Data: %1", _data];

View File

@ -29,7 +29,7 @@
* Public: Yes * 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]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_listAdd' Key: '%1', Data: '%2'", _key, _data];

View File

@ -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 <STRING> (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]];

View File

@ -30,7 +30,7 @@
* Public: Yes * 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]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_listSet' Key: '%1', Index: '%2', Data: '%3'", _key, _index, _data];

View File

@ -29,7 +29,7 @@
* Public: Yes * 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]; diag_log text format ["ArmaRAMDb: 'ramdb_db_fnc_set' Key: '%1', Data: '%2'", _key, _data];

148
docs/README.md Normal file
View File

@ -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, <br>PO Box 1866, Mountain View, CA 94042

View File

@ -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) 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(); await Task.Yield();

View File

@ -249,7 +249,7 @@ namespace ArmaRAMDb
WriteOutput(output, $"[\"{_id}_get\",{args[0]}]"); WriteOutput(output, $"[\"{_id}_get\",{args[0]}]");
return 100; return 100;
case "hdel": case "hdel":
HandleHDelOperation(args, argc); HandleHDelOperation();
WriteOutput(output, "Async"); WriteOutput(output, "Async");
return 200; return 200;
case "hdelid": case "hdelid":
@ -295,6 +295,10 @@ namespace ArmaRAMDb
HandleListAddOperation(args, argc); HandleListAddOperation(args, argc);
WriteOutput(output, "Async"); WriteOutput(output, "Async");
return 200; return 200;
case "listdel":
HandleListDelOperation(args, argc);
WriteOutput(output, "Async");
return 200;
case "listidx": case "listidx":
HandleListIdxOperation(_id, args, argc); HandleListIdxOperation(_id, args, argc);
WriteOutput(output, $"[\"{_id}_listindex\",{args[0]}]"); WriteOutput(output, $"[\"{_id}_listindex\",{args[0]}]");
@ -401,7 +405,7 @@ namespace ArmaRAMDb
} }
#pragma warning disable IDE0060 // Remove unused parameter #pragma warning disable IDE0060 // Remove unused parameter
private static void HandleHDelOperation(List<string> args, int argc) private static void HandleHDelOperation()
#pragma warning restore IDE0060 // Remove unused parameter #pragma warning restore IDE0060 // Remove unused parameter
{ {
Task.Run(async () => Task.Run(async () =>
@ -602,6 +606,14 @@ namespace ArmaRAMDb
}); });
} }
private static void HandleListDelOperation(List<string> args, int argc)
{
Task.Run(async () =>
{
await ListStore.ListDeleteAsync(args[0].Trim('"'));
});
}
#pragma warning disable IDE0060 // Remove unused parameter #pragma warning disable IDE0060 // Remove unused parameter
private static void HandleListRemOperation(List<string> args, int argc) private static void HandleListRemOperation(List<string> args, int argc)
#pragma warning restore IDE0060 // Remove unused parameter #pragma warning restore IDE0060 // Remove unused parameter