ChaiSQL

现代嵌入式 SQL 数据库。「Modern embedded SQL database」

Github星跟蹤圖

ChaiSQL

ChaiSQL is a modern embedded SQL database, focusing on flexibility and ease of use for developers. It provides a fresh alternative to traditional embedded databases by offering advanced features tailored for modern applications.

Build Status
go.dev reference
Status

Key Features

  • Modern SQL Experience: ChaiSQL introduces a modern twist to traditional SQL embedded databases
  • Optimized for Go: Native Go implementation with no CGO dependency.
  • Solid foundations: ChaiSQL is backed by Pebble for native Go toolchains, and RocksDB for non-Go or CGO builds (coming soon).
  • Schema Flexibility: Support for strict, partial, and schemaless table designs, catering to various data modeling needs.

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

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()

    // Create a table.
    // Notice that it is possible to define constraints on nested columns.
    err = db.Exec(`
        CREATE TABLE user (
            id              INT         PRIMARY KEY,
            name            TEXT        NOT NULL UNIQUE,
            created_at      TIMESTAMP   NOT NULL,
            address (
                city        TEXT    DEFAULT "unknown",
                zipcode     TEXT
            ),
            friends         ARRAY,

            CHECK len(friends) > 0
        )
    `)

    err = db.Exec(`
        INSERT INTO user (id, name, age, address, friends)
        VALUES (
            11,
            'Foo2',
            20,
            {city: "Lyon", zipcode: "69001"},
            ["foo", "bar", "baz"]
        )`)

    // Go structures can be passed directly
    type User struct {
        ID              uint
        Name            string
        TheAgeOfTheUser float64 `chai:"age"`
        Address         struct {
            City    string
            ZipCode string
        }
    }

    // Let's create a user
    u := User{
        ID:              20,
        Name:            "foo",
        TheAgeOfTheUser: 40,
    }
    u.Address.City = "Lyon"
    u.Address.ZipCode = "69001"

    err = db.Exec(`INSERT INTO user VALUES ?`, &u)

    // Query data
    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 {
        err = r.Scan(...)
        err = r.StructScan(...)
        err = r.MapScan(...)
        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.

主要指標

概覽
名稱與所有者chaisql/chai
主編程語言Go
編程語言Go (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2018-06-23 15:12:03
推送於2024-11-09 08:14:17
最后一次提交
發布數57
最新版本名稱v0.16.0 (發布於 )
第一版名稱v0.1.0 (發布於 )
用户参与
星數1.6k
關注者數34
派生數95
提交數2.1k
已啟用問題?
問題數257
打開的問題數26
拉請求數232
打開的拉請求數6
關閉的拉請求數28
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?