bl4_idb/
lib.rs

1//! Items Database Library for Borderlands 4
2//!
3//! This library provides a trait-based abstraction for item database operations,
4//! with implementations for SQLite (sync) and SQLx (async, SQLite + PostgreSQL).
5//!
6//! # Features
7//!
8//! - `sqlite-sync` (default) - Synchronous SQLite using rusqlite (for CLI)
9//! - `sqlx-sqlite` - Async SQLite using SQLx (for server)
10//! - `sqlx-postgres` - Async PostgreSQL using SQLx (for server)
11//! - `attachments` - Enable screenshot/image attachment storage
12//!
13//! # Example (Sync)
14//!
15//! ```no_run
16//! use bl4_idb::{SqliteDb, ItemsRepository, ItemFilter};
17//!
18//! let db = SqliteDb::open("items.db").unwrap();
19//! db.init().unwrap();
20//!
21//! // List all items
22//! let items = db.list_items(&ItemFilter::default()).unwrap();
23//! ```
24//!
25//! # Example (Async with SQLx SQLite)
26//!
27//! ```no_run
28//! use bl4_idb::{sqlx_impl::sqlite::SqlxSqliteDb, sqlx_impl::AsyncItemsRepository, ItemFilter};
29//!
30//! async fn example() {
31//!     let db = SqlxSqliteDb::connect("sqlite:items.db").await.unwrap();
32//!     db.init().await.unwrap();
33//!
34//!     // List all items
35//!     let items = db.list_items(&ItemFilter::default()).await.unwrap();
36//! }
37//! ```
38
39pub mod repository;
40pub mod types;
41
42#[cfg(feature = "sqlite-sync")]
43pub mod sqlite;
44
45#[cfg(any(feature = "sqlx-sqlite", feature = "sqlx-postgres"))]
46pub mod sqlx_impl;
47
48// Re-export types
49pub use types::*;
50
51// Re-export repository traits (sync)
52pub use repository::{
53    BulkRepository, BulkResult, BulkValueSet, ImportExportRepository, ItemsRepository, RepoError,
54    RepoResult,
55};
56
57#[cfg(feature = "attachments")]
58pub use repository::AttachmentsRepository;
59
60// Re-export async repository traits
61#[cfg(any(feature = "sqlx-sqlite", feature = "sqlx-postgres"))]
62pub use sqlx_impl::{AsyncItemsRepository, AsyncRepoResult};
63
64#[cfg(all(
65    feature = "attachments",
66    any(feature = "sqlx-sqlite", feature = "sqlx-postgres")
67))]
68pub use sqlx_impl::AsyncAttachmentsRepository;
69
70#[cfg(any(feature = "sqlx-sqlite", feature = "sqlx-postgres"))]
71pub use sqlx_impl::AsyncBulkRepository;
72#[cfg(any(feature = "sqlx-sqlite", feature = "sqlx-postgres"))]
73pub use sqlx_impl::BulkResult as AsyncBulkResult;
74
75// Re-export implementations
76#[cfg(feature = "sqlite-sync")]
77pub use sqlite::{SqliteDb, DEFAULT_DB_PATH};
78
79#[cfg(feature = "sqlx-sqlite")]
80pub use sqlx_impl::sqlite::SqlxSqliteDb;
81
82#[cfg(feature = "sqlx-postgres")]
83pub use sqlx_impl::postgres::SqlxPgDb;