tinySQL is an embedded SQL engine with in-memory and persistent storage. It supports joins, recursive CTEs, window functions, full-text and vector search, and geospatial queries. Use it from Go, C, Python, Rust, or Swift, or run it in the browser with WebAssembly.
Browser playground · Documentation
Building or embedding tinySQL requires Go 1.27.3 or newer.
go run ./cmd/tinysql -mode csv :memory: "SELECT 'hello' AS message;"See the CLI guide for SQL files, output formats, and persistent databases.
From your Go module, add tinySQL.
go get github.com/SimonWaldherr/tinySQL@latestThis program creates an in-memory database and queries it with a bound parameter.
package main
import (
"context"
"fmt"
tinysql "github.com/SimonWaldherr/tinySQL"
)
func main() {
ctx := context.Background()
db := tinysql.NewDB()
defer db.Close()
if _, err := tinysql.ExecScript(ctx, db, "default", `
CREATE TABLE users (id INT PRIMARY KEY, name TEXT);
INSERT INTO users VALUES (1, 'Ada'), (2, 'Grace');`); err != nil {
panic(err)
}
// Bind values with ?, $1 or :1 instead of formatting SQL text.
result, err := tinysql.ExecSQLArgs(ctx, db, "default",
"SELECT id, name FROM users WHERE id >= ? ORDER BY id", 1)
if err != nil {
panic(err)
}
for _, row := range result.Rows {
fmt.Println(row["id"], row["name"])
}
}ExecScript applies each statement in order and stops at the first error.
Use database/sql when the statements need to commit or roll back together.
See the transaction example
and the language bindings guide.
| Task | Guides |
|---|---|
| Write and inspect SQL | SQL examples, function reference, query analyzer |
| Import, batch, and analyze data | File queries, cached inserts, analytical snapshots |
| Build a search or RAG pipeline | BM25, vector search, and hybrid retrieval |
| Persist and serve a database | Storage modes and backups, HTTP/gRPC server |
| Validate scripts and operate a daemon | SQL checks in CI, Admin flush and Prometheus metrics |
| Schedule work or deliver events | Jobs and transactional event log, delayed inserts |
| Work with maps and routing | Geospatial formats, tile serving, OSM routing |
Find more runnable examples in the demo index and more tools in the command index.
SQLite, GeoPackage, and MBTiles need the sqliteimport build tag; Shapefile
needs shapefile. The tinysql_minimal tag omits optional features for smaller
WASM builds; see the browser build guide.
go test ./...
go vet ./...
make docs-check
make test-bindings # C ABI, Python and RustDevelopment covers builds and tests. See architecture, API stability, and the performance notes for internals, compatibility, and workload-specific benchmarks.
- Use one writer process per database. Server replicas are asynchronous; sharding, automatic failover, multi-primary writes, and distributed transactions are not supported.
- Composite PRIMARY/UNIQUE/FOREIGN KEY, ATTACH/DETACH, VACUUM, partial indexes,
generated columns, and data-modifying CTE bodies are not supported. CHECK,
ON CONFLICT (target) DO UPDATEand SAVEPOINT work, with the limits described in SQL feature gaps. - Secondary indexes accelerate equality/prefix seeks and numeric ranges. Use GEO_SEARCH for indexed point-column bbox/radius queries; ordinary WHERE GEO_DWITHIN(...) predicates are not planner-accelerated.
- GIS validity is structural rather than full topology validation. GEO_DISSOLVE/GEO_UNION_AGG require clean, vertex-aligned adjacent polygons; they are not general polygon-boolean union operations.
- RBAC is coarse and single-table oriented. Table and catalog encryption covers the disk, JSON, Hybrid and Index modes. Operational metadata such as storage manifests remains visible.
See SQL feature gaps for details and current coverage.