sqldriver

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package sqldriver is a wrapper around the ADBC (Arrow Database Connectivity) interfaces to support the standard golang database/sql package, described here: https://go.dev/src/database/sql/doc.txt

This allows any ADBC driver implementation to also be used as-is with the database/sql package of the standard library rather than having to implement drivers for both separately.

Registering the driver can be done by importing this and then running

sql.Register("drivername", sqldriver.Driver{adbcdriver})

Additionally, the sqldriver/flightsql package simplifies registration of the FlightSQL ADBC driver implementation, so that only a single import statement is needed. See the example in that package.

EXPERIMENTAL. The ADBC interfaces are subject to change and as such this wrapper is also subject to change based on that.

Example
package main

import (
	"database/sql"
	"fmt"

	"github.com/apache/arrow-adbc/go/adbc/drivermgr"
	"github.com/apache/arrow-adbc/go/adbc/sqldriver"
)

func main() {
	sql.Register("adbc", sqldriver.Driver{&drivermgr.Driver{}})

	// AdbcDriverInit is the assumed entrypoint by default, but i'll keep
	// it specified explicitly here for demonstration purposes.
	// this also assumes that libadbc_driver_sqlite.so is on your LD_LIBRARY_PATH
	db, err := sql.Open("adbc", "driver=adbc_driver_sqlite;entrypoint=AdbcDriverInit")
	if err != nil {
		panic(err)
	}

	rows, err := db.Query("SELECT ?", 1)
	if err != nil {
		panic(err)
	}
	defer rows.Close()

	colNames, err := rows.Columns()
	if err != nil {
		panic(err)
	}

	fmt.Println(colNames)
	cols, err := rows.ColumnTypes()
	if err != nil {
		panic(err)
	}
	fmt.Println(cols[0].Name())
	fmt.Println(cols[0].Nullable())

	for rows.Next() {
		var v int64
		if err := rows.Scan(&v); err != nil {
			panic(err)
		}
		fmt.Println(v)
	}

}
Output:

[?]
?
true true
1

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOptionsFromCtx

func GetOptionsFromCtx(ctx context.Context) map[string]string

func SetOptionsInCtx

func SetOptionsInCtx(ctx context.Context, opts map[string]string) context.Context

Types

type Driver

type Driver struct {
	Driver adbc.Driver
}

func (Driver) Open

func (d Driver) Open(name string) (driver.Conn, error)

Open returns a new connection to the database. The name should be semi-colon separated key-value pairs of the form: key=value;key2=value2;.....

Open may return a cached connection (one previously closed), but doing so is unnecessary; the sql package maintains a pool of idle connections for efficient re-use.

The returned connection is only used by one goroutine at a time.

func (Driver) OpenConnector

func (d Driver) OpenConnector(name string) (driver.Connector, error)

OpenConnector expects the same format as driver.Open

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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