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.
&str
required
Path to the database file
Result<Database> - The opened database instance
Example:
Database::open_with_options
Open a database with custom configuration options.
&str
required
Path to the database file
DatabaseOptions
required
Configuration options for the database
DatabaseOptions
Configuration options for opening a database.usize
default:"25,000"
Number of pages to cache in memory (1 page = ~4KB)
u64
default:"1,000"
Automatically checkpoint when WAL reaches this many frames
u32
default:"0o644"
Unix file permissions for database files (Unix only)
bool
default:"false"
Open database in read-only mode
usize
default:"100,000"
Maximum number of documents in bulk operations
usize
default:"67,108,864"
Maximum size of a single document in bytes (64MB)
usize
default:"52,428,800"
Maximum HTTP request body size for web server (50MB)
Collection operations
collection
Get a handle to a collection.
&str
required
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.
&str
required
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.
Fn(&mut Transaction) -> Result<R>
required
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.
&str
required
Name of the collection
&str
required
Name for the index
&str
required
Field to index
bool
required
Whether to enforce uniqueness
create_compound_index
Create a compound index on multiple fields.
&str
required
Name of the collection
&str
required
Name for the index
&[&str]
required
Ordered list of fields to include in the compound index
bool
required
Whether to enforce uniqueness on the combination of field values
create_text_index
Create a text index for full-text search.
&str
required
Name of the collection
&str
required
Name for the text index
&[&str]
required
List of text fields to index for search
drop_index
Drop an index from a collection.
&str
required
Name of the collection
&str
required
Name of the index to drop
list_indexes
List all indexes for a specific collection.
&str
required
Name of the collection
Result<Vec<IndexInfo>> - List of index information
Schema validation
set_schema
Set a validation schema for a collection.
&str
required
Name of the collection
Schema
required
The schema to apply
get_schema
Get the validation schema for a collection.
&str
required
Name of the collection
Option<Schema> - The schema if set, or None
remove_schema
Remove the validation schema from a collection.
&str
required
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.
&str
required
Destination path for the backup file
verify_backup
Verify a backup file by checking its integrity.
&str
required
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.
TransactionConfig
required
Transaction configuration
set_auto_checkpoint_threshold
Set the auto-checkpoint threshold.
u64
required
Number of WAL frames before auto-checkpoint