backend

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxConnLifeTime = 10 * time.Minute
	DefaultMaxConnIdleTime = 1 * time.Minute
	DefaultMaxOpenConns    = 10
)

Variables

View Source
var ErrInvalidConfig = errors.New("invalid config")
View Source
var ErrUnknownBackend = errors.New("unknown backend")

Functions

func HasBackend

func HasBackend(str string) bool

func IsDuckDBConnectionString

func IsDuckDBConnectionString(connString string) bool

IsDuckDBConnectionString returns true if the connection string is for duckdb looks for the duckdb:// prefix

func IsMySqlConnectionString

func IsMySqlConnectionString(connString string) bool

IsMySqlConnectionString returns true if the connection string is for mysql looks for the mysql:// prefix

func IsPostgresConnectionString

func IsPostgresConnectionString(connString string) bool

IsPostgresConnectionString returns true if the connection string is for postgres looks for the postgresql:// or postgres:// prefix

func IsSqliteConnectionString

func IsSqliteConnectionString(connString string) bool

IsSqliteConnectionString returns true if the connection string is for sqlite looks for the sqlite:// prefix

Types

type Backend

type Backend interface {
	Connect(context.Context, ...ConnectOption) (*sql.DB, error)
	RowReader() RowReader
	ConnectionString() string
	Name() string
}

func FromConnectionString

func FromConnectionString(ctx context.Context, str string) (Backend, error)

type BasicRowReader

type BasicRowReader struct {
	CellReader func(columnValue any, col *queryresult.ColumnDef) (any, error)
}

BasicRowReader is a RowReader implementation for generic database/sql driver

func NewBasicRowReader

func NewBasicRowReader() *BasicRowReader

func (*BasicRowReader) Read

func (r *BasicRowReader) Read(columnValues []any, cols []*queryresult.ColumnDef) ([]any, error)

type ConnectConfig

type ConnectConfig struct {
	MaxConnLifeTime  time.Duration
	MaxConnIdleTime  time.Duration
	MaxOpenConns     int
	SearchPathConfig SearchPathConfig
}

func NewConnectConfig

func NewConnectConfig(opts []ConnectOption) *ConnectConfig

type ConnectOption

type ConnectOption func(*ConnectConfig)

func WithConfig

func WithConfig(other *ConnectConfig) ConnectOption

func WithSearchPathConfig

func WithSearchPathConfig(config SearchPathConfig) ConnectOption

WithSearchPathConfig sets the search path to use when connecting to the database. If a prefix is also set, the search path will be resolved to the first matching schema in the search path. Only applies if the backend is postgres

type DuckDBBackend

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

func NewDuckDBBackend

func NewDuckDBBackend(connString string) *DuckDBBackend

func (*DuckDBBackend) Connect

func (b *DuckDBBackend) Connect(_ context.Context, options ...ConnectOption) (*sql.DB, error)

Connect implements Backend.

func (*DuckDBBackend) ConnectionString

func (b *DuckDBBackend) ConnectionString() string

func (*DuckDBBackend) Name

func (b *DuckDBBackend) Name() string

func (*DuckDBBackend) RowReader

func (b *DuckDBBackend) RowReader() RowReader

RowReader implements Backend.

type MySQLBackend

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

func NewMySQLBackend

func NewMySQLBackend(connString string) *MySQLBackend

func (*MySQLBackend) Connect

func (b *MySQLBackend) Connect(_ context.Context, options ...ConnectOption) (*sql.DB, error)

Connect implements Backend.

func (*MySQLBackend) ConnectionString

func (b *MySQLBackend) ConnectionString() string

func (*MySQLBackend) Name

func (b *MySQLBackend) Name() string

func (*MySQLBackend) RowReader

func (b *MySQLBackend) RowReader() RowReader

RowReader implements Backend.

type PgxConnector

type PgxConnector struct {
	driver.Connector
	AfterConnectFunc func(context.Context, driver.Conn) error
}

PgxConnector is a wrapper around driver.Connector that allows for a callback to be executed after the connection is established.

func NewPgxConnector

func NewPgxConnector(dataSourceName string, afterConnectFunc func(context.Context, driver.Conn) error) (*PgxConnector, error)

func (*PgxConnector) Connect

func (c *PgxConnector) Connect(ctx context.Context) (driver.Conn, error)

type PoolConfig

type PoolConfig struct {
	MaxConnLifeTime time.Duration
	MaxConnIdleTime time.Duration
	MaxOpenConns    int
}

type PostgresBackend

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

func NewPostgresBackend

func NewPostgresBackend(ctx context.Context, connString string) (*PostgresBackend, error)

func (*PostgresBackend) Connect

func (b *PostgresBackend) Connect(ctx context.Context, opts ...ConnectOption) (*sql.DB, error)

Connect implements Backend.

func (*PostgresBackend) ConnectionString

func (b *PostgresBackend) ConnectionString() string

func (*PostgresBackend) Name

func (b *PostgresBackend) Name() string

func (*PostgresBackend) OriginalSearchPath

func (b *PostgresBackend) OriginalSearchPath() []string

OriginalSearchPath implements SearchPathProvider.

func (*PostgresBackend) RequiredSearchPath

func (b *PostgresBackend) RequiredSearchPath() []string

RequiredSearchPath implements SearchPathProvider

func (*PostgresBackend) ResolvedSearchPath

func (b *PostgresBackend) ResolvedSearchPath() []string

ResolvedSearchPath implements SearchPathProvider

func (*PostgresBackend) RowReader

func (b *PostgresBackend) RowReader() RowReader

RowReader implements Backend.

type RowReader

type RowReader interface {
	Read(columnValues []any, cols []*queryresult.ColumnDef) ([]any, error)
}

type SearchPathConfig

type SearchPathConfig struct {
	SearchPath       []string
	SearchPathPrefix []string
}

func (SearchPathConfig) Empty

func (c SearchPathConfig) Empty() bool

func (SearchPathConfig) String

func (c SearchPathConfig) String() string

type SearchPathProvider

type SearchPathProvider interface {
	OriginalSearchPath() []string
	RequiredSearchPath() []string
	ResolvedSearchPath() []string
}

type SqliteBackend

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

func NewSqliteBackend

func NewSqliteBackend(connString string) *SqliteBackend

func (*SqliteBackend) Connect

func (b *SqliteBackend) Connect(_ context.Context, options ...ConnectOption) (*sql.DB, error)

Connect implements Backend.

func (*SqliteBackend) ConnectionString

func (b *SqliteBackend) ConnectionString() string

func (*SqliteBackend) Name

func (b *SqliteBackend) Name() string

func (*SqliteBackend) RowReader

func (b *SqliteBackend) RowReader() RowReader

RowReader implements Backend.

type SteampipeBackend

type SteampipeBackend struct {
	PostgresBackend
	// map of plugin versions, keyed by image ref
	PluginVersions map[string]*modconfig.PluginVersionString
}

func NewSteampipeBackend

func NewSteampipeBackend(ctx context.Context, postgresBackend PostgresBackend) (*SteampipeBackend, error)

func (*SteampipeBackend) Name

func (b *SteampipeBackend) Name() string

Jump to

Keyboard shortcuts

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