yamlbase
A lightweight SQL server that serves YAML-defined tables over standard SQL protocols
Yamlbase is a lightweight SQL server designed for local development and testing. Define your database schema and data in simple YAML files and serve them over standard PostgreSQL or MySQL wire protocols.
Features
- 🚀 Quick Setup - Define your database schema and data in simple YAML files
- 🐘 PostgreSQL Protocol - Compatible with standard PostgreSQL clients and drivers
- 🐬 MySQL Protocol - Full MySQL wire protocol support for MySQL clients
- 📊 SQL Support - SELECT queries with WHERE, ORDER BY, LIMIT, and basic JOINs
- 🔄 Hot Reload - Automatically reload data when YAML files change
- 🛠️ Development Friendly - Perfect for testing database integrations locally
- ⚡ Lightweight - Minimal resource usage, fast startup
Installation
From Crates.io
From Source
Using Docker
Quick Start
- Create a YAML file defining your database:
database:
name: "test_db"
tables:
users:
columns:
id: "INTEGER PRIMARY KEY"
name: "VARCHAR(100) NOT NULL"
email: "VARCHAR(255) UNIQUE"
created_at: "TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
is_active: "BOOLEAN DEFAULT true"
data:
- id: 1
name: "John Doe"
email: "john@example.com"
created_at: "2024-01-15 10:30:00"
is_active: true
- id: 2
name: "Jane Smith"
email: "jane@example.com"
created_at: "2024-01-16 14:22:00"
is_active: false
- Start the server:
# PostgreSQL protocol (default)
# MySQL protocol
- Connect with your preferred SQL client:
PostgreSQL:
# Using psql
# Password: password (default)
MySQL:
# Using mysql client
- Run SQL queries:
SELECT * FROM users WHERE is_active = true;
SELECT name, email FROM users ORDER BY created_at DESC LIMIT 5;
Command Line Options
yamlbase [OPTIONS]
Options:
-f, --file <FILE> Path to YAML database file
-p, --port <PORT> Port to listen on (default: 5432 for postgres, 3306 for mysql)
--bind-address <ADDR> Address to bind to [default: 0.0.0.0]
--protocol <PROTOCOL> SQL protocol: postgres, mysql, sqlserver [default: postgres]
-u, --username <USER> Authentication username [default: admin]
-P, --password <PASS> Authentication password [default: password]
--hot-reload Enable hot-reloading of YAML file changes
-v, --verbose Enable verbose logging
--log-level <LEVEL> Set log level: debug, info, warn, error [default: info]
-h, --help Print help
YAML Database Format
Supported Data Types
INTEGER/INT/BIGINT/SMALLINTVARCHAR(n)- Variable-length string with max lengthTEXT- Unlimited textTIMESTAMP/DATETIMEDATETIMEBOOLEAN/BOOLDECIMAL(p,s)/NUMERIC(p,s)- Fixed-point decimalFLOAT/REALDOUBLEUUIDJSON/JSONB
Column Constraints
PRIMARY KEY- Unique identifier for the tableNOT NULL- Column cannot contain NULL valuesUNIQUE- All values must be uniqueDEFAULT <value>- Default value for new rowsREFERENCES table(column)- Foreign key reference
Special Default Values
CURRENT_TIMESTAMP- Current date and timetrue/false- Boolean values- String, number, or NULL values
SQL Support
Currently Supported
SELECTqueries with column selectionWHEREclauses with comparison operators (=,!=,<,>,<=,>=)AND/ORlogical operatorsORDER BYwithASC/DESCLIMITfor result pagination- Wildcard selection (
SELECT *) - Basic table joins (comma-separated tables in FROM)
Examples
-- Select with conditions
SELECT * FROM users WHERE is_active = true AND age > 25;
-- Order and limit
SELECT name, email FROM users ORDER BY created_at DESC LIMIT 10;
-- Join tables
SELECT u.name, o.total_amount
FROM users u, orders o
WHERE u.id = o.user_id;
Not Yet Supported
INSERT,UPDATE,DELETEoperations- Aggregate functions (
COUNT,SUM,AVG, etc.) GROUP BYandHAVING- Subqueries
JOINsyntax (use comma-separated tables instead)- Transactions
Development
Running Tests
Building
Running with Hot Reload
Integration Examples
Python
PostgreSQL:
=
=
=
MySQL:
=
=
=
Node.js
PostgreSQL:
const = require;
const client = ;
await client.;
const res = await client.;
MySQL:
const mysql = require;
const connection = mysql.;
connection.;
Go
PostgreSQL:
import (
"database/sql"
_ "github.com/lib/pq"
)
db, err := sql.Open("postgres",
"host=localhost port=5432 user=admin password=password dbname=test_db sslmode=disable")
rows, err := db.Query("SELECT name, email FROM users")
MySQL:
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
db, err := sql.Open("mysql", "admin:password@tcp(127.0.0.1:3306)/test_db")
rows, err := db.Query("SELECT name, email FROM users")
Use Cases
- Local Development - Test database-dependent code without setting up PostgreSQL
- CI/CD Testing - Lightweight database for integration tests
- Prototyping - Quickly iterate on database schemas
- Education - Learn SQL without database installation
- Demo Applications - Ship demos with embedded test data
Performance
- Handles up to 10,000 records per table efficiently
- Supports 10+ concurrent connections
- Query response time typically under 100ms
- Memory usage under 100MB for typical test datasets
Limitations
- Read-only operations (no INSERT/UPDATE/DELETE yet)
- Basic SQL feature set
- No transaction support
- No indexes beyond primary keys
- SQL Server protocol not yet implemented
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development
# Run tests
# Run with hot-reload
# Run benchmarks
# Run all CI checks
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
Yamlbase is inspired by the need for simple, lightweight database solutions for testing and development. Special thanks to all contributors and the Rust community.