diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-21 04:04:05 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-21 04:04:05 +0000 |
| commit | 2e799fa7ec57d284c643df8b8dc54471470f5c59 (patch) | |
| tree | 0d8affa3e742d34e8d5a251b4ae50678c10a10d5 /src/nostr/builder.rs | |
| parent | 25b206c00766579f2322619f4716ca999f9b92ec (diff) | |
feat: add database backend configuration options
Add environment variable configuration for database backend selection:
- Added DatabaseBackend enum (memory, nostrdb, lmdb) in src/config.rs
- Updated relay builder to use configured backend in src/nostr/builder.rs
- Added NGIT_DATABASE_BACKEND to .env.example with documentation
- Updated docs/reference/configuration.md with backend comparison table
NostrDB and LMDB backends prepared for future implementation when
nostr-relay-builder adds support. Currently defaults to in-memory
database with warning logs when persistent backends are selected.
Diffstat (limited to 'src/nostr/builder.rs')
| -rw-r--r-- | src/nostr/builder.rs | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index 09b2fe2..547db8e 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs | |||
| @@ -11,7 +11,7 @@ use nostr::prelude::{Alphabet, SingleLetterTag}; | |||
| 11 | use nostr::{EventId, Filter, Kind, PublicKey}; | 11 | use nostr::{EventId, Filter, Kind, PublicKey}; |
| 12 | use nostr_relay_builder::prelude::*; | 12 | use nostr_relay_builder::prelude::*; |
| 13 | 13 | ||
| 14 | use crate::config::Config; | 14 | use crate::config::{Config, DatabaseBackend}; |
| 15 | use crate::nostr::events::{ | 15 | use crate::nostr::events::{ |
| 16 | validate_announcement, validate_state, KIND_REPOSITORY_ANNOUNCEMENT, KIND_REPOSITORY_STATE, | 16 | validate_announcement, validate_state, KIND_REPOSITORY_ANNOUNCEMENT, KIND_REPOSITORY_STATE, |
| 17 | }; | 17 | }; |
| @@ -397,14 +397,36 @@ pub fn create_relay(config: &Config) -> Result<LocalRelay> { | |||
| 397 | // Determine database path | 397 | // Determine database path |
| 398 | let db_path = Path::new(&config.relay_data_path); | 398 | let db_path = Path::new(&config.relay_data_path); |
| 399 | 399 | ||
| 400 | // Create database - using in-memory for now, can switch to persistent later | 400 | // Create database based on configuration |
| 401 | // TODO: Add configuration for NostrDB or LMDB backends | 401 | let database = match config.database_backend { |
| 402 | let database = Arc::new(MemoryDatabase::with_opts(MemoryDatabaseOptions { | 402 | DatabaseBackend::Memory => { |
| 403 | events: true, | 403 | tracing::info!("Using in-memory database (no persistence)"); |
| 404 | max_events: Some(100_000), | 404 | Arc::new(MemoryDatabase::with_opts(MemoryDatabaseOptions { |
| 405 | })); | 405 | events: true, |
| 406 | 406 | max_events: Some(100_000), | |
| 407 | tracing::info!("Using in-memory database (path: {})", db_path.display()); | 407 | })) |
| 408 | } | ||
| 409 | DatabaseBackend::NostrDb => { | ||
| 410 | tracing::info!("Using NostrDB backend at: {}", db_path.display()); | ||
| 411 | // TODO: Implement NostrDB backend once nostr-relay-builder supports it | ||
| 412 | // For now, fall back to memory database | ||
| 413 | tracing::warn!("NostrDB backend not yet implemented, using in-memory database"); | ||
| 414 | Arc::new(MemoryDatabase::with_opts(MemoryDatabaseOptions { | ||
| 415 | events: true, | ||
| 416 | max_events: Some(100_000), | ||
| 417 | })) | ||
| 418 | } | ||
| 419 | DatabaseBackend::Lmdb => { | ||
| 420 | tracing::info!("Using LMDB backend at: {}", db_path.display()); | ||
| 421 | // TODO: Implement LMDB backend once nostr-relay-builder supports it | ||
| 422 | // For now, fall back to memory database | ||
| 423 | tracing::warn!("LMDB backend not yet implemented, using in-memory database"); | ||
| 424 | Arc::new(MemoryDatabase::with_opts(MemoryDatabaseOptions { | ||
| 425 | events: true, | ||
| 426 | max_events: Some(100_000), | ||
| 427 | })) | ||
| 428 | } | ||
| 429 | }; | ||
| 408 | 430 | ||
| 409 | // Build relay with GRASP-01 validation | 431 | // Build relay with GRASP-01 validation |
| 410 | // Clone Arc for the write policy so both relay and policy can access the database | 432 | // Clone Arc for the write policy so both relay and policy can access the database |