go-mysql-server: github.com/src-d/go-mysql-server Index | Examples | Files | Directories

package sqle

import "github.com/src-d/go-mysql-server"

Code:

package main

import (
    "fmt"
    "io"

    "github.com/src-d/go-mysql-server"
    "github.com/src-d/go-mysql-server/memory"
    "github.com/src-d/go-mysql-server/sql"
)

func main() {
    e := sqle.NewDefault()
    ctx := sql.NewEmptyContext()

    // Create a test memory database and register it to the default engine.
    e.AddDatabase(createTestDatabase())

    _, r, err := e.Query(ctx, `SELECT name, count(*) FROM mytable
	WHERE name = 'John Doe'
	GROUP BY name`)
    checkIfError(err)

    // Iterate results and print them.
    for {
        row, err := r.Next()
        if err == io.EOF {
            break
        }
        checkIfError(err)

        name := row[0]
        count := row[1]

        fmt.Println(name, count)
    }

}

func checkIfError(err error) {
    if err != nil {
        panic(err)
    }
}

func createTestDatabase() sql.Database {
    db := memory.NewDatabase("test")
    table := memory.NewTable("mytable", sql.Schema{
        {Name: "name", Type: sql.Text, Source: "mytable"},
        {Name: "email", Type: sql.Text, Source: "mytable"},
    })
    db.AddTable("mytable", table)
    ctx := sql.NewEmptyContext()

    rows := []sql.Row{
        sql.NewRow("John Doe", "john@doe.com"),
        sql.NewRow("John Doe", "johnalt@doe.com"),
        sql.NewRow("Jane Doe", "jane@doe.com"),
        sql.NewRow("Evil Bob", "evilbob@gmail.com"),
    }

    for _, row := range rows {
        table.Insert(ctx, row)
    }

    return db
}

Index

Examples

Package Files

engine.go log.go

Variables

var (
    // QueryCounter describes a metric that accumulates number of queries monotonically.
    QueryCounter = discard.NewCounter()

    // QueryErrorCounter describes a metric that accumulates number of failed queries monotonically.
    QueryErrorCounter = discard.NewCounter()

    // QueryHistogram describes a queries latency.
    QueryHistogram = discard.NewHistogram()
)

type Config Uses

type Config struct {
    // VersionPostfix to display with the `VERSION()` UDF.
    VersionPostfix string
    // Auth used for authentication and authorization.
    Auth auth.Auth
}

Config for the Engine.

type Engine Uses

type Engine struct {
    Catalog  *sql.Catalog
    Analyzer *analyzer.Analyzer
    Auth     auth.Auth
}

Engine is a SQL engine.

func New Uses

func New(c *sql.Catalog, a *analyzer.Analyzer, cfg *Config) *Engine

New creates a new Engine with custom configuration. To create an Engine with the default settings use `NewDefault`.

func NewDefault Uses

func NewDefault() *Engine

NewDefault creates a new default Engine.

func (*Engine) AddDatabase Uses

func (e *Engine) AddDatabase(db sql.Database)

AddDatabase adds the given database to the catalog.

func (*Engine) Init Uses

func (e *Engine) Init() error

Init performs all the initialization requirements for the engine to work.

func (*Engine) Query Uses

func (e *Engine) Query(
    ctx *sql.Context,
    query string,
) (sql.Schema, sql.RowIter, error)

Query executes a query.

Directories

PathSynopsis
auth
benchmark
_example
internal/regex
internal/similartext
internal/sockstate
memory
server
sql
sql/analyzer
sql/expression
sql/expression/function
sql/expression/function/aggregation
sql/index
sql/index/pilosa
sql/parse
sql/plan
test

Package sqle imports 12 packages (graph) and is imported by 4 packages. Updated 2019-09-16. Refresh now. Tools for package owners.