How thebigby10/picodb works
Project Type and Purpose
• PicoDB is a C++‐based, embeddable library simulating SQL database operations over CSV files.
• It can be used either via a Command‐Line Interface (CommandLineInterface.cpp) or linked into other C++ projects as a static library (libpicoDB.a).
• Core use case: provide SELECT, INSERT, UPDATE, DELETE, schema management, joins, key constraints, basic encryption, and data functions without a full RDBMS.
File Structure
Top‑level:
• CMakeLists.txt – build configuration.
• CommandLineInterface.cpp – optional CLI entry point.
• /PicoDB – public API headers.
• src/ – library implementation subdivided into:
– core/ (Database, Table, ConfigManager, UserPermissionManager, Cell)
– storage/ (FileHandler, Encryptor)
– utils/ (Date, Map, String, Vector, converters)
• examples/ – sample applications and CSV databases.
• tests/ – unit and integration tests.
• resources/ – images or other assets.
Patterns:
• Modular layering: API → core engine → storage layer → utilities.
• No external process; everything runs in‐process.
• CMake enables building static library and examples/tests.
Extract Insights from README
• Confirms the modules: CSV storage, XOR encryption, SQL operation support, schema management, join capabilities, key enforcement, filtering, functions, subqueries.
• Identifies intended usage (embedding via CMake, CLI demos).
• Suggests future docs folder (not yet present).
Main Architectural Components
a. Public API / Client Layer
• PicoDB class (PicoDB.h / PicoDB.cpp) – entry point for consumers and CLI.
• Command‐Line Interface (if used).
b. Core Engine
• Query Processor (part of Database and Table classes): parses incoming SQL commands.
• Schema Manager (ConfigManager) – loads/stores database and table configurations.
• Catalog / Metadata (Table, Cell, UserPermissionManager) – enforces schemas, primary/foreign keys, user permissions.
c. Storage Layer
• FileHandler – reads/writes CSV files to disk.
• Encryptor – applies XOR cipher on data streams when encryption is enabled.
d. Utilities Layer
• Data types and helpers: Date, String, Vector, Map, StringVectorConverter for parsing/conversion, Vector for result sets.
e. Build and Deployment
• CMake – orchestrates compilation into libpicoDB.a, builds examples and tests.
• Tests – unit test harness using custom tests in tests/ and basic_tests.
f. External Dependencies (C++17, standard library).
Relationships and Interactions
• Client/API → invokes methods on PicoDB instance.
• PicoDB instance → delegates to ConfigManager to initialize or load database metadata.
• For each SQL call: PicoDB → Database → Query Processor → performs in‐memory operations across Table and Cell structures, referencing metadata.
• Write operations → pass through storage layer: Table → FileHandler → optionally Encryptor → CSV file.
• Read operations → FileHandler reads CSV, optionally decrypts, then Query Processor filters and projects results.
• Utility classes assist parsing, type conversion, and internal data representation.
Architectural Patterns and Principles
• Layered architecture: clear separation between API, core logic, storage, and utilities.
• Single Responsibility: each module (ConfigManager, FileHandler, Encryptor) has a focused purpose.
• Dependency inversion: high‑level modules (Database) depend on abstractions (FileHandler interface).
• In‑process library design: embeddable static library, minimal external infrastructure.