load_table
Function: load_table
load_table
The load_table
function is designed to load all records stored in a specific table file into memory. This allows subsequent operations to work on the table's data effectively without directly accessing the .table
file repeatedly.
Declaration
Parameters
table
(std::string
) The name of the table to be loaded. The function looks for a file named<table>.table
in the database directory.
Return Value
operation
An object containing:stat
: Indicates whether the operation wasSUCCESS
orFAILED
.error
: A message describing the error in case the operation fails.
Functionality
Checks if the Database is Open The function validates whether the database is currently open. If not, it returns a failure status with the error message
"Database not open"
.Validates Table Existence It checks if the specified table file (
<table>.table
) exists in the database directory. If not, the operation fails with the error message"Table does not exist"
.Parses the Table's Schema The function retrieves the schema (column names and their data types) of the table by reading its header using
get_table_content_header
.Reads and Loads Records The function processes the table file to identify and parse each record. Records are enclosed within square brackets (
[ ... ]
), and individual fields are extracted based on the schema.Decompresses Strings For columns of type
STRING
, the function decompresses the stored values to retrieve their original form.Stores Records in Memory Each parsed record is added to the in-memory representation of the table (
std::vector<std::unordered_map<std::string, std::any>>
).
Example
Here’s how to use the load_table
function:
Last updated