gitql

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2017 License: MIT Imports: 8 Imported by: 5

README

codebeat badge

Build Status

codecov

GoDoc

Installation

Check the Releases page to download the gitql binary.

Usage

Usage:
  gitql [OPTIONS] <query | shell | version>

Help Options:
  -h, --help  Show this help message

Available commands:
  query    Execute a SQL query a repository.
  shell    Start an interactive session.
  version  Show the version information.

For example:

$ cd my_git_repo
$ gitql query 'SELECT hash, author_email, author_name FROM commits LIMIT 2;' 
SELECT hash, author_email, author_name FROM commits LIMIT 2;
+------------------------------------------+---------------------+-----------------------+
|                   HASH                   |    AUTHOR EMAIL     |      AUTHOR NAME      |
+------------------------------------------+---------------------+-----------------------+
| 003dc36e0067b25333cb5d3a5ccc31fd028a1c83 | user1@test.io       | Santiago M. Mola      |
| 01ace9e4d144aaeb50eb630fed993375609bcf55 | user2@test.io       | Antonio Navarro Perez |
+------------------------------------------+---------------------+-----------------------+

You can use the interactive shell like you usually do to explore tables in postgreSQL per example:

$ gitql shell

           gitQL SHELL
           -----------
You must end your queries with ';'

!> SELECT hash, author_email, author_name FROM commits LIMIT 2;

--> Executing query: SELECT hash, author_email, author_name FROM commits LIMIT 2;

+------------------------------------------+---------------------+-----------------------+
|                   HASH                   |    AUTHOR EMAIL     |      AUTHOR NAME      |
+------------------------------------------+---------------------+-----------------------+
| 003dc36e0067b25333cb5d3a5ccc31fd028a1c83 | user1@test.io       | Santiago M. Mola      |
| 01ace9e4d144aaeb50eb630fed993375609bcf55 | user2@test.io       | Antonio Navarro Perez |
+------------------------------------------+---------------------+-----------------------+
!>  

Tables

gitql exposes the following tables:

Name Columns
commits hash, author_name, author_email, author_time, comitter_name, comitter_email, comitter_time, message
blobs hash, size
references hash,hash, name, is_branch, is_note, is_remote, is_tag, target
tags hash, name, tagger_email, tagger_name, tagger_when, message, target
tree_entries tree_hash, entry_hash, mode, name

SQL syntax

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

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

License

gitql is licensed under the MIT License.

Documentation

Overview

Example
package main

import (
	"database/sql"
	"fmt"

	"github.com/gitql/gitql"
	"github.com/gitql/gitql/mem"
	gitqlsql "github.com/gitql/gitql/sql"
)

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

	// Open a sql connection with the default engine.
	conn, err := sql.Open(gitql.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{
		gitqlsql.Column{Name: "name", Type: gitqlsql.String},
		gitqlsql.Column{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 = "gitql"
)

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 added in v0.5.0

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
cmd
internal
sql

Jump to

Keyboard shortcuts

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