Database
TheDatabase class is the main entry point for interacting with jasonisnthappy. It manages database connections, transactions, collections, and database-level operations.
Opening a database
Database.open()
Opens a database at the specified path with default options.
string
required
Path to the database file. If the file doesn’t exist, it will be created.
Database
A new Database instance
Database.openWithOptions()
Opens a database with custom configuration options.
string
required
Path to the database file
DatabaseOptions
required
Configuration options for the database
Database.defaultDatabaseOptions()
Returns the default database options.
DatabaseOptions
The default configuration options
Database information
getPath()
Returns the file path of the database.
string
The absolute path to the database file
isReadOnly()
Checks if the database is opened in read-only mode.
boolean
true if database is read-only, false otherwisedatabaseInfo()
Returns comprehensive information about the database.
DatabaseInfo
Database metadata and statistics
maxBulkOperations()
Returns the maximum number of operations allowed in a bulk write.
maxDocumentSize()
Returns the maximum document size in bytes.
maxRequestBodySize()
Returns the maximum request body size for the web server.
Collections
listCollections()
Returns an array of all collection names in the database.
string[]
Array of collection names
getCollection()
Returns a typed Collection instance for performing operations.
string
required
Name of the collection
Collection<T>
A typed Collection instance
collectionStats()
Returns detailed statistics for a specific collection.
string
required
Name of the collection
CollectionInfo
Collection metadata and statistics
Indexes
listIndexes()
Returns all indexes for a collection.
string
required
Name of the collection
IndexInfo[]
Array of index information
createIndex()
Creates a single-field index.
string
required
Name of the collection
string
required
Name for the new index
string
required
Field to index
boolean
required
Whether to enforce uniqueness constraint
createCompoundIndex()
Creates a multi-field compound index.
string
required
Name of the collection
string
required
Name for the new index
string[]
required
Array of field names to include in the index
boolean
required
Whether to enforce uniqueness constraint
createTextIndex()
Creates a full-text search index on a field.
string
required
Name of the collection
string
required
Name for the new text index
string
required
Field to index for full-text search
dropIndex()
Drops an index from a collection.
string
required
Name of the collection
string
required
Name of the index to drop
Schema validation
setSchema()
Sets a JSON schema for validating documents in a collection.
string
required
Name of the collection
Record<string, unknown>
required
JSON Schema object for validation
getSchema()
Retrieves the current schema for a collection.
string
required
Name of the collection
Record<string, unknown> | null
The JSON Schema object, or
null if no schema is setremoveSchema()
Removes the schema validation from a collection.
string
required
Name of the collection
Transactions
beginTransaction()
Starts a new transaction.
Transaction
A new Transaction instance
defaultTransactionConfig()
Returns the default transaction configuration.
TransactionConfig
Default transaction retry configuration
setTransactionConfig()
Sets the transaction retry configuration.
TransactionConfig
required
Transaction retry configuration
getTransactionConfig()
Gets the current transaction retry configuration.
TransactionConfig
Current transaction retry configuration
Maintenance operations
checkpoint()
Forces a checkpoint, writing all in-memory changes to disk.
setAutoCheckpointThreshold()
Sets the auto-checkpoint threshold.
number
required
Number of pages written before auto-checkpoint triggers
garbageCollect()
Runs garbage collection to reclaim deleted pages.
GarbageCollectResult
Statistics about freed resources
frameCount()
Returns the current number of frames in the page cache.
number
Number of cached pages
Backup and restore
backup()
Creates a backup of the database.
string
required
Destination path for the backup file
Database.verifyBackup()
Verifies and returns information about a backup file.
string
required
Path to the backup file to verify
BackupInfo
Backup file metadata
Metrics
metrics()
Returns database operation metrics.
MetricsSnapshot
Database operation statistics
Web server
startWebUi()
Starts a web-based admin interface for the database.
string
required
Address and port to bind the web server (e.g., “127.0.0.1:8080”)
WebServer
A WebServer instance that can be stopped