1. Overview
QueryBuilder is a modular backend system that allows loading CSV/Excel files into a database, running read-only SQL queries, inspecting tables and schemas, and exporting query results. The backend is designed to be engine-agnostic, supporting multiple SQL engines (SQLite, DuckDB planned).
Key Features
- Load CSV/Excel files into a local SQL database
- Abstracted database engine support
- Query execution with read-only validation
- Table and schema inspection
- Export query results to CSV or Excel
- Modular, extensible architecture
2. Architecture
Modules
-
Core
- Provides constants, config, logging, and custom exceptions
- Ensures consistent behavior and centralized logging
-
Engines
- EngineLoader: manages connections and cleanup
- EngineQuery: executes queries and fetches results
Supports SQLite (currently) and planned DuckDB. We use raw database APIs instead of ORM or third-party wrappers. It handles connection pooling internally and provides a context manager for safe resource handling
-
Loader
- Loads files into the database
- CSV files → single table
- Excel files → each sheet as a table
- Tracks table names
-
Query Builder
- High-level query execution
- Validates queries to allow only read-only operations
- Returns results as pandas DataFrames
-
Main (QuerySession)
- Entry point for CLI/GUI
- Manages engine, loader, query builder
- Provides unified interface for queries, schema, tables, export, cleanup
3. Data Flow
- File Upload/Load
- User provides CSV/Excel file
- FileLoader loads data into the selected database engine
- Tables are tracked for inspection