duckdb

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go SQL driver for DuckDB

The DuckDB driver conforms to the built-in database/sql interface.

Tests status

Installation

go get github.com/marcboeker/go-duckdb

go-duckdb uses CGO to make calls to the linked DuckDB database. Therefore you need to have a compiled version of DuckDB availabe or compile your own.

Please use the latest DuckDB version from master.

git clone https://github.com/duckdb/duckdb.git
cd duckdb
make

If you don't want to compile DuckDB yourself, you could also use the pre-compiled libraries from their releases page.

Please locate the following files in your DuckDB directory, as we need them to build the go-duckdb driver:

  • build/release/src/libduckdb{_static}.a or build/release/src/libduckdb.so (for Linux)
  • build/release/src/libduckdb.dylib (for macOS)
  • build/release/src/libduckdb.dll (for Windows)
  • src/include/duckdb.h

To run the example or execute the tests please specify the following CGO_LDFLAGS, CGO_CFLAGS and the DYLD_LIBRARY_PATH (if you are on macOS) env variables.

On Linux:

CGO_LDFLAGS="-L/path/to/libduckdb_static.a" CGO_CFLAGS="-I/path/to/duckdb.h" go run examples/simple.go

On macOS:

CGO_LDFLAGS="-L/path/to/duckdb/build/release/src" CGO_CFLAGS="-I/path/to/duckdb/src/include" DYLD_LIBRARY_PATH="/path/to/duckdb/build/release/src" go run examples/simple.go

You could also use make to install go-duckdb or run the examples/tests.

  • make test runs the test cases.
  • make examples executes the examples/simple.go file.
  • make install installs the current version.

Usage

go-duckdb hooks into the database/sql interface provided by the Go stdlib. To open a connection, simply specify the driver type as duckdb:

db, err := sql.Open("duckdb", "")

This creates an in-memory instance of DuckDB. If you would like to store the data on the filesystem, you need to specify the path where to store the database:

db, err := sql.Open("duckdb", "/path/to/foo.db")

If you want to set specific config options for DuckDB, you can add them as query style parameters in the form of name=value to the DSN, like:

db, err := sql.Open("duckdb", "/path/to/foo.db?access_mode=read_only&threads=4")

Please refer to the database/sql GoDoc for further usage instructions.

Documentation

Overview

Package duckdb implements a databse/sql driver for the DuckDB database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Composite

type Composite[T any] struct {
	// contains filtered or unexported fields
}

Use as the `Scanner` type for any composite types (maps, lists, structs)

func (Composite[T]) Get

func (s Composite[T]) Get() T

func (*Composite[T]) Scan

func (s *Composite[T]) Scan(v any) error

type HugeInt

type HugeInt C.duckdb_hugeint

HugeInt are composed in a (lower, upper) component The value of the HugeInt is upper * 2^64 + lower

func (HugeInt) Int64

func (v HugeInt) Int64() (int64, error)

func (HugeInt) UUID

func (v HugeInt) UUID() []byte

type Interval

type Interval struct {
	Days   int32 `json:"days"`
	Months int32 `json:"months"`
	Micros int64 `json:"micros"`
}

type Map

type Map map[any]any

func (*Map) Scan

func (m *Map) Scan(v any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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