Database class represents a jasonisnthappy database instance.
Opening a database
open
Opens a database at the specified path.Path to the database file
Database instance
open_with_options
Opens a database with custom options.Path to the database file
Custom database configuration options
Database instance
default_database_options
Returns the default database options.Default database configuration
Database management
close
Closes the database and frees associated resources.Context manager support
Use thewith statement for automatic resource cleanup.
Example:
begin_transaction
Begins a new transaction.Transaction instance
get_collection
Gets a collection reference for non-transactional operations.Name of the collection
Collection handle
Configuration
set_transaction_config
Sets the transaction retry configuration.Transaction configuration with retry settings
get_transaction_config
Gets the current transaction configuration.Current transaction configuration
set_auto_checkpoint_threshold
Sets the auto-checkpoint threshold in WAL frames.Number of WAL frames before automatic checkpoint
Database information
get_path
Gets the database file path.Database file path
is_read_only
Checks if the database is read-only.True if the database is read-only
list_collections
Lists all collections in the database.List of collection names
collection_stats
Gets statistics for a collection.Name of the collection
Collection statistics
database_info
Gets database information.Database information including path, size, collections, etc.
max_bulk_operations
Returns the maximum number of bulk operations allowed.Maximum bulk operations limit
max_document_size
Returns the maximum document size in bytes.Maximum document size in bytes
max_request_body_size
Returns the maximum HTTP request body size in bytes.Maximum request body size in bytes
Index management
create_index
Creates a single-field index.Name of the collection
Name for the index
Field to index
Whether the index should enforce uniqueness
create_compound_index
Creates a compound index on multiple fields.Name of the collection
Name for the index
Fields to include in the compound index
Whether the index should enforce uniqueness
create_text_index
Creates a full-text search index.Name of the collection
Name for the index
Text field to index
drop_index
Drops an index from a collection.Name of the collection
Name of the index to drop
list_indexes
Lists all indexes for a collection.Name of the collection
List of index metadata
Schema validation
set_schema
Sets a JSON schema for validation.Name of the collection
JSON schema for validation
get_schema
Gets the JSON schema for a collection.Name of the collection
JSON schema, or None if no schema is set
remove_schema
Removes the JSON schema from a collection.Name of the collection
Maintenance
checkpoint
Performs a manual WAL checkpoint.backup
Creates a backup of the database.Destination path for the backup file
verify_backup
Verifies the integrity of a backup and returns backup info.Path to the backup file
Backup verification information
garbage_collect
Performs garbage collection and returns stats.Garbage collection statistics
metrics
Gets database metrics.Database metrics including reads, writes, cache hits, etc.
frame_count
Gets the number of WAL frames.Number of WAL frames
Web UI
start_web_ui
Starts the web UI server at the given address.Address to bind the web server to (e.g., “127.0.0.1:8080”)
WebServer handle to control the server