Top Related Projects
TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
high-performance graph database for real-time use cases
🥑 ArangoDB is a native multi-model database with flexible data models for documents, graphs, and key-values. Build high performance applications using a convenient SQL-like query language or JavaScript extensions.
The open-source database for the realtime web.
Quick Overview
Chai is an embeddable database engine for Go applications, designed to be fast and easy to use. It provides a SQL-like query language with support for ACID transactions, indexes, and joins, making it suitable for various application types that require local data storage and querying capabilities.
Pros
- Embeddable and lightweight, ideal for applications requiring a local database
- Supports ACID transactions, ensuring data integrity
- Provides a SQL-like query language for familiar and powerful querying
- Offers good performance with optimized indexing and query execution
Cons
- Limited ecosystem compared to more established databases
- May lack some advanced features found in full-fledged SQL databases
- Documentation could be more comprehensive for complex use cases
- Primarily focused on Go, which may limit its adoption in other languages
Code Examples
- Creating a table and inserting data:
db, err := chai.Open("mydb")
if err != nil {
log.Fatal(err)
}
defer db.Close()
err = db.Exec("CREATE TABLE users (id INT, name TEXT, age INT)")
if err != nil {
log.Fatal(err)
}
err = db.Exec("INSERT INTO users (id, name, age) VALUES (?, ?, ?)", 1, "Alice", 30)
if err != nil {
log.Fatal(err)
}
- Querying data:
var users []struct {
ID int
Name string
Age int
}
err = db.QueryRows("SELECT * FROM users WHERE age > ?", 25).Scan(&users)
if err != nil {
log.Fatal(err)
}
for _, user := range users {
fmt.Printf("User: %s, Age: %d\n", user.Name, user.Age)
}
- Using transactions:
tx, err := db.Begin()
if err != nil {
log.Fatal(err)
}
err = tx.Exec("UPDATE users SET age = ? WHERE id = ?", 31, 1)
if err != nil {
tx.Rollback()
log.Fatal(err)
}
err = tx.Commit()
if err != nil {
log.Fatal(err)
}
Getting Started
To use Chai in your Go project, follow these steps:
-
Install Chai:
go get github.com/chaisql/chai -
Import Chai in your Go code:
import "github.com/chaisql/chai" -
Create and open a database:
db, err := chai.Open("mydb") if err != nil { log.Fatal(err) } defer db.Close() -
Start using Chai to create tables, insert data, and query your database as shown in the code examples above.
Competitor Comparisons
TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
Pros of TiDB
- Distributed architecture for high scalability and availability
- Supports both OLTP and OLAP workloads
- Compatible with MySQL protocol and ecosystem
Cons of TiDB
- More complex setup and maintenance due to distributed nature
- Higher resource requirements for deployment
- Steeper learning curve for administration and optimization
Code Comparison
TiDB (SQL-like syntax):
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(255),
age INT
);
Chai (JavaScript-like syntax):
db.createTable('users', {
id: db.int().primaryKey(),
name: db.string(),
age: db.int()
})
Key Differences
- TiDB is a distributed SQL database, while Chai is an embedded database for Go applications
- TiDB offers more advanced features for large-scale deployments, whereas Chai focuses on simplicity and ease of use
- TiDB uses a SQL-like syntax, while Chai employs a JavaScript-like API for database operations
- TiDB is designed for production-grade, distributed environments, while Chai is better suited for smaller, local applications
Use Cases
TiDB:
- Large-scale web applications
- Distributed systems requiring high availability
- Hybrid transactional and analytical processing
Chai:
- Embedded databases in Go applications
- Local data storage for desktop or mobile apps
- Prototyping and small-scale projects
CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
Pros of CockroachDB
- Highly scalable distributed SQL database with strong consistency
- Built-in support for geo-partitioning and multi-region deployments
- Enterprise-grade features like role-based access control and backup/restore
Cons of CockroachDB
- More complex setup and maintenance compared to Chai
- Higher resource requirements for optimal performance
- Steeper learning curve for developers new to distributed systems
Code Comparison
CockroachDB (SQL syntax):
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name STRING,
email STRING UNIQUE,
created_at TIMESTAMP DEFAULT current_timestamp()
);
Chai (Go syntax):
type User struct {
ID string `chai:"primary"`
Name string
Email string `chai:"unique"`
CreatedAt time.Time `chai:"default:now()"`
}
db.CreateTable("users", User{})
CockroachDB offers a more traditional SQL syntax, while Chai provides a Go-native approach to defining schemas. CockroachDB's SQL syntax may be more familiar to developers with SQL experience, whereas Chai's struct-based approach integrates more seamlessly with Go code.
Both databases support common features like primary keys, unique constraints, and default values, but their implementation and syntax differ significantly.
high-performance graph database for real-time use cases
Pros of Dgraph
- More mature and feature-rich graph database system
- Supports distributed and scalable deployments
- Has a powerful query language (GraphQL+-) and built-in GraphQL support
Cons of Dgraph
- Higher complexity and steeper learning curve
- Requires more resources to run and maintain
- Less suitable for simple, embedded use cases
Code Comparison
Dgraph query example:
{
me(func: eq(name, "Alice")) {
name
age
friends {
name
}
}
}
Chai query example:
db.Query("SELECT * FROM users WHERE name = ? AND age > ?", "Alice", 25)
Dgraph focuses on graph-based queries with relationships, while Chai uses a more traditional SQL-like syntax for querying. Dgraph's query language is more expressive for complex graph relationships, but Chai's approach may be more familiar to developers used to working with relational databases.
Dgraph is better suited for large-scale, distributed graph database applications, while Chai is designed as a lightweight, embedded database for Go applications. Dgraph offers more advanced features and scalability, but Chai provides simplicity and ease of use for smaller projects or those requiring a more traditional database approach.
🥑 ArangoDB is a native multi-model database with flexible data models for documents, graphs, and key-values. Build high performance applications using a convenient SQL-like query language or JavaScript extensions.
Pros of ArangoDB
- More mature and feature-rich database system with multi-model support (document, graph, key/value)
- Larger community and ecosystem, with extensive documentation and third-party integrations
- Supports distributed deployments and horizontal scaling
Cons of ArangoDB
- Higher resource requirements and more complex setup compared to Chai
- Steeper learning curve due to its extensive feature set
- May be overkill for simpler projects or applications with basic database needs
Code Comparison
ArangoDB (AQL query):
FOR user IN users
FILTER user.age >= 18
SORT user.name
RETURN { name: user.name, age: user.age }
Chai:
db.View(func(tx *chai.Tx) error {
return tx.From("users").
Where(chai.GTE("age", 18)).
OrderBy("name").
Select("name", "age").
Iterate(func(d chai.Document) error {
// Process each document
return nil
})
})
Summary
ArangoDB is a more comprehensive database solution with advanced features and scalability, suitable for complex applications. Chai, on the other hand, is a lightweight embedded database for Go, offering simplicity and ease of use for smaller projects or applications with straightforward database requirements.
The open-source database for the realtime web.
Pros of RethinkDB
- Mature and battle-tested database with a large community and extensive documentation
- Built-in support for real-time changefeeds and horizontal scaling
- Offers a powerful query language (ReQL) with support for complex operations and joins
Cons of RethinkDB
- Heavier resource usage and more complex setup compared to Chai
- Development has slowed down in recent years
- Steeper learning curve for new users due to its unique query language
Code Comparison
RethinkDB query example:
r.table('users')
.filter(r.row['age'].gt(18))
.orderBy('name')
.limit(10)
.run(conn)
Chai query example:
db.Query("SELECT * FROM users WHERE age > ? ORDER BY name LIMIT ?", 18, 10)
Key Differences
- RethinkDB is a full-fledged distributed database system, while Chai is an embedded database for Go applications
- RethinkDB uses a custom query language (ReQL), whereas Chai uses SQL-like syntax
- RethinkDB offers more advanced features like real-time updates and horizontal scaling, while Chai focuses on simplicity and ease of use in Go projects
Use Cases
- RethinkDB: Ideal for large-scale applications requiring real-time data synchronization and complex querying
- Chai: Well-suited for Go applications needing a lightweight, embedded database with SQL-like syntax
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
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.
⨠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.
Top Related Projects
TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
high-performance graph database for real-time use cases
🥑 ArangoDB is a native multi-model database with flexible data models for documents, graphs, and key-values. Build high performance applications using a convenient SQL-like query language or JavaScript extensions.
The open-source database for the realtime web.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot