Git Product home page Git Product logo

prestgo's Introduction

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.

prestgo's People

Contributors

iand avatar scritchley avatar rikonor avatar lattwood avatar saurori avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.