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//! ```ignore
28//! // Requires feature "sqlx-sqlite"
29//! use bl4_idb::{sqlx_impl::sqlite::SqlxSqliteDb, sqlx_impl::AsyncItemsRepository, ItemFilter};
30//!
31//! async fn example() {
32//! let db = SqlxSqliteDb::connect("sqlite:items.db").await.unwrap();
33//! db.init().await.unwrap();
34//!
35//! // List all items
36//! let items = db.list_items(&ItemFilter::default()).await.unwrap();
37//! }
38//! ```
39
40pub mod repository;
41pub mod types;
42
43#[cfg(feature = "sqlite-sync")]
44pub mod sqlite;
45
46#[cfg(any(feature = "sqlx-sqlite", feature = "sqlx-postgres"))]
47pub mod sqlx_impl;
48
49// Re-export types
50pub use types::*;
51
52// Re-export repository traits (sync)
53pub use repository::{
54 BulkRepository, BulkResult, BulkValueSet, ImportExportRepository, ItemsRepository, RepoError,
55 RepoResult,
56};
57
58#[cfg(feature = "attachments")]
59pub use repository::AttachmentsRepository;
60
61// Re-export async repository traits
62#[cfg(any(feature = "sqlx-sqlite", feature = "sqlx-postgres"))]
63pub use sqlx_impl::{AsyncItemsRepository, AsyncRepoResult};
64
65#[cfg(all(
66 feature = "attachments",
67 any(feature = "sqlx-sqlite", feature = "sqlx-postgres")
68))]
69pub use sqlx_impl::AsyncAttachmentsRepository;
70
71#[cfg(any(feature = "sqlx-sqlite", feature = "sqlx-postgres"))]
72pub use sqlx_impl::AsyncBulkRepository;
73#[cfg(any(feature = "sqlx-sqlite", feature = "sqlx-postgres"))]
74pub use sqlx_impl::BulkResult as AsyncBulkResult;
75
76// Re-export implementations
77#[cfg(feature = "sqlite-sync")]
78pub use sqlite::{SqliteDb, DEFAULT_DB_PATH};
79
80#[cfg(feature = "sqlx-sqlite")]
81pub use sqlx_impl::sqlite::SqlxSqliteDb;
82
83#[cfg(feature = "sqlx-postgres")]
84pub use sqlx_impl::postgres::SqlxPgDb;