Xbase.MemoHandler (Xbase v0.1.0)
View SourceHandles coordinated operations between DBF and DBT files for memo field support.
Provides high-level API for seamless memo content handling in record operations, automatic file discovery, and transaction safety across both file types.
Summary
Functions
Appends a record with automatic memo content handling.
Closes both DBF and DBT files properly.
Creates a new DBF file with memo support and coordinated DBT file.
Executes a function with transaction safety across both DBF and DBT files.
Opens a DBF file with automatic memo file discovery and coordination.
Reads a record with automatic memo content resolution.
Updates a record with automatic memo content handling.
Types
@type t() :: %Xbase.MemoHandler{ dbf: map(), dbf_path: String.t(), dbt: Xbase.Types.DbtFile.t() | nil, dbt_path: String.t() | nil, memo_mode: :auto | :required | :disabled }
Functions
Appends a record with automatic memo content handling.
Parameters
handler
- MemoHandler structurerecord_data
- Map of field names to values, where memo fields contain content strings
Returns
{:ok, updated_handler}
- Successfully appended record with memo content{:error, reason}
- Error appending record
Example
record_data = %{
"NAME" => "John Doe",
"NOTES" => "This memo content will be automatically stored in the DBT file"
}
{:ok, updated_handler} = MemoHandler.append_record_with_memo(handler, record_data)
Closes both DBF and DBT files properly.
Parameters
handler
- MemoHandler structure
Returns
:ok
- Files closed successfully
Creates a new DBF file with memo support and coordinated DBT file.
Parameters
dbf_path
- Path for the new DBF filefields
- Field definitions for the DBF fileopts
- Options for file creation:version
- DBF version (automatically set to memo-capable if memo fields present):dbt_path
- Explicit DBT file path (defaults to replacing .dbf with .dbt):block_size
- DBT block size (default: 512)
Returns
{:ok, MemoHandler.t()}
- Successfully created coordinated files{:error, reason}
- Error creating files
Executes a function with transaction safety across both DBF and DBT files.
Parameters
handler
- MemoHandler structuretransaction_fn
- Function to execute with the handler
Returns
{:ok, {result, updated_handler}}
- Transaction successful{:error, reason}
- Transaction failed, changes rolled back
Opens a DBF file with automatic memo file discovery and coordination.
Parameters
dbf_path
- Path to the DBF filemodes
- File access modes (default: [:read])opts
- Options for memo handling:memo
- Memo mode (:auto, :required, :disabled):dbt_path
- Explicit DBT file path (overrides auto-discovery)
Returns
{:ok, MemoHandler.t()}
- Successfully opened coordinated files{:error, reason}
- Error opening files
Examples
# Automatic memo file discovery
{:ok, handler} = MemoHandler.open_dbf_with_memo("data.dbf")
# Read-write mode with required memo support
{:ok, handler} = MemoHandler.open_dbf_with_memo("data.dbf", [:read, :write], memo: :required)
# Explicit DBT file path
{:ok, handler} = MemoHandler.open_dbf_with_memo("data.dbf", [], dbt_path: "memos.dbt")
Reads a record with automatic memo content resolution.
Parameters
handler
- MemoHandler structurerecord_index
- Zero-based record index to read
Returns
{:ok, record_data}
- Record data with memo content resolved{:error, reason}
- Error reading record
Updates a record with automatic memo content handling.
Parameters
handler
- MemoHandler structurerecord_index
- Zero-based record index to updaterecord_data
- Map of field names to values for update
Returns
{:ok, updated_handler}
- Successfully updated record with memo content{:error, reason}
- Error updating record