Database struct is the main entry point for interacting with jasonisnthappy. It manages connections, transactions, collections, and metadata.
Opening a database
Database::open
Open a database at the specified path with default options.
Path to the database file
Result<Database> - The opened database instance
Example:
Database::open_with_options
Open a database with custom configuration options.
Path to the database file
Configuration options for the database
DatabaseOptions
Configuration options for opening a database.Number of pages to cache in memory (1 page = ~4KB)
Automatically checkpoint when WAL reaches this many frames
Unix file permissions for database files (Unix only)
Open database in read-only mode
Maximum number of documents in bulk operations
Maximum size of a single document in bytes (64MB)
Maximum HTTP request body size for web server (50MB)
Collection operations
collection
Get a handle to a collection.
Name of the collection
Collection - A collection handle
Example:
list_collections
List all collections in the database.
Result<Vec<String>> - Sorted list of collection names
Example:
collection_stats
Get detailed statistics for a specific collection.
Name of the collection
Result<CollectionInfo> - Collection statistics
Example:
Transaction management
begin
Begin a new transaction.
Result<Transaction> - A new transaction
Example:
run_transaction
Execute a function within a transaction with automatic retry on conflicts.
Function to execute within the transaction
Result<R> - The result from the transaction function
Example:
Index management
create_index
Create a single-field index on a collection.
Name of the collection
Name for the index
Field to index
Whether to enforce uniqueness
create_compound_index
Create a compound index on multiple fields.
Name of the collection
Name for the index
Ordered list of fields to include in the compound index
Whether to enforce uniqueness on the combination of field values
create_text_index
Create a text index for full-text search.
Name of the collection
Name for the text index
List of text fields to index for search
drop_index
Drop an index from a collection.
Name of the collection
Name of the index to drop
list_indexes
List all indexes for a specific collection.
Name of the collection
Result<Vec<IndexInfo>> - List of index information
Schema validation
set_schema
Set a validation schema for a collection.
Name of the collection
The schema to apply
get_schema
Get the validation schema for a collection.
Name of the collection
Option<Schema> - The schema if set, or None
remove_schema
Remove the validation schema from a collection.
Name of the collection
Database maintenance
checkpoint
Manually trigger a WAL checkpoint.
garbage_collect
Remove old document versions that are no longer needed.
Result<GarbageCollectionStats> - Statistics about the garbage collection
Example:
backup
Create a backup of the database.
Destination path for the backup file
verify_backup
Verify a backup file by checking its integrity.
Path to the backup file to verify
Result<BackupInfo> - Backup information if valid
Example:
close
Close the database connection.
Database information
info
Get comprehensive database information.
Result<DatabaseInfo> - Detailed database statistics
Example:
metrics
Get a snapshot of current database metrics.
MetricsSnapshot - Current metrics
Example:
path
Get the database file path.
&str - The database file path
is_read_only
Check if the database is in read-only mode.
bool - true if read-only, false otherwise
Configuration
set_transaction_config
Set transaction retry configuration.
Transaction configuration
set_auto_checkpoint_threshold
Set the auto-checkpoint threshold.
Number of WAL frames before auto-checkpoint