README
ΒΆ
CommitDB
A Git-backed SQL database engine written in Go. Every transaction is a Git commit, providing built-in version control, complete history, branching, and the ability to restore to any point in time.
Why CommitDB?
- π Full version history - Every change is tracked, nothing is lost
- πΏ Git branching - Experiment in branches, merge when ready
- βͺ Time travel - Restore any table to any previous state
- π Remote sync - Push/pull to GitHub, GitLab, or any Git remote
- π Python support - Native driver for Python applications
Table of Contents
- Features
- Quick Start
- SQL Reference
- Branching & Merging
- Remote Operations
- Programmatic API
- CLI Commands
- Benchmarks
- Architecture
Features
| Category | Features |
|---|---|
| SQL | SELECT, INSERT, UPDATE, DELETE, CREATE/DROP TABLE/DATABASE/INDEX |
| Queries | WHERE, ORDER BY, LIMIT, OFFSET, DISTINCT, GROUP BY, HAVING |
| Aggregates | SUM, AVG, MIN, MAX, COUNT |
| JOINs | INNER, LEFT, RIGHT |
| Bulk I/O | COPY INTO for CSV import/export with custom delimiters |
| Version Control | Branching, merging, snapshots, time-travel restore |
| Remote | Push, pull, fetch with token/SSH/basic authentication |
| Performance | Indexing, in-memory or file-based storage |
| Concurrency | Thread-safe with RWMutex |
| Drivers | Python, Go, TCP/JSON protocol |
Quick Start
Installation
go get github.com/nickyhof/CommitDB
Using the CLI
# Build the CLI
go build -o commitdb-cli ./cmd/cli
# Run with in-memory storage
./commitdb-cli
# Run with file-based persistence
./commitdb-cli -baseDir=/path/to/data
Docker
# Pull from GitHub Container Registry
docker pull ghcr.io/nickyhof/commitdb:latest
# Run with in-memory storage
docker run -p 3306:3306 ghcr.io/nickyhof/commitdb
# Run with persistent storage
docker run -p 3306:3306 -v /path/to/data:/data ghcr.io/nickyhof/commitdb
# Run with TLS
docker run -p 3306:3306 \
-v /path/to/certs:/certs \
ghcr.io/nickyhof/commitdb \
--tls-cert /certs/cert.pem --tls-key /certs/key.pem
# Run with JWT authentication
docker run -p 3306:3306 -v /path/to/data:/data \
ghcr.io/nickyhof/commitdb \
--jwt-secret "your-secret" --jwt-issuer "https://auth.example.com"
Using the SQL Server
# Build the server
go build -o commitdb-server ./cmd/server
# Run on default port (3306)
./commitdb-server
# Run with custom port and file persistence
./commitdb-server -port 5432 -baseDir=/path/to/data
# Connect with netcat
echo 'CREATE DATABASE test' | nc localhost 3306
echo 'SELECT * FROM test.users' | nc localhost 3306
The server accepts SQL queries (one per line) and returns JSON responses:
{"success":true,"type":"query","result":{"columns":["id","name"],"data":[["1","Alice"]],"records_read":1}}
Server Authentication (JWT)
The server supports optional JWT authentication. When enabled, clients must authenticate before executing queries, and their identity is used for Git commit authorship.
Architecture:
ββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββ
β Identity β β CommitDB β β Client β
β Provider ββββββββ Server ββββββββ (Python/CLI) β
β (Auth0/etc) β β β β β
ββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββ
β β β
β 1. JWKS keys β β
βββββββββββββββββββββββββΊβ β
β β β
β β 2. AUTH JWT <token> β
β βββββββββββββββββββββββββ
β β β
β β 3. Validate + extract β
β β name/email claims β
β β β
β β 4. OK (authenticated) β
β ββββββββββββββββββββββββΊβ
β β β
β β 5. SQL queries with β
β β authenticated β
β β identity for Git β
Server Configuration:
# Run with JWT authentication (HS256 shared secret)
./commitdb-server --jwt-secret "your-shared-secret" --jwt-issuer "https://auth.example.com"
# Without auth (default identity used for all connections)
./commitdb-server
Client Authentication:
# Authenticate via netcat
echo 'AUTH JWT eyJhbGciOiJIUzI1NiIs...' | nc localhost 3306
# Response: {"success":true,"type":"auth","result":{"authenticated":true,"identity":"Alice <[email protected]>"}}
# Then execute queries
echo 'CREATE DATABASE mydb' | nc localhost 3306
Expected JWT Claims:
{
"name": "Alice Smith",
"email": "[email protected]",
"exp": 1706140800
}
Server TLS/SSL Encryption
Enable encrypted connections with TLS:
# Generate self-signed certificate (for development)
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes \
-subj "/CN=localhost"
# Start server with TLS
./commitdb-server --tls-cert cert.pem --tls-key key.pem
# With TLS and JWT authentication
./commitdb-server --tls-cert cert.pem --tls-key key.pem --jwt-secret "your-secret"
# Test with openssl
openssl s_client -connect localhost:3306
Python client with SSL:
from commitdb import CommitDB
# SSL with certificate verification
db = CommitDB('localhost', 3306, use_ssl=True, ssl_ca_cert='cert.pem')
db.connect()
# SSL without verification (dev only)
db = CommitDB('localhost', 3306, use_ssl=True, ssl_verify=False)
db.connect()
# SSL + JWT authentication
db = CommitDB('localhost', 3306,
use_ssl=True, ssl_ca_cert='cert.pem',
jwt_token='eyJhbG...')
db.connect()
Python Driver
pip install commitdb
Remote mode (connect to server):
from commitdb import CommitDB
with CommitDB('localhost', 3306) as db:
db.execute('CREATE DATABASE mydb')
result = db.query('SELECT * FROM mydb.users')
for row in result:
print(row)
Embedded mode (no server required):
from commitdb import CommitDBLocal
# In-memory database
with CommitDBLocal() as db:
db.execute('CREATE DATABASE mydb')
db.execute('CREATE TABLE mydb.users (id INT PRIMARY KEY, name STRING)')
db.execute("INSERT INTO mydb.users (id, name) VALUES (1, 'Alice')")
result = db.query('SELECT * FROM mydb.users')
# File-based persistence
with CommitDBLocal('/path/to/data') as db:
db.execute('CREATE DATABASE mydb')
See drivers/python/README.md for full documentation.
Example Session
βββββββββββββββββββββββββββββββββββββββββ
β CommitDB v1.5.0 β
β Git-backed SQL Database Engine β
βββββββββββββββββββββββββββββββββββββββββ
commitdb> CREATE DATABASE myapp;
commitdb> CREATE TABLE myapp.users (id INT PRIMARY KEY, name STRING, email STRING);
commitdb> INSERT INTO myapp.users (id, name, email) VALUES (1, 'Alice', '[email protected]');
commitdb> SELECT * FROM myapp.users;
+----+-------+-------------------+
| id | name | email |
+----+-------+-------------------+
| 1 | Alice | [email protected] |
+----+-------+-------------------+
SQL Reference
Data Types
| Type | Description | Example Values |
|---|---|---|
INT / INTEGER |
64-bit signed integer | 42, -100, 0 |
FLOAT / DOUBLE / REAL |
64-bit floating-point number | 3.14, -0.5, 1.0 |
STRING / VARCHAR |
Variable-length text (short) | 'hello', 'Alice' |
TEXT |
Variable-length text (long) | Long text content |
BOOL / BOOLEAN |
Boolean value | true, false |
DATE |
Date only (YYYY-MM-DD) | '2024-06-15' |
TIMESTAMP / DATETIME |
Date and time (YYYY-MM-DD HH:MM:SS) | '2024-06-15 14:30:00' |
JSON |
JSON object or array (validated) | '{"name":"Alice"}' |
Data Definition
-- Databases
CREATE DATABASE mydb;
DROP DATABASE mydb;
SHOW DATABASES;
-- Tables
CREATE TABLE mydb.users (
id INT PRIMARY KEY,
name STRING,
email STRING,
age INT,
active BOOL,
birth_date DATE, -- Date only (YYYY-MM-DD)
created TIMESTAMP, -- Date + time (YYYY-MM-DD HH:MM:SS)
metadata JSON -- JSON object or array
);
DROP TABLE mydb.users;
SHOW TABLES IN mydb;
DESCRIBE mydb.users;
-- Indexes
CREATE INDEX idx_name ON mydb.users(name);
CREATE UNIQUE INDEX idx_email ON mydb.users(email);
DROP INDEX idx_name ON mydb.users;
SHOW INDEXES ON mydb.users;
-- Alter Table
ALTER TABLE mydb.users ADD COLUMN phone STRING;
ALTER TABLE mydb.users DROP COLUMN phone;
ALTER TABLE mydb.users MODIFY COLUMN name TEXT;
ALTER TABLE mydb.users RENAME COLUMN name TO username;
Data Manipulation
-- Insert (single row)
INSERT INTO mydb.users (id, name, email) VALUES (1, 'Alice', '[email protected]');
INSERT INTO mydb.users (id, name, created) VALUES (2, 'Bob', NOW()); -- Auto timestamp
-- Bulk Insert (multiple rows in one statement)
INSERT INTO mydb.users (id, name, email) VALUES
(3, 'Charlie', '[email protected]'),
(4, 'Diana', '[email protected]'),
(5, 'Eve', '[email protected]');
-- Select
SELECT * FROM mydb.users;
SELECT name, email FROM mydb.users WHERE age > 25;
SELECT * FROM mydb.users ORDER BY name ASC LIMIT 10 OFFSET 5;
SELECT DISTINCT city FROM mydb.users;
-- Update (by primary key)
UPDATE mydb.users SET name = 'Bob' WHERE id = 1;
-- Delete (by primary key)
DELETE FROM mydb.users WHERE id = 1;
Aggregate Functions
SELECT COUNT(*) FROM mydb.orders;
SELECT SUM(amount) FROM mydb.orders;
SELECT AVG(price) FROM mydb.products;
SELECT MIN(age), MAX(age) FROM mydb.users;
-- With GROUP BY
SELECT category, SUM(amount) FROM mydb.orders GROUP BY category;
SELECT city, COUNT(id) FROM mydb.users GROUP BY city HAVING COUNT(id) > 10;
Joins
-- Inner Join
SELECT * FROM mydb.orders
INNER JOIN mydb.customers ON customer_id = id;
-- Left Join
SELECT o.id, c.name FROM mydb.orders o
LEFT JOIN mydb.customers c ON o.customer_id = c.id;
-- Right Join
SELECT * FROM mydb.products
RIGHT JOIN mydb.categories ON category_id = id;
String Functions
-- Case conversion
SELECT UPPER(name) FROM mydb.users;
SELECT LOWER(email) FROM mydb.users;
-- String manipulation
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM mydb.users;
SELECT SUBSTRING(name, 1, 3) FROM mydb.users; -- First 3 characters
SELECT TRIM(description) FROM mydb.products;
SELECT LENGTH(name) FROM mydb.users;
SELECT REPLACE(text, 'old', 'new') FROM mydb.documents;
-- With alias
SELECT UPPER(name) AS uppercase_name FROM mydb.users;
Date Functions
-- Current date/time
SELECT NOW() FROM mydb.events;
-- Extract date parts
SELECT YEAR(created_at) FROM mydb.events;
SELECT MONTH(created_at) FROM mydb.events;
SELECT DAY(created_at) FROM mydb.events;
SELECT HOUR(created_at) FROM mydb.events;
-- Date arithmetic
SELECT DATE_ADD(created_at, 7, 'DAY') FROM mydb.events; -- Add 7 days
SELECT DATE_SUB(created_at, 1, 'MONTH') FROM mydb.events; -- Subtract 1 month
SELECT DATEDIFF(end_date, start_date) FROM mydb.events; -- Days between
-- Format and extract
SELECT DATE(created_at) FROM mydb.events; -- Just the date
SELECT DATE_FORMAT(created_at, '%Y-%m-%d') FROM mydb.events;
JSON Data Type
-- Create table with JSON column
CREATE TABLE mydb.documents (
id INT PRIMARY KEY,
name STRING,
data JSON
);
-- Insert JSON data (validated on insert)
INSERT INTO mydb.documents (id, name, data) VALUES
(1, 'doc1', '{"name":"Alice","age":30,"tags":["admin"]}');
-- Extract values using JSON path expressions
SELECT JSON_EXTRACT(data, '$.name') FROM mydb.documents; -- Returns 'Alice'
SELECT JSON_EXTRACT(data, '$.age') FROM mydb.documents; -- Returns '30'
SELECT JSON_EXTRACT(data, '$.tags') FROM mydb.documents; -- Returns '["admin"]'
-- Other JSON functions
SELECT JSON_KEYS(data) FROM mydb.documents; -- Returns 'age,name,tags'
SELECT JSON_LENGTH(data) FROM mydb.documents; -- Returns '3'
SELECT JSON_TYPE(data) FROM mydb.documents; -- Returns 'object'
SELECT JSON_CONTAINS(data, 'Alice') FROM mydb.documents; -- Returns '1' if found
Bulk Import/Export (COPY INTO)
-- Export table to CSV file (with header)
COPY INTO '/path/to/users.csv' FROM mydb.users;
-- Export with options
COPY INTO '/path/to/data.csv' FROM mydb.users WITH (HEADER = TRUE, DELIMITER = ',');
-- Import CSV file into table (expects header by default)
COPY INTO mydb.users FROM '/path/to/users.csv';
-- Import with custom options
COPY INTO mydb.users FROM '/path/to/data.tsv' WITH (HEADER = TRUE, DELIMITER = '\t');
Functions Reference
| Category | Function | Description |
|---|---|---|
| Aggregate | COUNT(*) |
Count rows |
SUM(column) |
Sum numeric values | |
AVG(column) |
Average of numeric values | |
MIN(column) |
Minimum value | |
MAX(column) |
Maximum value | |
| String | UPPER(str) |
Convert to uppercase |
LOWER(str) |
Convert to lowercase | |
CONCAT(a, b, ...) |
Concatenate strings | |
SUBSTRING(str, start, len) |
Extract substring (1-indexed) | |
TRIM(str) |
Remove leading/trailing whitespace | |
LENGTH(str) |
String length | |
REPLACE(str, old, new) |
Replace occurrences | |
| Date | NOW() |
Current date/time |
DATE(timestamp) |
Extract date part | |
YEAR(date), MONTH(date), DAY(date) |
Extract date components | |
HOUR(ts), MINUTE(ts), SECOND(ts) |
Extract time components | |
DATE_ADD(date, n, unit) |
Add interval (DAY, MONTH, YEAR, HOUR, etc.) | |
DATE_SUB(date, n, unit) |
Subtract interval | |
DATEDIFF(date1, date2) |
Days between dates | |
DATE_FORMAT(date, format) |
Format date (%Y, %m, %d, %H, %i, %s) | |
| JSON | JSON_EXTRACT(json, path) |
Extract value using path ($.key.nested) |
JSON_KEYS(json) |
Get comma-separated keys | |
JSON_LENGTH(json) |
Number of elements | |
JSON_TYPE(json) |
Type (object, array, string, number, boolean, null) | |
JSON_CONTAINS(json, value) |
Returns 1 if value exists |
Transactions
BEGIN;
-- ... operations ...
COMMIT;
-- or
ROLLBACK;
Snapshots & Restore
CommitDB's Git-backed storage enables powerful version control features:
// Create a named snapshot (git tag) at current state
persistence.Snapshot("v1.0.0", nil)
// Create a snapshot at a specific transaction
persistence.Snapshot("before-migration", &transaction)
// Recover to a named snapshot (resets all data)
persistence.Recover("v1.0.0")
// Restore to a specific transaction
persistence.Restore(transaction, nil, nil)
// Restore only a specific database
db := "mydb"
persistence.Restore(transaction, &db, nil)
// Restore only a specific table
table := "users"
persistence.Restore(transaction, &db, &table)
Branching & Merging
Create isolated branches to experiment with changes, then merge back:
-- Create a new branch
CREATE BRANCH feature_x
-- Switch to the branch
CHECKOUT feature_x
-- Make changes (only visible on this branch)
INSERT INTO mydb.users (id, name) VALUES (100, 'NewUser');
ALTER TABLE mydb.users ADD COLUMN email STRING;
-- See all branches
SHOW BRANCHES
-- Switch back to main branch
CHECKOUT master
-- Merge changes from feature branch (auto-resolves conflicts with Last-Writer-Wins)
MERGE feature_x
-- Or merge with manual conflict resolution
MERGE feature_x WITH MANUAL RESOLUTION
-- View pending conflicts
SHOW MERGE CONFLICTS
-- Resolve conflicts
RESOLVE CONFLICT mydb.users.1 USING HEAD -- Keep current branch value
RESOLVE CONFLICT mydb.users.1 USING SOURCE -- Keep feature branch value
RESOLVE CONFLICT mydb.users.1 USING '{"custom":"value"}' -- Custom value
-- Complete the merge
COMMIT MERGE
-- Or abort the merge
ABORT MERGE
Merge Strategies:
| Strategy | Description |
|---|---|
| Row-level (default) | Auto-resolves conflicts using Last-Writer-Wins (later commit wins) |
| Manual | Pauses on conflicts, requires resolution before completing |
Go API:
// Create branch at current HEAD
persistence.Branch("feature", nil)
// Create branch from specific transaction
persistence.Branch("old-state", &transaction)
// Switch branches
persistence.Checkout("feature")
// List all branches
branches, _ := persistence.ListBranches()
// Get current branch
current, _ := persistence.CurrentBranch()
// Merge with default strategy (row-level, Last-Writer-Wins)
txn, err := persistence.Merge("feature", identity)
// Merge with options
result, err := persistence.MergeWithOptions("feature", identity, ps.MergeOptions{
Strategy: ps.MergeStrategyManual,
})
// Handle pending merge
if result.Pending {
for _, conflict := range result.Unresolved {
// Resolve each conflict
persistence.ResolveConflict(conflict.Database, conflict.Table, conflict.Key, resolution)
}
persistence.CompleteMerge(identity)
}
// Or abort
persistence.AbortMerge()
// Delete branch
persistence.DeleteBranch("feature")
Remote Operations
Push and pull branches to/from remote Git repositories:
-- Add a remote
CREATE REMOTE origin 'https://github.com/user/repo.git'
CREATE REMOTE upstream '[email protected]:upstream/repo.git'
-- List remotes
SHOW REMOTES
-- Remove a remote
DROP REMOTE upstream
-- Push to remote (default: origin, current branch)
PUSH
PUSH TO origin
PUSH TO origin BRANCH feature
-- Pull from remote
PULL
PULL FROM origin
PULL FROM origin BRANCH master
-- Fetch without merging
FETCH
FETCH FROM upstream
Authentication:
-- Token-based (GitHub, GitLab, etc.)
PUSH WITH TOKEN 'ghp_xxxxxxxxxxxx'
PULL FROM origin WITH TOKEN 'ghp_xxxxxxxxxxxx'
-- SSH key authentication
PUSH WITH SSH KEY '/path/to/id_rsa'
PUSH WITH SSH KEY '/path/to/id_rsa' PASSPHRASE 'mypassword'
-- Basic auth (username/password)
PULL FROM origin WITH USER 'username' PASSWORD 'password'
Go API:
// Add a remote
persistence.AddRemote("origin", "https://github.com/user/repo.git")
// List remotes
remotes, _ := persistence.ListRemotes()
// Remove a remote
persistence.RemoveRemote("origin")
// Push (no auth)
persistence.Push("origin", "master", nil)
// Push with token auth
auth := &ps.RemoteAuth{
Type: ps.AuthTypeToken,
Token: "ghp_xxxxxxxxxxxx",
}
persistence.Push("origin", "master", auth)
// Pull with SSH auth
auth := &ps.RemoteAuth{
Type: ps.AuthTypeSSH,
KeyPath: "/path/to/id_rsa",
Passphrase: "optional_passphrase",
}
persistence.Pull("origin", "master", auth)
// Fetch
persistence.Fetch("origin", nil)
WHERE Operators
| Operator | Example |
|---|---|
= |
WHERE id = 1 |
!=, <> |
WHERE status != 'deleted' |
<, > |
WHERE age > 18 |
<=, >= |
WHERE price <= 100 |
AND |
WHERE age > 18 AND active = true |
OR |
WHERE city = 'NYC' OR city = 'LA' |
IN |
WHERE status IN ('active', 'pending') |
NOT IN |
WHERE NOT category IN ('archived') |
IS NULL |
WHERE email IS NULL |
IS NOT NULL |
WHERE email IS NOT NULL |
LIKE |
WHERE name LIKE 'A%' |
Programmatic API
package main
import (
"fmt"
"github.com/nickyhof/CommitDB"
"github.com/nickyhof/CommitDB/core"
"github.com/nickyhof/CommitDB/ps"
)
func main() {
// Create persistence layer
persistence, _ := ps.NewMemoryPersistence()
// Or use file-based: persistence, _ := ps.NewFilePersistence("/path/to/data", nil)
// Open database
db := CommitDB.Open(&persistence)
// Create engine with identity (for git commits)
engine := db.Engine(core.Identity{
Name: "MyApp",
Email: "[email protected]",
})
// Execute SQL
result, err := engine.Execute("CREATE DATABASE myapp")
if err != nil {
panic(err)
}
result, _ = engine.Execute("CREATE TABLE myapp.users (id INT PRIMARY KEY, name STRING)")
result, _ = engine.Execute("INSERT INTO myapp.users (id, name) VALUES (1, 'Alice')")
result, _ = engine.Execute("SELECT * FROM myapp.users")
// Display results
result.Display()
}
CLI Commands
| Command | Description |
|---|---|
.help |
Show help message |
.quit, .exit |
Exit the CLI |
.databases |
List all databases |
.tables <db> |
List tables in database |
.use <db> |
Set default database |
.history |
Show command history |
.clear |
Clear screen |
.version |
Show version |
Column Types
| Type | Description |
|---|---|
INT |
Integer values |
STRING |
Short strings |
TEXT |
Long text |
FLOAT |
Floating point |
BOOL |
Boolean (true/false) |
TIMESTAMP |
Date/time values |
Testing
# Run all tests
go test ./...
# Run benchmarks
go test -bench=. ./...
# Run integration tests only
go test -run Integration ./...
Benchmarks
Performance benchmarks run on Apple M1 Pro (v1.5.0):
SQL Parsing (no I/O)
| Benchmark | Time | Memory |
|---|---|---|
| Simple SELECT | 184 ns | 336 B |
| SELECT with WHERE | 282 ns | 389 B |
| SELECT with ORDER BY | 310 ns | 365 B |
| Complex SELECT | 587 ns | 528 B |
| INSERT | 573 ns | 405 B |
| UPDATE | 308 ns | 240 B |
| DELETE | 219 ns | 176 B |
Query Execution (1000 rows, in-memory)
| Benchmark | Time | Throughput |
|---|---|---|
| SELECT * | 2.5 ms | ~400 ops/sec |
| SELECT with WHERE | 2.6 ms | ~385 ops/sec |
| SELECT with ORDER BY | 3.3 ms | ~305 ops/sec |
| SELECT with LIMIT | 2.4 ms | ~415 ops/sec |
| COUNT(*) | 2.4 ms | ~415 ops/sec |
| SUM/AVG/MIN/MAX | 2.5 ms | ~400 ops/sec |
| DISTINCT | 2.5 ms | ~400 ops/sec |
| INSERT | 11.2 ms | ~89 ops/sec |
| UPDATE | 4.9 ms | ~205 ops/sec |
Lexer
| Benchmark | Time | Memory |
|---|---|---|
| Tokenize complex query | 447 ns | 48 B |
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Applications β
β cmd/cli/ CLI application β
β cmd/server/ TCP SQL server with JSON protocol β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β sql/ SQL Layer β
β Lexer: Tokenizes SQL into keywords, identifiers, etc. β
β Parser: Builds AST (statement structs) from tokens β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β db/ Engine Layer β
β Executes parsed statements, handles transactions β
β Returns QueryResult or CommitResult β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β op/ Operations Layer β
β High-level wrappers for database and table operations β
β DatabaseOp: Create, Get, Drop, Restore, TableNames β
β TableOp: Get, Put, Delete, Scan, Keys, Count β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β ps/ Persistence Layer β
β Git-backed storage with go-git library β
β CRUD, branching, merging, snapshots, transactions β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β Git Repository β
β Every transaction = Git commit β
β Tables stored as JSON files in directories β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Package Summary
| Package | Purpose |
|---|---|
core/ |
Shared types: Identity, Table, Column, Database |
sql/ |
SQL lexer and parser, statement types |
db/ |
Query execution engine, result types |
op/ |
Database/table operations wrapper (convenience methods) |
ps/ |
Git-backed persistence, branching, merging, remotes |
cmd/cli/ |
Interactive command-line interface |
cmd/server/ |
TCP server with JSON protocol |
bindings/ |
CGO bindings for embedded use |
drivers/python/ |
Python client library |
Documentation
ΒΆ
Overview ΒΆ
Package CommitDB provides a Git-backed SQL database engine.
CommitDB stores data using Git as the underlying storage mechanism, making every transaction a Git commit. This provides built-in version control, history tracking, and the ability to restore to any point in time.
Quick Start ΒΆ
Create an in-memory database:
persistence, _ := ps.NewMemoryPersistence()
db := CommitDB.Open(&persistence)
engine := db.Engine(core.Identity{Name: "App", Email: "[email protected]"})
engine.Execute("CREATE DATABASE mydb")
engine.Execute("CREATE TABLE mydb.users (id INT PRIMARY KEY, name STRING)")
engine.Execute("INSERT INTO mydb.users (id, name) VALUES (1, 'Alice')")
result, _ := engine.Execute("SELECT * FROM mydb.users")
result.Display()
Supported SQL ΒΆ
CommitDB supports a subset of SQL including:
- CREATE/DROP DATABASE
- CREATE/DROP TABLE
- CREATE/DROP INDEX
- INSERT, SELECT, UPDATE, DELETE
- WHERE with comparison operators
- ORDER BY, LIMIT, OFFSET
- Aggregate functions: SUM, AVG, MIN, MAX, COUNT
- GROUP BY, HAVING
- JOINs: INNER, LEFT, RIGHT
- DISTINCT
- Transactions: BEGIN, COMMIT, ROLLBACK
Index ΒΆ
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
cli
command
|
|
|
server
command
Package main provides authentication for the CommitDB TCP server.
|
Package main provides authentication for the CommitDB TCP server. |
|
Package core provides core types used throughout CommitDB.
|
Package core provides core types used throughout CommitDB. |
|
Package db provides the SQL execution engine for CommitDB.
|
Package db provides the SQL execution engine for CommitDB. |
|
Package op provides high-level operations for working with CommitDB databases and tables.
|
Package op provides high-level operations for working with CommitDB databases and tables. |
|
Package ps provides the persistence layer for CommitDB.
|
Package ps provides the persistence layer for CommitDB. |
|
Package sql provides SQL lexing and parsing for CommitDB.
|
Package sql provides SQL lexing and parsing for CommitDB. |