How antonmedv/elephpantdb works
ElephpantDB is a single-file PHP SQL database with both a CLI API and a JSON-over-HTTP endpoint. The main workflow accepts one SQL statement and optional parameters, tokenizes and parses it, validates and executes it, then returns rows, an affected-row count, or an error. Its documented capabilities include schema and data changes, indexed equality lookups, persistence and recovery, locking, and vacuuming. Most implementation is in one file; the excerpts are partial, so uncertain internal call wiring is omitted.
Main entry points: elephpantdb.php Statement executor
Components 19
Interfaces
- HTTP endpoint
elephpantdb.php - Database API
elephpantdb.php - Token authentication
elephpantdb.php - Query result
elephpantdb.php
SQL engine
- SQL tokenizer
elephpantdb.php - SQL parser
elephpantdb.php - Parameter binder
elephpantdb.php - Schema validation
elephpantdb.php - Predicate evaluation
elephpantdb.php - Index planning
elephpantdb.php - Statement executor
elephpantdb.php
Table storage
- Table schema
elephpantdb.php - Append-only heap
elephpantdb.php - Hash indexes
elephpantdb.php
Integrity and maintenance
- Table locking
elephpantdb.php - Recovery and checksums
elephpantdb.php - Vacuum and rebuild
elephpantdb.php
Other components
- SQL client
- Local filesystem
Connections 27
- SQL client → HTTP endpoint: posts SQL
- SQL client → Database API: executes SQL
- HTTP endpoint → Token authentication: checks token
- HTTP endpoint → Database API: dispatches request
- Database API → SQL tokenizer: tokenizes SQL
- Database API → SQL parser: parses statement
- Database API → Parameter binder: binds parameters
- Database API → Statement executor: executes statement
- SQL parser → Schema validation: validates structure
- Statement executor → Schema validation: validates values
- Statement executor → Predicate evaluation: checks rows
- Statement executor → Index planning: selects index
- Statement executor → Table schema: reads or writes
- Statement executor → Append-only heap: reads or mutates
- Statement executor → Hash indexes: looks up or updates
- Statement executor → Table locking: locks table
- Statement executor → Vacuum and rebuild: runs vacuum
- Statement executor → Query result: produces result
- Append-only heap → Local filesystem: persists records
- Table schema → Local filesystem: persists schema
- Hash indexes → Local filesystem: persists indexes
- Table locking → Local filesystem: uses flock
- Append-only heap → Recovery and checksums: checks and repairs
- Recovery and checksums → Local filesystem: truncates tail
- Vacuum and rebuild → Append-only heap: rewrites live rows
- Vacuum and rebuild → Hash indexes: rebuilds indexes
- Vacuum and rebuild → Table schema: reads schema