Coder Social home page Coder Social logo

chai's Introduction

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,
            created_at      TIMESTAMP   NOT NULL
        )
    `)

    err = db.Exec(`INSERT INTO user (id, name, age) VALUES ($1, $2, $3)`, 20, "foo", 40)

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

    err = rows.Iterate(func(r *chai.Row) error {
        // scan each column
        var id, name, age
        err = r.Scan(&id, &name, &age)
        // or into a struct
        var u User
        err = r.StructScan(&u)
        // or even a map
        var m 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.

chai's People

Contributors

asdine avatar jhchabran avatar tzzed avatar tie avatar tdakkota avatar yaziine avatar agonist avatar goku321 avatar jpeletier avatar sashaostrikov avatar ilmanzo avatar gillesfabio avatar tdemin avatar justinjudd avatar james-storey avatar ab22 avatar carlosfrodrigues avatar darkclainer avatar gfelixc avatar cvhariharan avatar kenshaw avatar kudinovkv avatar amirhossein2000 avatar abramlab avatar belanenko avatar dependabot[bot] avatar u5surf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.