MCPcopy Index your code
hub / github.com/chaisql/chai

github.com/chaisql/chai @v0.18.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.18.0 ↗ · + Follow
1,850 symbols 8,486 edges 222 files 584 documented · 32% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

ChaiSQL

ChaiSQL is a modern embedded SQL database, written in pure Go, with a PostgreSQL-inspired API. It’s designed for developers who want the familiarity of Postgres with the simplicity of an embedded database.

Build Status go.dev reference Status

✨ Highlights

  • Postgres-like SQL – the syntax you already know, embedded in your Go app.
  • Pure Go – no CGO or external dependencies.
  • Flexible Storage – keep data on disk or run fully in-memory.
  • Built on Pebble – powered by CockroachDB’s Pebble engine.

🔎 Current Capabilities

ChaiSQL already supports a useful core of SQL features, including:

  • Creating and dropping tables & indexes (with composite indexes)
  • Inserting, updating, deleting rows
  • Basic SELECT queries with filtering, ordering, grouping
  • DISTINCT, UNION / UNION ALL

👉 Joins and many advanced features are not implemented yet. The goal is steady growth toward broader PostgreSQL compatibility, but today ChaiSQL is best suited for simpler schemas and embedded use cases.

🗺 Roadmap

ChaiSQL is still in active development and not production-ready. Planned milestones include:

  • [ ] Finalize stable on-disk storage format (90% complete)
  • [ ] Broader SQL-92 coverage
  • [ ] Drivers for other languages (JS/TS, Python, …)
  • [ ] RocksDB backend support
  • [ ] Compatibility with PostgreSQL drivers/ORMs

Installation

Install the ChaiSQL driver and CLI:

go install github.com/chaisql/chai@latest
go install github.com/chaisql/chai/cmd/chai@latest

Quickstart

Here’s a simple Go example that creates a table, inserts rows, and queries them:

package main

import (
    "database/sql"
    "fmt"
    "log"

    _ "github.com/chaisql/chai"
)

func main() {
    // Open an on-disk database called "mydb"
    db, err := sql.Open("chai", "mydb")
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()

    // Create schema
    _, err = db.Exec(`
        CREATE TABLE users (
            id          INTEGER PRIMARY KEY,
            name        TEXT NOT NULL UNIQUE,
            email       TEXT NOT NULL,
            age         INT  NOT NULL,
            created_at  TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        );
    `)
    if err != nil {
        log.Fatal(err)
    }

    // Insert some data
    _, err = db.Exec(`
        INSERT INTO users (id, name, email, age)
        VALUES
            (1, 'Alice', 'alice@example.com', 30),
            (2, 'Bob',   'bob@example.com',   25),
            (3, 'Carol', 'carol@example.com', 40);
    `)
    if err != nil {
        log.Fatal(err)
    }

    // Query active adults
    rows, err := db.Query(`
        SELECT id, name, email, age
        FROM users
        WHERE age >= 18
        ORDER BY age DESC
    `)
    if err != nil {
        log.Fatal(err)
    }
    defer rows.Close()

    for rows.Next() {
        var id, age int
        var name, email string
        if err := rows.Scan(&id, &name, &email, &age); err != nil {
            log.Fatal(err)
        }
        fmt.Printf("User %d: %s (%s), %d years old\n", id, name, email, age)
    }
}

In-memory Database

For ephemeral databases, just use :memory::

db, err := sql.Open("chai", ":memory:")

Chai shell

The chai command-line tool provides an interactive SQL shell:

# In-memory database:
chai

# Disk-based database:
chai dirName

Contributing

Contributions are welcome!

A big thanks to our contributors!

Made with contrib.rocks.

For any questions or discussions, open an issue.

❓ FAQ

Why not just use SQLite?

SQLite is fantastic, but it has its own SQL dialect. ChaiSQL is designed for PostgreSQL compatibility, so it feels familiar if you already use Postgres.

Is it production-ready?

Not yet. We’re actively building out SQL support and stability.

Can I use existing Postgres tools?

Not yet. ChaiSQL is PostgreSQL-API inspired, but it does not speak the Postgres wire protocol and is not compatible with psql, pg_dump, or drivers that expect a Postgres server.

Extension points exported contracts — how you extend this code

Expr (Interface)
An Expr evaluates to a value. [36 implementers]
internal/expr/expr.go
Statement (Interface)
A Statement represents a unique action that can be executed against the database. [14 implementers]
internal/query/statement/statement.go
TypeDefinition (Interface)
(no doc) [8 implementers]
internal/types/types.go
Result (Interface)
(no doc) [32 implementers]
internal/database/row.go
Session (Interface)
(no doc) [3 implementers]
internal/engine/engine.go
Operator (Interface)
An Operator is used to modify a stream. It takes an environment containing the current value as well as any other metada
internal/stream/operator.go
Row (Interface)
(no doc) [1 implementers]
internal/row/row.go
Function (Interface)
A Function is an expression whose evaluation calls a function previously defined. [15 implementers]
internal/expr/expr.go

Core symbols most depended-on inside this repo

Pipe
called by 406
internal/stream/stream.go
New
called by 268
internal/stream/stream.go
Equal
called by 255
internal/sql/parser/expr.go
Run
called by 236
internal/query/statement/statement.go
NewIntegerValue
called by 208
internal/types/integer.go
Type
called by 173
internal/types/value.go
Scan
called by 168
internal/stream/table/scan.go
NewTextValue
called by 160
internal/types/text.go

Shape

Method 1,052
Function 517
Struct 225
Interface 30
TypeAlias 22
FuncType 4

Languages

Go100%

Modules by API surface

internal/expr/functions/builtins.go75 symbols
internal/database/catalog.go69 symbols
internal/expr/comparison.go38 symbols
internal/sql/driver/driver.go34 symbols
internal/stream/operator.go32 symbols
internal/sql/scanner/scanner.go32 symbols
internal/engine/engine.go32 symbols
internal/types/integer.go30 symbols
internal/types/bigint.go30 symbols
internal/tree/tree.go29 symbols
internal/types/double.go27 symbols
internal/row/row.go27 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add chai \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact