Home

Awesome

go-zetasqlite

Go GoDoc codecov

A database driver library that interprets ZetaSQL queries and runs them using SQLite3

Features

go-zetasqlite supports database/sql driver interface. So, you can use ZetaSQL queries just by importing github.com/goccy/go-zetasqlite. Also, go-zetasqlite uses SQLite3 as the database engine. Since we are using go-sqlite3, we can use the options ( like :memory: ) supported by go-sqlite3 ( see details ). ZetaSQL functionality is provided by go-zetasql

Installation

go get github.com/goccy/go-zetasqlite

NOTE

Since this library uses go-zetasql, the following environment variables must be enabled in order to build. See here for details.

CGO_ENABLED=1
CXX=clang++

Synopsis

You can pass ZetaSQL queries to Query/Exec function of database/sql package.

package main

import (
  "database/sql"
  "fmt"

  _ "github.com/goccy/go-zetasqlite"
)

func main() {
  db, err := sql.Open("zetasqlite", ":memory:")
  if err != nil {
    panic(err)
  }
  defer db.Close()

  rows, err := db.Query(`SELECT * FROM UNNEST([?, ?, ?])`, 1, 2, 3)
  if err != nil {
    panic(err)
  }
  var ids []int64
  for rows.Next() {
    var id int64
    if err := rows.Scan(&id); err != nil {
      panic(err)
    }
    ids = append(ids, id)
  }
  fmt.Println(ids) // [1 2 3]
}

Tools

ZetaSQLite CLI

You can execute ZetaSQL queries interactively by using the tools provided by cmd/zetasqlite-cli. See here for details

Status

A list of ZetaSQL ( Google Standard SQL ) specifications and features supported by go-zetasqlite.

Types

Expressions

Operators

Conditional Expressions

Subqueries

Query

Statements

DDL ( Data Definition Language )

DML ( Data Manipulation Language )

DCL ( Data Control Language )

Procedural Language

Debugging Statements

Other Statements

User Defined Functions

Functions

Aggregate functions

Statistical aggregate functions

Approximate aggregate functions

HyperLogLog++ functions

Numbering functions

Bit functions

Conversion functions

Mathematical functions

Navigation functions

Hash functions

String functions

JSON functions

Array functions

Date functions

Datetime functions

Time functions

Timestamp functions

Interval functions

Geography functions

Security functions

UUID functions

Net functions

Debugging functions

AEAD encryption functions

License

MIT