A pure Go database driver for the Presto query engine.
Simply run
go get github.com/avct/prestgo/...
This will install the Presto database driver and the prq
tool for running queries from the command line.
Documentation is at http://godoc.org/github.com/avct/prestgo
Prestgo conforms to the Go standard library Driver interface. This means it works transparently with the database/sql
package. Simply import the github.com/avct/prestgo
package to auto-register the driver:
import "github.com/avct/prestgo"
If you don't intend to use any prestgo-specific functions directly, you can import using the blank identifier which will still register the driver:
import _ "github.com/avct/prestgo"
The driver name is prestgo
and it supports the standard Presto data source name format presto://user@hostname:port/catalog/schema
. All parts of the data source name are optional, defaulting to port 8080 on localhost with hive
catalog, default
schema and a user of prestgo
.
Here's how to get a list of tables from a Presto server:
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/avct/prestgo"
)
func main() {
db, err := sql.Open("prestgo", "presto://example:8080/hive/default")
if err != nil {
log.Fatalf("failed to connect to presto: %v", err)
}
rows, err := db.Query("SHOW TABLES")
if err != nil {
log.Fatalf("failed to run query: %v", err)
}
defer rows.Close()
for rows.Next() {
var name string
if err := rows.Scan(&name); err != nil {
log.Fatal(err.Error())
}
fmt.Printf("%s\n", name)
}
if err := rows.Err(); err != nil {
log.Fatal(err.Error())
}
}
The included command line query tool prq
can be used like this:
prq "presto://example:8080/hive/default" "SHOW TABLES"
- SELECT, SHOW, DESCRIBE
- Pagination of results
varchar
,bigint
,boolean
,double
andtimestamp
datatypes- Custom HTTP clients
(aka: Things you could help with)
- Parameterised queries
- INSERT queries
- DDL (ALTER/CREATE/DROP TABLE)
- Cancelling of queries
- User authentication
json
,date
,time
,interval
,array
,row
andmap
datatypes
Originally written by Ian Davis.
Your name here...
- Do submit your changes as a pull request
- Do your best to adhere to the existing coding conventions and idioms.
- Do supply unit tests if possible.
- Do run
go fmt
on the code before committing - Do feel free to add yourself to the Contributors list in
the
README.md
. Alphabetical order applies. - Don't touch the Authors section. An existing author will add you if your contributions are significant enough.
This software is released under the MIT License, please see the accompanying LICENSE
file.