A multi-protocol database server with pluggable network protocols and JIT-compiled stored procedure execution.
aul is a database server that:
- Accepts connections via multiple protocols — TDS (SQL Server), PostgreSQL wire protocol, MySQL protocol, HTTP REST, and gRPC
- Loads stored procedures from SQL files — Supporting T-SQL initially, with planned support for other dialects
- Executes procedures dynamically — Using tgpiler's runtime interpreter for flexible execution including dynamic SQL and transactions
- JIT-compiles hot procedures — Automatically transpiles frequently-executed procedures to Go and loads them as plugins for optimised performance
┌─────────────────────────────────────────────────────────────────┐
│ aul Server │
├─────────────────────────────────────────────────────────────────┤
│ Protocol Listeners │
│ ┌─────┐ ┌──────────┐ ┌───────┐ ┌──────┐ ┌──────┐ │
│ │ TDS │ │ Postgres │ │ MySQL │ │ HTTP │ │ gRPC │ │
│ └──┬──┘ └────┬─────┘ └───┬───┘ └──┬───┘ └──┬───┘ │
│ │ │ │ │ │ │
│ └─────────┴─────┬─────┴────────┴────────┘ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Connection Handler │ │
│ │ - Session management │ │
│ │ - Transaction tracking │ │
│ │ - Request routing │ │
│ └─────────────────────────┬───────────────────────────────┘ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Procedure Registry │ │
│ │ - Load from .sql files │ │
│ │ - Hot-reload on changes │ │
│ │ - Metadata extraction │ │
│ └─────────────────────────┬───────────────────────────────┘ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Runtime │ │
│ │ ┌──────────────────┐ ┌──────────────────┐ │ │
│ │ │ Interpreter │ │ JIT Manager │ │ │
│ │ │ (tsqlruntime) │ │ (tgpiler + Go) │ │ │
│ │ └────────┬─────────┘ └────────┬─────────┘ │ │
│ │ │ │ │ │
│ │ └───────────┬───────────┘ │ │
│ │ ▼ │ │
│ │ ┌──────────────────────────────────────────────────┐ │ │
│ │ │ Storage Backend │ │ │
│ │ │ - In-memory (testing) │ │ │
│ │ │ - PostgreSQL, MySQL, SQLite │ │ │
│ │ └──────────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
# Install the server
go install github.com/ha1tch/aul/cmd/aul@latest
# Install the interactive CLI
go install github.com/ha1tch/aul/cmd/iaul@latestOr build from source:
git clone https://github.com/ha1tch/aul.git
cd aul
go build -o aul ./cmd/aul
go build -o iaul ./cmd/iaulaul provides two commands:
| Command | Description |
|---|---|
aul |
The database server |
iaul |
Interactive SQL client (like psql for PostgreSQL) |
# Start with HTTP API (default)
aul --http-port 8080
# Start with SQL Server compatible TDS protocol
aul --tds-port 1433
# Multiple protocols
aul --tds-port 1433 --pg-port 5432 --http-port 8080
# Custom procedure directory with hot-reload
aul -d ./my_procedures -w
# Disable JIT compilation
aul --jit=falseiaul is a modern SQL client with readline support, tab completion, and psql-style commands.
# Connect interactively
iaul --host localhost --user sa --password secret --database mydb
# Execute SQL and exit
iaul -e "SELECT * FROM users" --format json
# Execute a script file
iaul -f schema.sql --silent && echo "Schema created"
# Export to CSV
iaul -e "SELECT * FROM orders" --format csv --quiet > orders.csvFeatures:
- Readline support (arrow keys, Ctrl+R history search)
- Tab completion for SQL keywords, tables, and columns
- psql-style commands (
\dt,\d table,\i file,\o file) - Multiple output formats (default, ascii, unicode, csv, json)
- Variable substitution (
:varname,$(varname)) - Pager support for large result sets
- Persistent command history
- Configurable macros
See cmd/iaul/README.md for full documentation.
Server Options:
-c, --config <file> Configuration file path
-d, --proc-dir <path> Directory containing stored procedures
-w, --watch Watch for file changes and hot-reload
Protocol Listeners:
--tds-port <port> TDS protocol port (SQL Server compatible)
--pg-port <port> PostgreSQL wire protocol port
--mysql-port <port> MySQL wire protocol port
--http-port <port> HTTP REST API port (default: 8080)
--grpc-port <port> gRPC port
Runtime Options:
--dialect <n> Default SQL dialect: tsql, postgres, mysql
--jit Enable JIT compilation (default: true)
--jit-threshold <n> Executions before JIT (default: 100)
--max-conns <n> Max concurrent connections (default: 1000)
--exec-timeout <dur> Execution timeout (default: 30s)
# /etc/aul/config.yaml
server:
name: my-aul-server
proc_dir: /var/lib/aul/procedures
watch_changes: true
listeners:
- protocol: tds
port: 1433
- protocol: http
port: 8080
tls:
enabled: true
cert_file: /etc/aul/server.crt
key_file: /etc/aul/server.key
runtime:
dialect: tsql
jit_enabled: true
jit_threshold: 100
max_concurrency: 500
exec_timeout: 30s
storage:
type: postgres
host: localhost
port: 5432
database: aul_data
username: aul
password: ${AUL_DB_PASSWORD}Place SQL files in the procedures directory:
-- procedures/usp_GetCustomer.sql
CREATE PROCEDURE usp_GetCustomer
@CustomerID INT
AS
BEGIN
SELECT CustomerID, Name, Email, CreatedAt
FROM Customers
WHERE CustomerID = @CustomerID;
ENDProcedures are automatically loaded at startup and can be hot-reloaded when files change (with -w flag).
aul automatically JIT-compiles procedures that are executed frequently:
- Execution tracking — Each procedure call increments an execution counter
- Threshold check — When counter exceeds
--jit-threshold, compilation is triggered - Transpilation — tgpiler converts T-SQL to Go code
- Compilation — Go compiler builds a plugin (.so)
- Hot-swap — Plugin is loaded and future calls use compiled code
The interpreter is always available as fallback for:
- Dynamic SQL (
EXEC(@sql)) - Procedures below the JIT threshold
- Compilation failures
aul/
├── cmd/aul/ # CLI entry point
├── server/ # Core server orchestration
├── protocol/ # Protocol listener implementations
│ ├── tds/ # TDS (SQL Server) protocol
│ ├── postgres/ # PostgreSQL wire protocol
│ ├── mysql/ # MySQL protocol
│ ├── http/ # HTTP REST API
│ └── grpc/ # gRPC
├── procedure/ # Procedure loading and registry
├── runtime/ # Execution runtime
├── jit/ # JIT compilation manager
├── storage/ # Storage backend implementations
├── pkg/
│ ├── version/ # Version information
│ ├── log/ # Structured logging system
│ └── errors/ # Rich error types with codes
├── docs/ # Documentation
└── tests/ # Integration tests
aul provides a comprehensive structured logging system with multiple categories:
- system — Server lifecycle, configuration, resource management
- execution — Procedure calls, query execution, JIT compilation
- application — Business logic, procedure loading, protocol handling
- audit — Security-relevant events (authentication, authorisation)
- performance — Timing, throughput, resource utilisation
Configure logging via CLI:
# Set log level (debug, info, warn, error)
aul --log-level debug
# Set output format (text, json)
aul --log-format jsonExample log output (text format):
2025-01-28 10:30:15.123 INFO [system] server starting
2025-01-28 10:30:15.125 DEBUG [application] procedure loaded name=dbo.usp_GetCustomer
2025-01-28 10:30:15.200 INFO [system] server started state=running procedures=5 listeners=1
Example log output (JSON format):
{"time":"2025-01-28T10:30:15.123Z","level":"INFO","category":"system","message":"server started","fields":{"procedures":5,"listeners":1}}aul uses structured errors with codes for programmatic handling:
| Range | Category | Example Codes |
|---|---|---|
| 1xxx | Configuration | E1001 (invalid), E1002 (missing) |
| 2xxx | Connection | E2001 (failed), E2003 (timeout), E2005 (handshake) |
| 3xxx | Procedure | E3001 (not found), E3003 (parse error) |
| 4xxx | Execution | E4001 (failed), E4002 (timeout), E4004 (nesting limit) |
| 5xxx | Storage | E5001 (connect), E5002 (query), E5004 (transaction) |
| 6xxx | JIT | E6002 (queue full), E6003 (transpile), E6004 (compile) |
| 9xxx | Internal | E9001 (internal), E9002 (not implemented) |
Errors include context fields for debugging:
E3001: procedure not found: usp_Missing
Operation: ConnectionHandler.handleExec
Context:
procedure: usp_Missing
- jackc/pgx/v5 — PostgreSQL wire protocol (pgproto3)
- shopspring/decimal — Arbitrary-precision decimals
Vendored from tgpiler/tsqlparser:
- tsqlparser v0.5.2 — Full T-SQL parser (AST generation)
- tsqlruntime — T-SQL runtime interpreter
| Component | Status |
|---|---|
| HTTP REST API | ✓ Working |
| PostgreSQL wire protocol | ✓ Working (accepts connections, basic handshake) |
| TDS (SQL Server) protocol | ✓ Working (login, TLS/login-only encryption, queries) |
| MySQL protocol | Not implemented |
| gRPC | Not implemented |
| Procedure loading | ✓ Full AST parsing via tsqlparser |
| T-SQL Parser | ✓ Integrated (tsqlparser v0.5.2) |
| Interpreter (tsqlruntime) | ✓ Integrated (from tgpiler v0.5.2) |
| JIT compilation | ✓ Architecture complete, pending tgpiler integration |
| Storage backends | ✓ SQLite (default), In-memory |
| Structured logging | ✓ Working |
| Error codes | ✓ Working |
See docs/INDEX.md for the full documentation index.
Key documents:
- 001 - Stored Procedure Architecture — Execution paths and dialect handling
- 002 - Storage and Translation — Hierarchy, tenancy, delegation, ACL design
- 003 - Development Plan — Phased roadmap to v1.0
- 004 - JIT Architecture — JIT pipeline design and implementation
- SQLite Backend — Type mappings, decimal handling, and limitations
GPL v3.0 https://www.gnu.org/licenses/gpl-3.0.en.html
Copyright (c) 2026 haitch