minidb-engine 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. minidb_engine-0.1.0/PKG-INFO +310 -0
  2. minidb_engine-0.1.0/README.md +303 -0
  3. minidb_engine-0.1.0/minidb/__init__.py +4 -0
  4. minidb_engine-0.1.0/minidb/database.py +391 -0
  5. minidb_engine-0.1.0/minidb/executor.py +214 -0
  6. minidb_engine-0.1.0/minidb/index.py +36 -0
  7. minidb_engine-0.1.0/minidb/plugins/__init__.py +6 -0
  8. minidb_engine-0.1.0/minidb/plugins/manager.py +42 -0
  9. minidb_engine-0.1.0/minidb/plugins/query_logger.py +37 -0
  10. minidb_engine-0.1.0/minidb/plugins/query_stats.py +53 -0
  11. minidb_engine-0.1.0/minidb/query.py +284 -0
  12. minidb_engine-0.1.0/minidb/storage.py +71 -0
  13. minidb_engine-0.1.0/minidb_engine.egg-info/PKG-INFO +310 -0
  14. minidb_engine-0.1.0/minidb_engine.egg-info/SOURCES.txt +31 -0
  15. minidb_engine-0.1.0/minidb_engine.egg-info/dependency_links.txt +1 -0
  16. minidb_engine-0.1.0/minidb_engine.egg-info/top_level.txt +1 -0
  17. minidb_engine-0.1.0/pyproject.toml +14 -0
  18. minidb_engine-0.1.0/setup.cfg +4 -0
  19. minidb_engine-0.1.0/tests/test_aggregation.py +39 -0
  20. minidb_engine-0.1.0/tests/test_api.py +29 -0
  21. minidb_engine-0.1.0/tests/test_concurrency.py +39 -0
  22. minidb_engine-0.1.0/tests/test_crud_queries.py +49 -0
  23. minidb_engine-0.1.0/tests/test_database.py +40 -0
  24. minidb_engine-0.1.0/tests/test_executor.py +56 -0
  25. minidb_engine-0.1.0/tests/test_index.py +102 -0
  26. minidb_engine-0.1.0/tests/test_plugins.py +65 -0
  27. minidb_engine-0.1.0/tests/test_query.py +36 -0
  28. minidb_engine-0.1.0/tests/test_query_planner.py +57 -0
  29. minidb_engine-0.1.0/tests/test_schema.py +78 -0
  30. minidb_engine-0.1.0/tests/test_sorting.py +40 -0
  31. minidb_engine-0.1.0/tests/test_statistics.py +64 -0
  32. minidb_engine-0.1.0/tests/test_transaction_isolation.py +70 -0
  33. minidb_engine-0.1.0/tests/test_transactions.py +98 -0
@@ -0,0 +1,310 @@
1
+ Metadata-Version: 2.4
2
+ Name: minidb-engine
3
+ Version: 0.1.0
4
+ Summary: A lightweight educational database engine built in Python.
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+
8
+ # MiniDB – Custom Database and Query Execution Engine
9
+
10
+ A lightweight, extensible database engine built from scratch using Python.
11
+
12
+ ## 1. Project Overview
13
+
14
+ MiniDB is an educational database management system that implements its own SQL-like query processing engine without using SQLite, DuckDB, or another full database engine as its core.
15
+
16
+ It demonstrates fundamental database internals, including custom query parsing, execution, persistent storage, indexing, query planning, transaction management, recovery, concurrency control, and extensible plugins.
17
+
18
+ ## 2. Project Objectives
19
+
20
+ - Build a custom tokenizer and query parser.
21
+ - Implement an internal query execution engine.
22
+ - Develop a persistent storage layer.
23
+ - Support CRUD operations and query filtering.
24
+ - Implement projection, sorting, and aggregation.
25
+ - Build indexing and basic query planning.
26
+ - Support transaction commit and rollback.
27
+ - Implement recovery of committed operations.
28
+ - Define thread-level concurrency behavior.
29
+ - Collect query execution statistics.
30
+ - Provide a reusable Python package with plugin support.
31
+
32
+ ## 3. Technologies Used
33
+
34
+ - Python 3
35
+ - JSON-based persistent storage
36
+ - Python unittest
37
+ - Streamlit dashboard
38
+ - setuptools packaging
39
+ - Visual Studio Code
40
+
41
+ ## 4. Architecture
42
+
43
+ MiniDB is organized into modular components:
44
+
45
+ | Module | Responsibility |
46
+ |---|---|
47
+ | `query.py` | Custom tokenization and query parsing |
48
+ | `executor.py` | Query execution |
49
+ | `database.py` | Public database API and transaction management |
50
+ | `storage.py` | Persistent JSON operation log |
51
+ | `index.py` | In-memory indexing |
52
+ | `plugins/manager.py` | Plugin registration and activation |
53
+ | `plugins/query_logger.py` | Automatic query logging |
54
+ | `plugins/query_stats.py` | Execution statistics |
55
+
56
+ ### Query Processing Workflow
57
+
58
+ User Query → Tokenizer → Parser → Query Executor → Query Planner → Storage / Index → Query Result
59
+
60
+ ### Plugin Workflow
61
+
62
+ Plugin Creation → Registration → Activation → Database Query Execution → Plugin Hooks
63
+
64
+ ## 5. Implemented Features
65
+
66
+ ### Query Processing
67
+ - Custom tokenizer and parser.
68
+ - INSERT, SELECT, UPDATE, and DELETE.
69
+ - WHERE-based filtering.
70
+ - Projection and sorting.
71
+ - COUNT, SUM, and AVG aggregations.
72
+
73
+ ### Storage and Data Management
74
+ - Custom persistent JSON operation log.
75
+ - Record insertion, retrieval, updating, and deletion.
76
+ - Recovery by replaying committed operations.
77
+ - Optional schema and data-type validation.
78
+
79
+ ### Indexing and Query Planning
80
+ - In-memory indexing.
81
+ - Index-based record retrieval.
82
+ - Basic rule-based query planning.
83
+ - Indexed and non-indexed query execution.
84
+ - Query execution statistics.
85
+
86
+ ### Transactions and Reliability
87
+ - BEGIN, COMMIT, and ROLLBACK.
88
+ - Buffered transaction operations.
89
+ - Transaction batches written as a single log entry.
90
+ - Recovery that ignores incomplete final log entries.
91
+ - Thread-level synchronization using a re-entrant lock.
92
+ - Transaction isolation between threads.
93
+
94
+ ### Plugin Architecture
95
+ - Plugin registration and activation.
96
+ - Plugin manager.
97
+ - Automatic query logging.
98
+ - Automatic execution-time measurement.
99
+ - Query success and failure statistics.
100
+ - Support for custom developer-created plugins.
101
+
102
+ ## 6. Installation
103
+
104
+ Clone or download the project.
105
+
106
+ Navigate to the project directory:
107
+
108
+ ```bash
109
+ cd minidb_starter
110
+ ```
111
+
112
+ Install MiniDB in editable mode:
113
+
114
+ ```bash
115
+ python -m pip install -e .
116
+ ```
117
+
118
+ Import the database:
119
+
120
+ ```python
121
+ from minidb import Database
122
+
123
+ db = Database("data/example.log")
124
+ ```
125
+
126
+ ## 7. Basic Usage
127
+
128
+ ```python
129
+ from minidb import Database
130
+
131
+ db = Database("data/example.log")
132
+
133
+ db.execute(
134
+ 'INSERT INTO students (name, semester) VALUES ("Ananya", 5)'
135
+ )
136
+
137
+ result = db.execute("SELECT * FROM students")
138
+
139
+ print(result)
140
+ ```
141
+
142
+ MiniDB supports INSERT, SELECT, UPDATE, and DELETE query operations.
143
+
144
+ ## 8. Using Built-in Plugins
145
+
146
+ ### Query Logger
147
+
148
+ ```python
149
+ from minidb import Database
150
+ from minidb.plugins.query_logger import QueryLogger
151
+
152
+ db = Database("data/example.log")
153
+
154
+ logger = QueryLogger()
155
+
156
+ db.register_plugin("logger", logger)
157
+ db.activate_plugin("logger")
158
+
159
+ db.execute(
160
+ 'INSERT INTO students (name, semester) VALUES ("Ananya", 5)'
161
+ )
162
+
163
+ print(logger.get_logs())
164
+ ```
165
+
166
+ ### Query Statistics
167
+
168
+ ```python
169
+ from minidb.plugins.query_stats import QueryStats
170
+
171
+ stats = QueryStats()
172
+
173
+ db.register_plugin("stats", stats)
174
+ db.activate_plugin("stats")
175
+
176
+ db.execute("SELECT * FROM students")
177
+
178
+ print(stats.get_statistics())
179
+ ```
180
+
181
+ Statistics include execution time, success status, and timestamp.
182
+
183
+ ## 9. Creating a Custom Plugin
184
+
185
+ Developers can extend MiniDB without modifying the core engine.
186
+
187
+ Example:
188
+
189
+ ```python
190
+ class AuditPlugin:
191
+
192
+ def activate(self, database):
193
+ self.database = database
194
+ self.records = []
195
+
196
+ def record_query(self, query):
197
+ self.records.append(query)
198
+ ```
199
+
200
+ Register and activate the plugin:
201
+
202
+ ```python
203
+ audit = AuditPlugin()
204
+
205
+ db.register_plugin("audit", audit)
206
+ db.activate_plugin("audit")
207
+ ```
208
+
209
+ Plugins implementing `record_query()` are automatically notified after successful query execution.
210
+
211
+ See [Plugin Development Guide](docs/PLUGIN_GUIDE.md) for more details.
212
+
213
+ ## 10. Running the Dashboard
214
+
215
+ Install Streamlit if it is not already installed:
216
+
217
+ ```bash
218
+ python -m pip install streamlit
219
+ ```
220
+
221
+ Start the dashboard:
222
+
223
+ ```bash
224
+ streamlit run app.py
225
+ ```
226
+
227
+ ## 11. Running Automated Tests
228
+
229
+ Run the complete test suite:
230
+
231
+ ```bash
232
+ python -m unittest discover -s tests -v
233
+ ```
234
+
235
+ The project currently contains 47 passing automated tests covering database functionality and plugin integration.
236
+
237
+ ## 12. Benchmarking
238
+
239
+ Run the benchmark script:
240
+
241
+ ```bash
242
+ python benchmark.py
243
+ ```
244
+
245
+ An example benchmark run produced the following results:
246
+
247
+ | Dataset Size | Full Scan (ms) | Indexed Query (ms) |
248
+ |---:|---:|---:|
249
+ | 100 | 0.2376 | 0.0929 |
250
+ | 1,000 | 1.2538 | 0.0637 |
251
+ | 5,000 | 6.0168 | 0.0635 |
252
+
253
+ These are example measurements from one run. Actual performance depends on the hardware, dataset, and execution conditions.
254
+
255
+ ## 13. Project Structure
256
+
257
+ ```text
258
+ minidb_starter/
259
+ │
260
+ ├── minidb/
261
+ │ ├── __init__.py
262
+ │ ├── database.py
263
+ │ ├── executor.py
264
+ │ ├── index.py
265
+ │ ├── query.py
266
+ │ ├── storage.py
267
+ │ └── plugins/
268
+ │ ├── __init__.py
269
+ │ ├── manager.py
270
+ │ ├── query_logger.py
271
+ │ └── query_stats.py
272
+ │
273
+ ├── tests/
274
+ ├── examples/
275
+ │ └── custom_plugin.py
276
+ ├── docs/
277
+ │ └── PLUGIN_GUIDE.md
278
+ ├── data/
279
+ ├── app.py
280
+ ├── demo.py
281
+ ├── benchmark.py
282
+ ├── pyproject.toml
283
+ └── README.md
284
+ ```
285
+
286
+ ## 14. Current Limitations
287
+
288
+ - MiniDB is an educational database engine, not a production-grade database.
289
+ - Indexes are maintained in memory and rebuilt when the database is reopened.
290
+ - The query planner uses basic rules rather than a cost-based optimization model.
291
+ - Concurrency protection is thread-level within a database instance; multi-process coordination is not implemented.
292
+ - The recovery mechanism is a simplified operation-log approach, not a full production-grade WAL.
293
+ - Plugin isolation and automatic third-party plugin discovery are not implemented.
294
+ - Supported SQL-like syntax is intentionally limited.
295
+
296
+ ## 15. Future Improvements
297
+
298
+ - More SQL operations and query capabilities.
299
+ - Advanced query optimization.
300
+ - Improved crash recovery.
301
+ - More indexing strategies.
302
+ - Plugin discovery and distribution.
303
+ - Better concurrency and multi-process support.
304
+ - Expanded benchmarking and performance analysis.
305
+
306
+ ## 16. Project Purpose
307
+
308
+ MiniDB is designed to demonstrate how database engines work internally while providing a reusable Python library and an extensible plugin architecture.
309
+
310
+ It is intended for learning, experimentation, and further development.
@@ -0,0 +1,303 @@
1
+ # MiniDB – Custom Database and Query Execution Engine
2
+
3
+ A lightweight, extensible database engine built from scratch using Python.
4
+
5
+ ## 1. Project Overview
6
+
7
+ MiniDB is an educational database management system that implements its own SQL-like query processing engine without using SQLite, DuckDB, or another full database engine as its core.
8
+
9
+ It demonstrates fundamental database internals, including custom query parsing, execution, persistent storage, indexing, query planning, transaction management, recovery, concurrency control, and extensible plugins.
10
+
11
+ ## 2. Project Objectives
12
+
13
+ - Build a custom tokenizer and query parser.
14
+ - Implement an internal query execution engine.
15
+ - Develop a persistent storage layer.
16
+ - Support CRUD operations and query filtering.
17
+ - Implement projection, sorting, and aggregation.
18
+ - Build indexing and basic query planning.
19
+ - Support transaction commit and rollback.
20
+ - Implement recovery of committed operations.
21
+ - Define thread-level concurrency behavior.
22
+ - Collect query execution statistics.
23
+ - Provide a reusable Python package with plugin support.
24
+
25
+ ## 3. Technologies Used
26
+
27
+ - Python 3
28
+ - JSON-based persistent storage
29
+ - Python unittest
30
+ - Streamlit dashboard
31
+ - setuptools packaging
32
+ - Visual Studio Code
33
+
34
+ ## 4. Architecture
35
+
36
+ MiniDB is organized into modular components:
37
+
38
+ | Module | Responsibility |
39
+ |---|---|
40
+ | `query.py` | Custom tokenization and query parsing |
41
+ | `executor.py` | Query execution |
42
+ | `database.py` | Public database API and transaction management |
43
+ | `storage.py` | Persistent JSON operation log |
44
+ | `index.py` | In-memory indexing |
45
+ | `plugins/manager.py` | Plugin registration and activation |
46
+ | `plugins/query_logger.py` | Automatic query logging |
47
+ | `plugins/query_stats.py` | Execution statistics |
48
+
49
+ ### Query Processing Workflow
50
+
51
+ User Query → Tokenizer → Parser → Query Executor → Query Planner → Storage / Index → Query Result
52
+
53
+ ### Plugin Workflow
54
+
55
+ Plugin Creation → Registration → Activation → Database Query Execution → Plugin Hooks
56
+
57
+ ## 5. Implemented Features
58
+
59
+ ### Query Processing
60
+ - Custom tokenizer and parser.
61
+ - INSERT, SELECT, UPDATE, and DELETE.
62
+ - WHERE-based filtering.
63
+ - Projection and sorting.
64
+ - COUNT, SUM, and AVG aggregations.
65
+
66
+ ### Storage and Data Management
67
+ - Custom persistent JSON operation log.
68
+ - Record insertion, retrieval, updating, and deletion.
69
+ - Recovery by replaying committed operations.
70
+ - Optional schema and data-type validation.
71
+
72
+ ### Indexing and Query Planning
73
+ - In-memory indexing.
74
+ - Index-based record retrieval.
75
+ - Basic rule-based query planning.
76
+ - Indexed and non-indexed query execution.
77
+ - Query execution statistics.
78
+
79
+ ### Transactions and Reliability
80
+ - BEGIN, COMMIT, and ROLLBACK.
81
+ - Buffered transaction operations.
82
+ - Transaction batches written as a single log entry.
83
+ - Recovery that ignores incomplete final log entries.
84
+ - Thread-level synchronization using a re-entrant lock.
85
+ - Transaction isolation between threads.
86
+
87
+ ### Plugin Architecture
88
+ - Plugin registration and activation.
89
+ - Plugin manager.
90
+ - Automatic query logging.
91
+ - Automatic execution-time measurement.
92
+ - Query success and failure statistics.
93
+ - Support for custom developer-created plugins.
94
+
95
+ ## 6. Installation
96
+
97
+ Clone or download the project.
98
+
99
+ Navigate to the project directory:
100
+
101
+ ```bash
102
+ cd minidb_starter
103
+ ```
104
+
105
+ Install MiniDB in editable mode:
106
+
107
+ ```bash
108
+ python -m pip install -e .
109
+ ```
110
+
111
+ Import the database:
112
+
113
+ ```python
114
+ from minidb import Database
115
+
116
+ db = Database("data/example.log")
117
+ ```
118
+
119
+ ## 7. Basic Usage
120
+
121
+ ```python
122
+ from minidb import Database
123
+
124
+ db = Database("data/example.log")
125
+
126
+ db.execute(
127
+ 'INSERT INTO students (name, semester) VALUES ("Ananya", 5)'
128
+ )
129
+
130
+ result = db.execute("SELECT * FROM students")
131
+
132
+ print(result)
133
+ ```
134
+
135
+ MiniDB supports INSERT, SELECT, UPDATE, and DELETE query operations.
136
+
137
+ ## 8. Using Built-in Plugins
138
+
139
+ ### Query Logger
140
+
141
+ ```python
142
+ from minidb import Database
143
+ from minidb.plugins.query_logger import QueryLogger
144
+
145
+ db = Database("data/example.log")
146
+
147
+ logger = QueryLogger()
148
+
149
+ db.register_plugin("logger", logger)
150
+ db.activate_plugin("logger")
151
+
152
+ db.execute(
153
+ 'INSERT INTO students (name, semester) VALUES ("Ananya", 5)'
154
+ )
155
+
156
+ print(logger.get_logs())
157
+ ```
158
+
159
+ ### Query Statistics
160
+
161
+ ```python
162
+ from minidb.plugins.query_stats import QueryStats
163
+
164
+ stats = QueryStats()
165
+
166
+ db.register_plugin("stats", stats)
167
+ db.activate_plugin("stats")
168
+
169
+ db.execute("SELECT * FROM students")
170
+
171
+ print(stats.get_statistics())
172
+ ```
173
+
174
+ Statistics include execution time, success status, and timestamp.
175
+
176
+ ## 9. Creating a Custom Plugin
177
+
178
+ Developers can extend MiniDB without modifying the core engine.
179
+
180
+ Example:
181
+
182
+ ```python
183
+ class AuditPlugin:
184
+
185
+ def activate(self, database):
186
+ self.database = database
187
+ self.records = []
188
+
189
+ def record_query(self, query):
190
+ self.records.append(query)
191
+ ```
192
+
193
+ Register and activate the plugin:
194
+
195
+ ```python
196
+ audit = AuditPlugin()
197
+
198
+ db.register_plugin("audit", audit)
199
+ db.activate_plugin("audit")
200
+ ```
201
+
202
+ Plugins implementing `record_query()` are automatically notified after successful query execution.
203
+
204
+ See [Plugin Development Guide](docs/PLUGIN_GUIDE.md) for more details.
205
+
206
+ ## 10. Running the Dashboard
207
+
208
+ Install Streamlit if it is not already installed:
209
+
210
+ ```bash
211
+ python -m pip install streamlit
212
+ ```
213
+
214
+ Start the dashboard:
215
+
216
+ ```bash
217
+ streamlit run app.py
218
+ ```
219
+
220
+ ## 11. Running Automated Tests
221
+
222
+ Run the complete test suite:
223
+
224
+ ```bash
225
+ python -m unittest discover -s tests -v
226
+ ```
227
+
228
+ The project currently contains 47 passing automated tests covering database functionality and plugin integration.
229
+
230
+ ## 12. Benchmarking
231
+
232
+ Run the benchmark script:
233
+
234
+ ```bash
235
+ python benchmark.py
236
+ ```
237
+
238
+ An example benchmark run produced the following results:
239
+
240
+ | Dataset Size | Full Scan (ms) | Indexed Query (ms) |
241
+ |---:|---:|---:|
242
+ | 100 | 0.2376 | 0.0929 |
243
+ | 1,000 | 1.2538 | 0.0637 |
244
+ | 5,000 | 6.0168 | 0.0635 |
245
+
246
+ These are example measurements from one run. Actual performance depends on the hardware, dataset, and execution conditions.
247
+
248
+ ## 13. Project Structure
249
+
250
+ ```text
251
+ minidb_starter/
252
+ │
253
+ ├── minidb/
254
+ │ ├── __init__.py
255
+ │ ├── database.py
256
+ │ ├── executor.py
257
+ │ ├── index.py
258
+ │ ├── query.py
259
+ │ ├── storage.py
260
+ │ └── plugins/
261
+ │ ├── __init__.py
262
+ │ ├── manager.py
263
+ │ ├── query_logger.py
264
+ │ └── query_stats.py
265
+ │
266
+ ├── tests/
267
+ ├── examples/
268
+ │ └── custom_plugin.py
269
+ ├── docs/
270
+ │ └── PLUGIN_GUIDE.md
271
+ ├── data/
272
+ ├── app.py
273
+ ├── demo.py
274
+ ├── benchmark.py
275
+ ├── pyproject.toml
276
+ └── README.md
277
+ ```
278
+
279
+ ## 14. Current Limitations
280
+
281
+ - MiniDB is an educational database engine, not a production-grade database.
282
+ - Indexes are maintained in memory and rebuilt when the database is reopened.
283
+ - The query planner uses basic rules rather than a cost-based optimization model.
284
+ - Concurrency protection is thread-level within a database instance; multi-process coordination is not implemented.
285
+ - The recovery mechanism is a simplified operation-log approach, not a full production-grade WAL.
286
+ - Plugin isolation and automatic third-party plugin discovery are not implemented.
287
+ - Supported SQL-like syntax is intentionally limited.
288
+
289
+ ## 15. Future Improvements
290
+
291
+ - More SQL operations and query capabilities.
292
+ - Advanced query optimization.
293
+ - Improved crash recovery.
294
+ - More indexing strategies.
295
+ - Plugin discovery and distribution.
296
+ - Better concurrency and multi-process support.
297
+ - Expanded benchmarking and performance analysis.
298
+
299
+ ## 16. Project Purpose
300
+
301
+ MiniDB is designed to demonstrate how database engines work internally while providing a reusable Python library and an extensible plugin architecture.
302
+
303
+ It is intended for learning, experimentation, and further development.
@@ -0,0 +1,4 @@
1
+ """MiniDB: a small educational embedded database engine."""
2
+ from .database import Database
3
+
4
+ __all__ = ["Database"]