Convert Figma logo to code with AI

chaisql logochai

Modern embedded SQL database

1,573
95
1,573
35

Top Related Projects

37,777

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.

30,408

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.

20,588

high-performance graph database for real-time use cases

13,643

🥑 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.

26,829

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

  1. 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)
}
  1. 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)
}
  1. 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:

  1. Install Chai:

    go get github.com/chaisql/chai
    
  2. Import Chai in your Go code:

    import "github.com/chaisql/chai"
    
  3. Create and open a database:

    db, err := chai.Open("mydb")
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()
    
  4. Start using Chai to create tables, insert data, and query your database as shown in the code examples above.

Competitor Comparisons

37,777

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
30,408

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.

20,588

high-performance graph database for real-time use cases

Pros of Dgraph

  • Designed for distributed systems, offering better scalability for large datasets
  • Supports GraphQL natively, providing a powerful query language out of the box
  • Has a more mature ecosystem with extensive documentation and community support

Cons of Dgraph

  • Higher complexity and steeper learning curve compared to Chai
  • Requires more resources to run and maintain, potentially increasing operational costs
  • Less suitable for smaller projects or applications with simpler data models

Code Comparison

Chai query example:

db.Query("SELECT * FROM users WHERE age > ?", 18)

Dgraph query example:

{
  users(func: gt(age, 18)) {
    name
    age
  }
}

Key Differences

  • Chai is an embedded database, while Dgraph is a distributed graph database
  • Chai uses SQL-like syntax, whereas Dgraph uses GraphQL and its own query language
  • Dgraph offers more advanced features like ACID transactions and horizontal scaling
  • Chai is more lightweight and easier to integrate into Go applications

Use Cases

  • Choose Chai for simpler Go projects, embedded databases, or when SQL familiarity is important
  • Opt for Dgraph when dealing with complex relationships, large-scale data, or when GraphQL support is required
13,643

🥑 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.

26,829

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

ChaiSQL

ChaiSQL is a modern embedded SQL database, focusing on flexibility and ease of use for developers.

Build Status go.dev reference Status

Key Features

  • PostgreSQL API: ChaiSQL SQL API is compatible with PostgreSQL
  • Optimized for Go: Native Go implementation with no CGO dependency.
  • Storage flexibility: Store data on-disk or in-memory.
  • Solid foundations: ChaiSQL is backed by Pebble for native Go toolchains, and RocksDB for non-Go or CGO builds (coming soon).

Roadmap

ChaiSQL is work in progress and is not ready yet for production.

Here is a high level list of features that we want to implement in the near future, in no particular order:

  • Stable storage format (90% completed)
  • Implement most of the SQL-92 standard (detailed roadmap coming soon)
  • Provide clients for other languages (JS/TS, Python, etc) and add support for RocksDB as the backend
  • Compatibility with PostgreSQL drivers and ORMs

Installation

Install the ChaiSQL database

go install github.com/chaisql/chai

Quickstart

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/chaisql/chai"
)

func main() {
    // Create a database instance, here we'll store everything on-disk
    db, err := chai.Open("mydb")
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()

    err = db.Exec(`
        CREATE TABLE user (
            id              INT         PRIMARY KEY,
            name            TEXT        NOT NULL UNIQUE,
            age             INT         NOT NULL,
            created_at      TIMESTAMP
        )
    `)

    err = db.Exec(`INSERT INTO user (id, name, age) VALUES (1, "Jo Bloggs", 33)`)

    rows, err := db.Query("SELECT id, name, age, address FROM user WHERE age >= 18")
    defer rows.Close()

    err = rows.Iterate(func(r *chai.Row) error {
        // scan each column
        var id, age int
        var name string
        err = r.Scan(&id, &name, &age)
        // or into a struct
        type User struct {
            ID   int
            Name string
            Age  int
        }
        var u User
        err = r.StructScan(&u)
        // or even a map
        m := make(map[string]any)
        err = r.MapScan(&m)
        return nil
    })
}

Checkout the Go doc and the usage example in the README to get started quickly.

In-memory database

For in-memory operations, simply use :memory::

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

Using database/sql

// import chai as a blank import
import _ "github.com/chaisql/chai/driver"

// Create a sql/database DB instance
db, err := sql.Open("chai", "mydb")
if err != nil {
    log.Fatal(err)
}
defer db.Close()

// Then use db as usual
res, err := db.ExecContext(...)
res, err := db.Query(...)
res, err := db.QueryRow(...)

// use the driver.Scanner to scan into a struct
var u User
err = res.Scan(driver.Scanner(&u))

chai shell

The chai command line provides an SQL shell for database management:

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

Usage example:

# For in-memory database:
chai

# For 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.