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
- func BuildGetObjectsRecordReader(mem memory.Allocator, in <-chan GetObjectsInfo, errCh <-chan error) (array.RecordReader, error)
- func Nullable[T any](val T) *T
- func PatternToNamedArg(name string, pattern *string) sql.NamedArg
- func RequiredList[T any](vals []T) requiredList[T]
- func ToXdbcDataType(dt arrow.DataType) (xdbcType internal.XdbcDataType)
- func ValueOrZero[T any](val *T) T
- type AutocommitSetter
- type ColumnInfo
- type Connection
- type ConnectionBuilder
- func (b *ConnectionBuilder) Connection() Connection
- func (b *ConnectionBuilder) WithAutocommitSetter(helper AutocommitSetter) *ConnectionBuilder
- func (b *ConnectionBuilder) WithConcurrency(concurrency int) *ConnectionBuilder
- func (b *ConnectionBuilder) WithCurrentNamespacer(helper CurrentNamespacer) *ConnectionBuilder
- func (b *ConnectionBuilder) WithDbObjectsEnumerator(helper DbObjectsEnumerator) *ConnectionBuilder
- func (b *ConnectionBuilder) WithDriverInfoPreparer(helper DriverInfoPreparer) *ConnectionBuilder
- func (b *ConnectionBuilder) WithTableTypeLister(helper TableTypeLister) *ConnectionBuilder
- type ConnectionImpl
- type ConnectionImplBase
- func (base *ConnectionImplBase) Base() *ConnectionImplBase
- func (base *ConnectionImplBase) Close() error
- func (base *ConnectionImplBase) Commit(ctx context.Context) error
- func (base *ConnectionImplBase) GetInfo(ctx context.Context, infoCodes []adbc.InfoCode) (array.RecordReader, error)
- func (base *ConnectionImplBase) GetObjects(ctx context.Context, depth adbc.ObjectDepth, catalog *string, dbSchema *string, ...) (array.RecordReader, error)
- func (base *ConnectionImplBase) GetOption(key string) (string, error)
- func (base *ConnectionImplBase) GetOptionBytes(key string) ([]byte, error)
- func (base *ConnectionImplBase) GetOptionDouble(key string) (float64, error)
- func (base *ConnectionImplBase) GetOptionInt(key string) (int64, error)
- func (base *ConnectionImplBase) GetTableSchema(ctx context.Context, catalog *string, dbSchema *string, tableName string) (*arrow.Schema, error)
- func (base *ConnectionImplBase) GetTableTypes(context.Context) (array.RecordReader, error)
- func (base *ConnectionImplBase) NewStatement() (adbc.Statement, error)
- func (base *ConnectionImplBase) ReadPartition(ctx context.Context, serializedPartition []byte) (array.RecordReader, error)
- func (base *ConnectionImplBase) Rollback(context.Context) error
- func (base *ConnectionImplBase) SetOption(key string, val string) error
- func (base *ConnectionImplBase) SetOptionBytes(key string, val []byte) error
- func (base *ConnectionImplBase) SetOptionDouble(key string, val float64) error
- func (base *ConnectionImplBase) SetOptionInt(key string, val int64) error
- type ConstraintColumnUsage
- type ConstraintInfo
- type CurrentNamespacer
- type DBSchemaInfo
- type Database
- type DatabaseImpl
- type DatabaseImplBase
- func (base *DatabaseImplBase) Base() *DatabaseImplBase
- func (base *DatabaseImplBase) Close() error
- func (base *DatabaseImplBase) GetOption(key string) (string, error)
- func (base *DatabaseImplBase) GetOptionBytes(key string) ([]byte, error)
- func (base *DatabaseImplBase) GetOptionDouble(key string) (float64, error)
- func (base *DatabaseImplBase) GetOptionInt(key string) (int64, error)
- func (base *DatabaseImplBase) Open(ctx context.Context) (adbc.Connection, error)
- func (base *DatabaseImplBase) SetOption(key string, val string) error
- func (base *DatabaseImplBase) SetOptionBytes(key string, val []byte) error
- func (base *DatabaseImplBase) SetOptionDouble(key string, val float64) error
- func (base *DatabaseImplBase) SetOptionInt(key string, val int64) error
- func (base *DatabaseImplBase) SetOptions(options map[string]string) error
- type DbObjectsEnumerator
- type Driver
- type DriverImpl
- type DriverImplBase
- type DriverInfo
- type DriverInfoPreparer
- type ErrorHelper
- type GetObjectsInfo
- type TableInfo
- type TableTypeLister
Constants ¶
const ( ConnectionMessageOptionUnknown = "Unknown connection option" ConnectionMessageOptionUnsupported = "Unsupported connection option" ConnectionMessageCannotCommit = "Cannot commit when autocommit is enabled" ConnectionMessageCannotRollback = "Cannot rollback when autocommit is enabled" )
const ( UnknownVersion = "(unknown or development build)" DefaultInfoDriverADBCVersion = adbc.AdbcVersion1_1_0 )
const (
DatabaseMessageOptionUnknown = "Unknown database option"
)
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 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 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 ToXdbcDataType ¶ added in v1.2.0
func ToXdbcDataType(dt arrow.DataType) (xdbcType internal.XdbcDataType)
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.
Types ¶
type AutocommitSetter ¶
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 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 Autocommit bool Closed bool }
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) (array.RecordReader, error)
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 (*ConnectionImplBase) GetTableTypes ¶
func (base *ConnectionImplBase) GetTableTypes(context.Context) (array.RecordReader, error)
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
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 ¶
type Database interface { adbc.Database adbc.GetSetOptions adbc.DatabaseLogging }
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 }
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(driver *DriverImplBase) DatabaseImplBase
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() error
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) 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
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 ¶
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 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 ¶
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.
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 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 ¶
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.