dbsql

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: Apache-2.0 Imports: 20 Imported by: 26

README

Databricks SQL Driver for Go (Beta)

Description

This repo contains a Databricks SQL Driver for Go's database/sql package. It can be used to connect and query Databricks clusters and SQL Warehouses.

NOTE: This Driver is Beta.

Documentation

Full documentation is not yet available. See below for usage examples.

Usage

import (
	"database/sql"
	"time"

	_ "github.com/databricks/databricks-sql-go"
)

db, err := sql.Open("databricks", "token:********@********.databricks.com/sql/1.0/endpoints/********")
if err != nil {
	panic(err)
}


rows, err := db.Query("SELECT 1")

Additional usage examples are available here.

DSN (Data Source Name)

The DSN format is:

token:[your token]@[Workspace hostname][Endpoint HTTP Path]?param=value

You can set query timeout value by appending a timeout query parameter (in seconds) and you can set max rows to retrieve per network request by setting the maxRows query parameter:

token:[your token]@[Workspace hostname][Endpoint HTTP Path]?timeout=1000&maxRows=1000

Develop

Lint

We use golangci-lint as the lint tool. If you use vs code, just add the following settings:

{
    "go.lintTool": "golangci-lint",
    "go.lintFlags": [
        "--fast"
    ]
}
Unit Tests
go test

Issues

If you find any issues, feel free to create an issue or send a pull request directly.

Contributing

See CONTRIBUTING.md

License

Apache 2.0

Documentation

Overview

Package dbsql implements the go driver to Databricks SQL

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = "databricks: not implemented"
View Source
var ErrParametersNotSupported = "databricks: query parameters are not supported"
View Source
var ErrTransactionsNotSupported = "databricks: transactions are not supported"

Functions

func NewConnector

func NewConnector(options ...connOption) (driver.Connector, error)

NewConnector creates a connection that can be used with sql.OpenDB(). This is an easier way to set up the DB instead of having to construct a DSN string.

func NewRows added in v0.2.1

func NewRows(connID string, corrId string, client cli_service.TCLIService, opHandle *cli_service.TOperationHandle, pageSize int64, location *time.Location, directResults *cli_service.TSparkDirectResults) driver.Rows

func WithAccessToken added in v0.2.0

func WithAccessToken(token string) connOption

WithAccessToken sets up the Personal Access Token. Mandatory for now.

func WithHTTPPath added in v0.2.0

func WithHTTPPath(path string) connOption

WithHTTPPath sets up the endpoint to the warehouse. Mandatory.

func WithInitialNamespace added in v0.2.0

func WithInitialNamespace(catalog, schema string) connOption

Sets the initial catalog name and schema name in the session. Use <select * from foo> instead of <select * from catalog.schema.foo>

func WithMaxRows added in v0.2.0

func WithMaxRows(n int) connOption

WithMaxRows sets up the max rows fetched per request. Default is 10000

func WithPort added in v0.2.0

func WithPort(port int) connOption

WithPort sets up the server port. Mandatory.

func WithServerHostname added in v0.2.0

func WithServerHostname(host string) connOption

WithServerHostname sets up the server hostname. Mandatory.

func WithSessionParams added in v0.2.0

func WithSessionParams(params map[string]string) connOption

Sessions params will be set upon opening the session by calling SET function. If using connection pool, session params can avoid successive calls of "SET ..."

func WithTimeout added in v0.2.0

func WithTimeout(n time.Duration) connOption

WithTimeout adds timeout for the server query execution. Default is no timeout.

func WithUserAgentEntry added in v0.2.0

func WithUserAgentEntry(entry string) connOption

Used to identify partners. Set as a string with format <isv-name+product-name>.

Types

This section is empty.

Directories

Path Synopsis
examples module
internal

Jump to

Keyboard shortcuts

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