sqle

package module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2017 License: MIT Imports: 8 Imported by: 3

README

sqle

codebeat badge Build Status codecov GoDoc

Installation

The import path for the package is gopkg.in/sqle/sqle.v0.

To install it, run:

go get gopkg.in/sqle/sqle.v0

Documentation

SQL syntax

We are continuously adding more functionality to gitql. We support a subset of the SQL standard, currently including:

Supported
Comparison expressions !=, ==, >, <, >=,<=
Null check expressions IS NULL, IS NOT NULL
Grouping expressions COUNT, FIRST
Standard expressions ALIAS, LITERAL, STAR (*)
Statements CROSS JOIN, DESCRIBE, FILTER (WHERE), GROUP BY, LIMIT, SELECT, SHOW TABLES, SORT

Powered by sqle

License

sqle is licensed under the MIT License.

Documentation

Overview

Example
package main

import (
	"database/sql"
	"fmt"

	"gopkg.in/sqle/sqle.v0"
	"gopkg.in/sqle/sqle.v0/mem"
	gitqlsql "gopkg.in/sqle/sqle.v0/sql"
)

func main() {
	// Create a test memory database and register it to the default engine.
	sqle.DefaultEngine.AddDatabase(createTestDatabase())

	// Open a sql connection with the default engine.
	conn, err := sql.Open(sqle.DriverName, "")
	checkIfError(err)

	// Prepare a query.
	stmt, err := conn.Prepare(`SELECT name, count(*) FROM mytable
	WHERE name = 'John Doe'
	GROUP BY name`)
	checkIfError(err)

	// Get result rows.
	rows, err := stmt.Query()
	checkIfError(err)

	// Iterate results and print them.
	for {
		if !rows.Next() {
			break
		}

		name := ""
		count := int64(0)
		err := rows.Scan(&name, &count)
		checkIfError(err)

		fmt.Println(name, count)
	}
	checkIfError(rows.Err())

}

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

func createTestDatabase() *mem.Database {
	db := mem.NewDatabase("test")
	table := mem.NewTable("mytable", gitqlsql.Schema{
		{Name: "name", Type: gitqlsql.String},
		{Name: "email", Type: gitqlsql.String},
	})
	db.AddTable("mytable", table)
	table.Insert(gitqlsql.NewRow("John Doe", "john@doe.com"))
	table.Insert(gitqlsql.NewRow("John Doe", "johnalt@doe.com"))
	table.Insert(gitqlsql.NewRow("Jane Doe", "jane@doe.com"))
	table.Insert(gitqlsql.NewRow("Evil Bob", "evilbob@gmail.com"))
	return db
}
Output:

John Doe 2

Index

Examples

Constants

View Source
const (
	DriverName = "sqle"
)

Variables

View Source
var DefaultEngine = New()

DefaultEngine is the default Engine instance, used when opening a connection to gitql:// when using database/sql.

View Source
var (
	ErrNotSupported = errors.New("feature not supported yet")
)

Functions

This section is empty.

Types

type Engine

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

Engine is a SQL engine. It implements the standard database/sql/driver/Driver interface, so it can be registered as a database/sql driver.

func New

func New() *Engine

New creates a new Engine.

func (*Engine) AddDatabase

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

func (*Engine) Open

func (e *Engine) Open(name string) (driver.Conn, error)

Open creates a new session for the engine and returns it as a driver.Conn.

Name parameter is ignored.

func (*Engine) Query

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

Query executes a query without attaching to any session.

Directories

Path Synopsis
sql

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL