Skip to main content
The 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
Returns: 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
Example:

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
Returns: Collection - A collection handle Example:

list_collections

List all collections in the database.
Returns: Result<Vec<String>> - Sorted list of collection names Example:

collection_stats

Get detailed statistics for a specific collection.
&str
required
Name of the collection
Returns: Result<CollectionInfo> - Collection statistics Example:

Transaction management

begin

Begin a new transaction.
Returns: 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
Returns: 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
Example:

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
Example:

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
Example:

drop_index

Drop an index from a collection.
&str
required
Name of the collection
&str
required
Name of the index to drop
Example:

list_indexes

List all indexes for a specific collection.
&str
required
Name of the collection
Returns: 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
Example:

get_schema

Get the validation schema for a collection.
&str
required
Name of the collection
Returns: 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.
Example:

garbage_collect

Remove old document versions that are no longer needed.
Returns: Result<GarbageCollectionStats> - Statistics about the garbage collection Example:

backup

Create a backup of the database.
&str
required
Destination path for the backup file
Example:

verify_backup

Verify a backup file by checking its integrity.
&str
required
Path to the backup file to verify
Returns: Result<BackupInfo> - Backup information if valid Example:

close

Close the database connection.
Example:

Database information

info

Get comprehensive database information.
Returns: Result<DatabaseInfo> - Detailed database statistics Example:

metrics

Get a snapshot of current database metrics.
Returns: MetricsSnapshot - Current metrics Example:

path

Get the database file path.
Returns: &str - The database file path

is_read_only

Check if the database is in read-only mode.
Returns: bool - true if read-only, false otherwise

Configuration

set_transaction_config

Set transaction retry configuration.
TransactionConfig
required
Transaction configuration
Example:

set_auto_checkpoint_threshold

Set the auto-checkpoint threshold.
u64
required
Number of WAL frames before auto-checkpoint
Example: