Skip to content

A pure Go database driver for the Presto query engine (prestodb.io)

License

Notifications You must be signed in to change notification settings

ianoc-stripe/prestgo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prestgo

A pure Go database driver for the Presto query engine.

Installation

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

Usage

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"

Features

  • SELECT, SHOW, DESCRIBE
  • Pagination of results
  • varchar, bigint, boolean, double and timestamp datatypes
  • Custom HTTP clients

Future

(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 and map datatypes

Authors

Originally written by Ian Davis.

Contributors

Your name here...

Contributing

  • 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.

License

This software is released under the MIT License, please see the accompanying LICENSE file.

About

A pure Go database driver for the Presto query engine (prestodb.io)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%