crate

package module
v0.0.0-...-ec69b9d Latest Latest
Warning

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

Go to latest
Published: May 1, 2017 License: MIT Imports: 9 Imported by: 0

README

go-crate

CircleCI

Golang Sql Driver for Crate Data Storage. (https://crate.io/)

http://godoc.org/github.com/herenow/go-crate

http://golang.org/pkg/database/sql/

Install & Usage

go get github.com/herenow/go-crate
import "database/sql"
import _ "github.com/herenow/go-crate"

db, err := sql.Open("crate", "http://localhost:4200/")

Not Supported SQL Functions

Some functions of the database/sql package may not be supported, due to a lack of support of Crate or this package. Transactions are not supported by crate.

Notes

  • Feel free to send in contributions to this package.

TODO

  • Possible type checking when receving data from crate, and convert it to documented Go types.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CrateDriver

type CrateDriver struct {
	Url string // Crate http endpoint url
}

Crate conn structure

func (*CrateDriver) Begin

func (c *CrateDriver) Begin() (driver.Tx, error)

Yet not supported

func (*CrateDriver) Close

func (c *CrateDriver) Close() error

Nothing to close, crate is stateless

func (*CrateDriver) Exec

func (c *CrateDriver) Exec(stmt string, args []driver.Value) (result driver.Result, err error)

Exec queries on the dataabase

func (*CrateDriver) Open

func (c *CrateDriver) Open(crate_url string) (driver.Conn, error)

Init a new "Connection" to a Crate Data Storage instance. Note that the connection is not tested until the first query.

func (*CrateDriver) Prepare

func (c *CrateDriver) Prepare(query string) (driver.Stmt, error)

Driver method that initiates the prepared stmt interface

func (*CrateDriver) Query

func (c *CrateDriver) Query(stmt string, args []driver.Value) (driver.Rows, error)

Queries the database

Example
package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/herenow/go-crate"
)

func main() {
	db, err := sql.Open("crate", "http://localhost:4200")

	if err != nil {
		log.Fatal(err)
	}

	rows, err := db.Query("SELECT name FROM sys.cluster")

	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	for rows.Next() {
		var name string

		if err := rows.Scan(&name); err != nil {
			log.Fatal(err)
		}
		fmt.Printf("%s\n", name)
	}

	if err := rows.Err(); err != nil {
		log.Fatal(err)
	}
}
Output:

type CrateErr

type CrateErr struct {
	Code    int
	Message string
}

Specific Crate errors returned by the endpoint. Use this to type check for database errors.

func (*CrateErr) Error

func (e *CrateErr) Error() string

Return error message, this is part of the error interface.

type CrateStmt

type CrateStmt struct {
	// contains filtered or unexported fields
}

Prepared stmt interface

func (*CrateStmt) Close

func (s *CrateStmt) Close() error

No need to implement close

func (*CrateStmt) Exec

func (s *CrateStmt) Exec(args []driver.Value) (driver.Result, error)

Just pass it to the driver's default Exec() function

func (*CrateStmt) NumInput

func (s *CrateStmt) NumInput() int

The NumInput method is not supported, return -1 so the database/sql packages knows.

func (*CrateStmt) Query

func (s *CrateStmt) Query(args []driver.Value) (driver.Rows, error)

Just pass it to the driver's' default Query() function

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result interface

func (*Result) LastInsertId

func (r *Result) LastInsertId() (int64, error)

Last inserted id

func (*Result) RowsAffected

func (r *Result) RowsAffected() (int64, error)

of affected rows on exec

type Rows

type Rows struct {
	// contains filtered or unexported fields
}

Rows reader

func (*Rows) Close

func (r *Rows) Close() error

Close

func (*Rows) Columns

func (r *Rows) Columns() []string

Row columns

func (*Rows) Next

func (r *Rows) Next(dest []driver.Value) error

Get the next row

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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