dbx_core/traits.rs
1//! Database Traits — 기능별 역할 분리
2//!
3//! Database 구조체의 메서드를 기능별 Trait으로 분리하여
4//! 명확한 책임 구분과 테스트 용이성을 제공합니다.
5
6use crate::error::DbxResult;
7
8// ════════════════════════════════════════════
9// Core CRUD Operations
10// ════════════════════════════════════════════
11
12/// 핵심 CRUD 작업을 제공하는 Trait
13pub trait DatabaseCore {
14 /// 데이터 삽입
15 fn insert(&self, table: &str, key: &[u8], value: &[u8]) -> DbxResult<()>;
16
17 /// 데이터 조회
18 fn get(&self, table: &str, key: &[u8]) -> DbxResult<Option<Vec<u8>>>;
19
20 /// 데이터 삭제
21 fn delete(&self, table: &str, key: &[u8]) -> DbxResult<()>;
22
23 /// 전체 스캔
24 fn scan(&self, table: &str) -> DbxResult<Vec<(Vec<u8>, Vec<u8>)>>;
25
26 /// 메모리 → 디스크 플러시
27 fn flush(&self) -> DbxResult<()>;
28
29 /// 배치 삽입
30 fn insert_batch(&self, table: &str, entries: Vec<(Vec<u8>, Vec<u8>)>) -> DbxResult<()>;
31}
32
33// ════════════════════════════════════════════
34// SQL Execution
35// ════════════════════════════════════════════
36
37/// SQL 실행 기능을 제공하는 Trait
38pub trait DatabaseSql {
39 /// SQL 문 실행 (RecordBatch는 engine에서 정의)
40 fn execute_sql(&self, sql: &str) -> DbxResult<Vec<arrow::record_batch::RecordBatch>>;
41
42 /// 테이블 등록 (Arrow RecordBatch)
43 fn register_table(&self, name: &str, batches: Vec<arrow::record_batch::RecordBatch>);
44
45 /// 배치 추가
46 fn append_batch(&self, table: &str, batch: arrow::record_batch::RecordBatch) -> DbxResult<()>;
47}
48
49// ════════════════════════════════════════════
50// Query Builder
51// ════════════════════════════════════════════
52
53/// Fluent 스타일 쿼리 빌더를 제공하는 Trait
54/// (구체적인 타입은 api/query.rs에서 정의)
55pub trait DatabaseQuery {
56 // Query Builder 메서드는 engine/database.rs에서 구현
57}
58
59// ════════════════════════════════════════════
60// Transaction Management
61// ════════════════════════════════════════════
62
63/// 트랜잭션 관리 기능을 제공하는 Trait
64pub trait DatabaseTransaction {
65 /// 트랜잭션 시작
66 fn begin(
67 &self,
68 ) -> DbxResult<crate::transaction::api::Transaction<'_, crate::transaction::api::Active>>;
69}
70
71// ════════════════════════════════════════════
72// Snapshot & Backup
73// ════════════════════════════════════════════
74
75/// 스냅샷 및 백업 기능을 제공하는 Trait
76pub trait DatabaseSnapshot {
77 /// 데이터베이스를 파일로 저장
78 fn save_to_file(&self, path: &str) -> DbxResult<()>;
79
80 /// 파일에서 데이터베이스 로드
81 fn load_from_file(path: &str) -> DbxResult<Self>
82 where
83 Self: Sized;
84}