**feat: add write-only mode support and example usage**

- Introduced `writeOnly` mode in `BrainyData` allowing optimized data ingestion by skipping index loading and disabling search operations.
- Enhanced `BrainyDataConfig` to include `writeOnly` support and validate compatibility with `readOnly` mode.
- Implemented error handling for search attempts during `writeOnly` mode.
- Updated the README with detailed usage examples for database modes, including `writeOnly` and `readOnly`.
- Added `examples/write-only-mode.js` to demonstrate practical applications of the `writeOnly` mode.

**Purpose**: Optimize memory usage and startup time for data ingestion scenarios by enabling write-only mode with comprehensive documentation and examples.
This commit is contained in:
David Snelling 2025-07-30 13:32:30 -07:00
parent d70d0946cf
commit 5d82db12e2
3 changed files with 3696 additions and 3426 deletions

View file

@ -598,6 +598,37 @@ await db.deleteVerb(verbId)
## Advanced Configuration
### Database Modes
Brainy supports special operational modes that restrict certain operations:
```typescript
import { BrainyData } from '@soulcraft/brainy'
// Create and initialize the database
const db = new BrainyData()
await db.init()
// Set the database to read-only mode (prevents write operations)
db.setReadOnly(true)
// Check if the database is in read-only mode
const isReadOnly = db.isReadOnly() // Returns true
// Set the database to write-only mode (prevents search operations)
db.setWriteOnly(true)
// Check if the database is in write-only mode
const isWriteOnly = db.isWriteOnly() // Returns true
// Reset to normal mode (allows both read and write operations)
db.setReadOnly(false)
db.setWriteOnly(false)
```
- **Read-Only Mode**: When enabled, prevents all write operations (add, update, delete). Useful for deployment scenarios where you want to prevent modifications to the database.
- **Write-Only Mode**: When enabled, prevents all search operations. Useful for initial data loading or when you want to optimize for write performance.
### Embedding
```typescript