driverbase

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package driverbase provides a framework for implementing ADBC drivers in Go. It intends to reduce boilerplate for common functionality and managing state transitions.

Index

Constants

View Source
const (
	ConnectionMessageOptionUnknown              = "Unknown connection option"
	ConnectionMessageOptionUnsupported          = "Unsupported connection option"
	ConnectionMessageCannotCommit               = "Cannot commit when autocommit is enabled"
	ConnectionMessageCannotRollback             = "Cannot rollback when autocommit is enabled"
	ConnectionMessageTraceParentIncorrectFormat = "Incorrect or unsupported trace parent format"
)
View Source
const (
	TraceExporterNone traceExporterType = iota
	TraceExporterOtlp
	TraceExporterConsole
	TraceExporterAdbcFile
)
View Source
const (
	DatabaseMessageOptionUnknown                   = "Unknown database option"
	DatabaseMessageOtelTracesExporterOptionUnknown = "Unknown " + otelTracesExporter + " option"
	DatabaseMessageNoOtelTracesExporters           = "No trace exporters added"
)
View Source
const (
	UnknownVersion               = "(unknown or development build)"
	DefaultInfoDriverADBCVersion = adbc.AdbcVersion1_1_0
)
View Source
const (
	StatementMessageOptionUnknown              = "Unknown statement option"
	StatementMessageOptionUnsupported          = "Unsupported statement option"
	StatementMessageTraceParentIncorrectFormat = "Incorrect or unsupported trace parent format"
)

Variables

This section is empty.

Functions

func BuildGetObjectsRecordReader added in v1.2.0

func BuildGetObjectsRecordReader(mem memory.Allocator, in <-chan GetObjectsInfo, errCh <-chan error) (array.RecordReader, error)

BuildGetObjectsRecordReader constructs a RecordReader for the GetObjects ADBC method. It accepts a channel of GetObjectsInfo to allow concurrent retrieval of metadata and serialization to Arrow record.

func NewRotatingFileWriter added in v1.7.0

func NewRotatingFileWriter(options ...rotatingFileWriterOption) (*rotatingFileWriterImpl, error)

Creates a new RotatingFileWriter from the given options

func Nullable added in v1.2.0

func Nullable[T any](val T) *T

Nullable wraps a value and returns a pointer to the value, which is how nullable values are represented for purposes of JSON serialization.

func PatternToNamedArg added in v1.2.0

func PatternToNamedArg(name string, pattern *string) sql.NamedArg

func RequiredList added in v1.2.0

func RequiredList[T any](vals []T) requiredList[T]

RequiredList is a wrapper for a slice of values that is not considered "nullable" for serialization purposes. When marshaling JSON, the empty value is serialized as "[]" instead of "null".

func SetOTelDriverInfoAttributes added in v1.7.0

func SetOTelDriverInfoAttributes(driverInfo *DriverInfo, span trace.Span)

func ValueOrZero added in v1.2.0

func ValueOrZero[T any](val *T) T

ValueOrZero safely dereferences a pointer, returning the zero-value of the underlying type in the case of a nil pointer.

func WithFileCountMax added in v1.7.0

func WithFileCountMax(fileCountMax int) rotatingFileWriterOption

Adds the FileCountMax option

func WithFileSizeMaxKb added in v1.7.0

func WithFileSizeMaxKb(fileSizeMaxKb int64) rotatingFileWriterOption

Adds the FileSizeMaxKb option

func WithLogNamePrefix added in v1.7.0

func WithLogNamePrefix(logNamePrefix string) rotatingFileWriterOption

Adds the LogNamePrefix option

func WithTracingFolderPath added in v1.7.0

func WithTracingFolderPath(tracingFolderPath string) rotatingFileWriterOption

Adds the TracingFolderPath option

Types

type AutocommitSetter

type AutocommitSetter interface {
	SetAutocommit(enabled bool) error
}

AutocommitSetter is an interface that drivers may implement to simplify the implementation of autocommit state management. There is no need to implement this for backends that do not support autocommit, as this is already the default behavior. SetAutocommit should only attempt to update the autocommit state in the backend. Local driver state is automatically updated if the result of this call does not produce an error. (Get/Set)Options implementations are provided automatically as well/

type ColumnInfo added in v1.2.0

type ColumnInfo struct {
	ColumnName            string  `json:"column_name"`
	OrdinalPosition       *int32  `json:"ordinal_position,omitempty"`
	Remarks               *string `json:"remarks,omitempty"`
	XdbcDataType          *int16  `json:"xdbc_data_type,omitempty"`
	XdbcTypeName          *string `json:"xdbc_type_name,omitempty"`
	XdbcColumnSize        *int32  `json:"xdbc_column_size,omitempty"`
	XdbcDecimalDigits     *int16  `json:"xdbc_decimal_digits,omitempty"`
	XdbcNumPrecRadix      *int16  `json:"xdbc_num_prec_radix,omitempty"`
	XdbcNullable          *int16  `json:"xdbc_nullable,omitempty"`
	XdbcColumnDef         *string `json:"xdbc_column_def,omitempty"`
	XdbcSqlDataType       *int16  `json:"xdbc_sql_data_type,omitempty"`
	XdbcDatetimeSub       *int16  `json:"xdbc_datetime_sub,omitempty"`
	XdbcCharOctetLength   *int32  `json:"xdbc_char_octet_length,omitempty"`
	XdbcIsNullable        *string `json:"xdbc_is_nullable,omitempty"`
	XdbcScopeCatalog      *string `json:"xdbc_scope_catalog,omitempty"`
	XdbcScopeSchema       *string `json:"xdbc_scope_schema,omitempty"`
	XdbcScopeTable        *string `json:"xdbc_scope_table,omitempty"`
	XdbcIsAutoincrement   *bool   `json:"xdbc_is_autoincrement,omitempty"`
	XdbcIsGeneratedcolumn *bool   `json:"xdbc_is_generatedcolumn,omitempty"`
}

ColumnInfo is a structured representation of adbc.ColumnSchema

type Connection

type Connection interface {
	adbc.Connection
	adbc.GetSetOptions
}

Connection is the interface satisfied by the result of the NewConnection constructor, given that an input is provided satisfying the ConnectionImpl interface.

type ConnectionBuilder

type ConnectionBuilder struct {
	// contains filtered or unexported fields
}

func NewConnectionBuilder

func NewConnectionBuilder(impl ConnectionImpl) *ConnectionBuilder

func (*ConnectionBuilder) Connection

func (b *ConnectionBuilder) Connection() Connection

func (*ConnectionBuilder) WithAutocommitSetter

func (b *ConnectionBuilder) WithAutocommitSetter(helper AutocommitSetter) *ConnectionBuilder

func (*ConnectionBuilder) WithConcurrency added in v1.2.0

func (b *ConnectionBuilder) WithConcurrency(concurrency int) *ConnectionBuilder

func (*ConnectionBuilder) WithCurrentNamespacer

func (b *ConnectionBuilder) WithCurrentNamespacer(helper CurrentNamespacer) *ConnectionBuilder

func (*ConnectionBuilder) WithDbObjectsEnumerator

func (b *ConnectionBuilder) WithDbObjectsEnumerator(helper DbObjectsEnumerator) *ConnectionBuilder

func (*ConnectionBuilder) WithDriverInfoPreparer

func (b *ConnectionBuilder) WithDriverInfoPreparer(helper DriverInfoPreparer) *ConnectionBuilder

func (*ConnectionBuilder) WithTableTypeLister

func (b *ConnectionBuilder) WithTableTypeLister(helper TableTypeLister) *ConnectionBuilder

type ConnectionImpl

type ConnectionImpl interface {
	adbc.Connection
	adbc.GetSetOptions
	adbc.OTelTracing
	Base() *ConnectionImplBase
}

ConnectionImpl is an interface that drivers implement to provide vendor-specific functionality.

type ConnectionImplBase

type ConnectionImplBase struct {
	Alloc       memory.Allocator
	ErrorHelper ErrorHelper
	DriverInfo  *DriverInfo
	Logger      *slog.Logger
	Tracer      trace.Tracer

	Autocommit bool
	Closed     bool
	// contains filtered or unexported fields
}

ConnectionImplBase is a struct that provides default implementations of the ConnectionImpl interface. It is meant to be used as a composite struct for a driver's ConnectionImpl implementation.

func NewConnectionImplBase

func NewConnectionImplBase(database *DatabaseImplBase) ConnectionImplBase

NewConnectionImplBase instantiates ConnectionImplBase.

  • database is a DatabaseImplBase containing the common resources from the parent database, allowing the Arrow allocator, error handler, and logger to be reused.

func (*ConnectionImplBase) Base

func (base *ConnectionImplBase) Base() *ConnectionImplBase

func (*ConnectionImplBase) Close

func (base *ConnectionImplBase) Close() error

func (*ConnectionImplBase) Commit

func (base *ConnectionImplBase) Commit(ctx context.Context) error

func (*ConnectionImplBase) GetInfo

func (base *ConnectionImplBase) GetInfo(ctx context.Context, infoCodes []adbc.InfoCode) (reader array.RecordReader, err error)

func (*ConnectionImplBase) GetInitialSpanAttributes added in v1.7.0

func (cnxn *ConnectionImplBase) GetInitialSpanAttributes() []attribute.KeyValue

func (*ConnectionImplBase) GetObjects

func (base *ConnectionImplBase) GetObjects(ctx context.Context, depth adbc.ObjectDepth, catalog *string, dbSchema *string, tableName *string, columnName *string, tableType []string) (array.RecordReader, error)

func (*ConnectionImplBase) GetOption

func (base *ConnectionImplBase) GetOption(key string) (string, error)

func (*ConnectionImplBase) GetOptionBytes

func (base *ConnectionImplBase) GetOptionBytes(key string) ([]byte, error)

func (*ConnectionImplBase) GetOptionDouble

func (base *ConnectionImplBase) GetOptionDouble(key string) (float64, error)

func (*ConnectionImplBase) GetOptionInt

func (base *ConnectionImplBase) GetOptionInt(key string) (int64, error)

func (*ConnectionImplBase) GetTableSchema

func (base *ConnectionImplBase) GetTableSchema(ctx context.Context, catalog *string, dbSchema *string, tableName string) (*arrow.Schema, error)

func (*ConnectionImplBase) GetTableTypes

func (base *ConnectionImplBase) GetTableTypes(context.Context) (array.RecordReader, error)

func (*ConnectionImplBase) GetTraceParent added in v1.7.0

func (cnxn *ConnectionImplBase) GetTraceParent() string

func (*ConnectionImplBase) NewStatement

func (base *ConnectionImplBase) NewStatement() (adbc.Statement, error)

func (*ConnectionImplBase) ReadPartition

func (base *ConnectionImplBase) ReadPartition(ctx context.Context, serializedPartition []byte) (array.RecordReader, error)

func (*ConnectionImplBase) Rollback

func (base *ConnectionImplBase) Rollback(context.Context) error

func (*ConnectionImplBase) SetOption

func (base *ConnectionImplBase) SetOption(key string, val string) error

func (*ConnectionImplBase) SetOptionBytes

func (base *ConnectionImplBase) SetOptionBytes(key string, val []byte) error

func (*ConnectionImplBase) SetOptionDouble

func (base *ConnectionImplBase) SetOptionDouble(key string, val float64) error

func (*ConnectionImplBase) SetOptionInt

func (base *ConnectionImplBase) SetOptionInt(key string, val int64) error

func (*ConnectionImplBase) SetTraceParent added in v1.7.0

func (cnxn *ConnectionImplBase) SetTraceParent(traceParent string)

func (*ConnectionImplBase) StartSpan added in v1.7.0

func (cnxn *ConnectionImplBase) StartSpan(
	ctx context.Context,
	spanName string,
	opts ...trace.SpanStartOption,
) (context.Context, trace.Span)

type ConstraintColumnUsage added in v1.2.0

type ConstraintColumnUsage struct {
	ForeignKeyCatalog  *string `json:"fk_catalog,omitempty"`
	ForeignKeyDbSchema *string `json:"fk_db_schema,omitempty"`
	ForeignKeyTable    string  `json:"fk_table"`
	ForeignKeyColumn   string  `json:"fk_column_name"`
}

ConstraintColumnUsage is a structured representation of adbc.UsageSchema

type ConstraintInfo added in v1.2.0

type ConstraintInfo struct {
	ConstraintName        *string                 `json:"constraint_name,omitempty"`
	ConstraintType        string                  `json:"constraint_type"`
	ConstraintColumnNames requiredList[string]    `json:"constraint_column_names"`
	ConstraintColumnUsage []ConstraintColumnUsage `json:"constraint_column_usage,omitempty"`
}

ConstraintInfo is a structured representation of adbc.ConstraintSchema

type CurrentNamespacer

type CurrentNamespacer interface {
	GetCurrentCatalog() (string, error)
	GetCurrentDbSchema() (string, error)
	SetCurrentCatalog(string) error
	SetCurrentDbSchema(string) error
}

CurrentNamespacer is an interface that drivers may implement to delegate stateful namespacing with DB catalogs and schemas. The appropriate (Get/Set)Options implementations will be provided using the results of these methods.

type DBSchemaInfo added in v1.2.0

type DBSchemaInfo struct {
	DbSchemaName   *string     `json:"db_schema_name,omitempty"`
	DbSchemaTables []TableInfo `json:"db_schema_tables"`
}

DBSchemaInfo is a structured representation of adbc.DBSchemaSchema

type Database

Database is the interface satisfied by the result of the NewDatabase constructor, given an input is provided satisfying the DatabaseImpl interface.

func NewDatabase

func NewDatabase(impl DatabaseImpl) Database

NewDatabase wraps a DatabaseImpl to create an adbc.Database.

type DatabaseImpl

type DatabaseImpl interface {
	adbc.Database
	adbc.GetSetOptions
	Base() *DatabaseImplBase
}

DatabaseImpl is an interface that drivers implement to provide vendor-specific functionality.

type DatabaseImplBase

type DatabaseImplBase struct {
	Alloc       memory.Allocator
	ErrorHelper ErrorHelper
	DriverInfo  *DriverInfo
	Logger      *slog.Logger
	Tracer      trace.Tracer
	// contains filtered or unexported fields
}

DatabaseImplBase is a struct that provides default implementations of the DatabaseImpl interface. It is meant to be used as a composite struct for a driver's DatabaseImpl implementation.

func NewDatabaseImplBase

func NewDatabaseImplBase(ctx context.Context, driver *DriverImplBase) (DatabaseImplBase, error)

NewDatabaseImplBase instantiates DatabaseImplBase.

  • driver is a DriverImplBase containing the common resources from the parent driver, allowing the Arrow allocator and error handler to be reused.

func (*DatabaseImplBase) Base

func (base *DatabaseImplBase) Base() *DatabaseImplBase

func (*DatabaseImplBase) Close

func (base *DatabaseImplBase) Close() (err error)

func (*DatabaseImplBase) GetInitialSpanAttributes added in v1.7.0

func (d *DatabaseImplBase) GetInitialSpanAttributes() []attribute.KeyValue

func (*DatabaseImplBase) GetOption

func (base *DatabaseImplBase) GetOption(key string) (string, error)

func (*DatabaseImplBase) GetOptionBytes

func (base *DatabaseImplBase) GetOptionBytes(key string) ([]byte, error)

func (*DatabaseImplBase) GetOptionDouble

func (base *DatabaseImplBase) GetOptionDouble(key string) (float64, error)

func (*DatabaseImplBase) GetOptionInt

func (base *DatabaseImplBase) GetOptionInt(key string) (int64, error)

func (*DatabaseImplBase) GetTraceParent added in v1.7.0

func (d *DatabaseImplBase) GetTraceParent() (traceParent string)

func (*DatabaseImplBase) InitTracing added in v1.7.0

func (base *DatabaseImplBase) InitTracing(ctx context.Context, driverName string, driverVersion string) (err error)

func (*DatabaseImplBase) Open

func (base *DatabaseImplBase) Open(ctx context.Context) (adbc.Connection, error)

func (*DatabaseImplBase) SetOption

func (base *DatabaseImplBase) SetOption(key string, val string) error

func (*DatabaseImplBase) SetOptionBytes

func (base *DatabaseImplBase) SetOptionBytes(key string, val []byte) error

func (*DatabaseImplBase) SetOptionDouble

func (base *DatabaseImplBase) SetOptionDouble(key string, val float64) error

func (*DatabaseImplBase) SetOptionInt

func (base *DatabaseImplBase) SetOptionInt(key string, val int64) error

func (*DatabaseImplBase) SetOptions

func (base *DatabaseImplBase) SetOptions(options map[string]string) error

func (*DatabaseImplBase) SetTraceParent added in v1.7.0

func (d *DatabaseImplBase) SetTraceParent(traceParent string)

func (*DatabaseImplBase) StartSpan added in v1.7.0

func (d *DatabaseImplBase) StartSpan(
	ctx context.Context,
	spanName string,
	opts ...trace.SpanStartOption,
) (context.Context, trace.Span)

type DbObjectsEnumerator

type DbObjectsEnumerator interface {
	GetCatalogs(ctx context.Context, catalogFilter *string) ([]string, error)
	GetDBSchemasForCatalog(ctx context.Context, catalog string, schemaFilter *string) ([]string, error)
	GetTablesForDBSchema(ctx context.Context, catalog string, schema string, tableFilter *string, columnFilter *string, includeColumns bool) ([]TableInfo, error)
}

DbObjectsEnumerator is an interface that drivers may implement to simplify the implementation of adbc.Connection.GetObjects(). By independently implementing lookup for catalogs, dbSchemas and tables, the driverbase is able to provide the full GetObjects functionality for arbitrary search patterns and lookup depth.

type Driver

type Driver interface {
	adbc.Driver
}

Driver is the interface satisfied by the result of the NewDriver constructor, given an input is provided satisfying the DriverImpl interface.

func NewDriver

func NewDriver(impl DriverImpl) Driver

NewDriver wraps a DriverImpl to create a Driver.

type DriverImpl

type DriverImpl interface {
	adbc.Driver
	adbc.DriverWithContext
	Base() *DriverImplBase
}

DriverImpl is an interface that drivers implement to provide vendor-specific functionality.

type DriverImplBase

type DriverImplBase struct {
	Alloc       memory.Allocator
	ErrorHelper ErrorHelper
	DriverInfo  *DriverInfo
}

DriverImplBase is a struct that provides default implementations of the DriverImpl interface. It is meant to be used as a composite struct for a driver's DriverImpl implementation.

func NewDriverImplBase

func NewDriverImplBase(info *DriverInfo, alloc memory.Allocator) DriverImplBase

NewDriverImplBase instantiates DriverImplBase.

  • info contains build and vendor info, as well as the name to construct error messages.
  • alloc is an Arrow allocator to use.

func (*DriverImplBase) Base

func (base *DriverImplBase) Base() *DriverImplBase

func (*DriverImplBase) NewDatabase

func (base *DriverImplBase) NewDatabase(opts map[string]string) (adbc.Database, error)

func (*DriverImplBase) NewDatabaseWithContext added in v1.7.0

func (base *DriverImplBase) NewDatabaseWithContext(ctx context.Context, opts map[string]string) (adbc.Database, error)

type DriverInfo

type DriverInfo struct {
	// contains filtered or unexported fields
}

func DefaultDriverInfo

func DefaultDriverInfo(name string) *DriverInfo

func (*DriverInfo) GetInfoForInfoCode

func (di *DriverInfo) GetInfoForInfoCode(code adbc.InfoCode) (any, bool)

func (*DriverInfo) GetName

func (di *DriverInfo) GetName() string

func (*DriverInfo) InfoSupportedCodes

func (di *DriverInfo) InfoSupportedCodes() []adbc.InfoCode

func (*DriverInfo) RegisterInfoCode

func (di *DriverInfo) RegisterInfoCode(code adbc.InfoCode, value any) error

type DriverInfoPreparer

type DriverInfoPreparer interface {
	PrepareDriverInfo(ctx context.Context, infoCodes []adbc.InfoCode) error
}

DriverInfoPreparer is an interface that drivers may implement to add/update DriverInfo values whenever adbc.Connection.GetInfo() is called.

type ErrorHelper

type ErrorHelper struct {
	DriverName string
}

ErrorHelper helps format errors for ADBC drivers.

func (*ErrorHelper) Errorf

func (helper *ErrorHelper) Errorf(code adbc.Status, message string, format ...interface{}) error

type GetObjectsInfo added in v1.2.0

type GetObjectsInfo struct {
	CatalogName      *string        `json:"catalog_name,omitempty"`
	CatalogDbSchemas []DBSchemaInfo `json:"catalog_db_schemas"`
}

GetObjectsInfo is a structured representation of adbc.GetObjectsSchema

func (*GetObjectsInfo) Scan added in v1.2.0

func (g *GetObjectsInfo) Scan(src any) error

Scan implements sql.Scanner.

type Statement added in v1.7.0

type Statement interface {
	adbc.Statement
	adbc.GetSetOptions
}

func NewStatement added in v1.7.0

func NewStatement(impl StatementImpl) Statement

type StatementImpl added in v1.7.0

type StatementImplBase added in v1.7.0

type StatementImplBase struct {
	ErrorHelper ErrorHelper
	Tracer      trace.Tracer
	// contains filtered or unexported fields
}

func NewStatementImplBase added in v1.7.0

func NewStatementImplBase(cnxn *ConnectionImplBase, errorHelper ErrorHelper) StatementImplBase

func (*StatementImplBase) GetInitialSpanAttributes added in v1.7.0

func (st *StatementImplBase) GetInitialSpanAttributes() []attribute.KeyValue

func (*StatementImplBase) GetOption added in v1.7.0

func (st *StatementImplBase) GetOption(key string) (string, error)

func (*StatementImplBase) GetOptionBytes added in v1.7.0

func (st *StatementImplBase) GetOptionBytes(key string) ([]byte, error)

func (*StatementImplBase) GetOptionDouble added in v1.7.0

func (st *StatementImplBase) GetOptionDouble(key string) (float64, error)

func (*StatementImplBase) GetOptionInt added in v1.7.0

func (st *StatementImplBase) GetOptionInt(key string) (int64, error)

func (*StatementImplBase) GetTraceParent added in v1.7.0

func (st *StatementImplBase) GetTraceParent() string

func (*StatementImplBase) SetOption added in v1.7.0

func (st *StatementImplBase) SetOption(key, value string) error

func (*StatementImplBase) SetOptionBytes added in v1.7.0

func (st *StatementImplBase) SetOptionBytes(key string, value []byte) error

func (*StatementImplBase) SetOptionDouble added in v1.7.0

func (st *StatementImplBase) SetOptionDouble(key string, value float64) error

func (*StatementImplBase) SetOptionInt added in v1.7.0

func (st *StatementImplBase) SetOptionInt(key string, value int64) error

func (*StatementImplBase) SetTraceParent added in v1.7.0

func (st *StatementImplBase) SetTraceParent(traceParent string)

func (*StatementImplBase) StartSpan added in v1.7.0

func (st *StatementImplBase) StartSpan(
	ctx context.Context,
	spanName string,
	opts ...trace.SpanStartOption,
) (context.Context, trace.Span)

type TableInfo added in v1.2.0

type TableInfo struct {
	TableName        string           `json:"table_name"`
	TableType        string           `json:"table_type"`
	TableColumns     []ColumnInfo     `json:"table_columns"`
	TableConstraints []ConstraintInfo `json:"table_constraints"`
}

TableInfo is a structured representation of adbc.TableSchema

type TableTypeLister

type TableTypeLister interface {
	ListTableTypes(ctx context.Context) ([]string, error)
}

TableTypeLister is an interface that drivers may implement to simplify the implementation of adbc.Connection.GetTableTypes() for backends that do not natively send these values as arrow records. The conversion of the result to a RecordReader is handled automatically.

Jump to

Keyboard shortcuts

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