query

package
v0.0.0-...-5dae8fa Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: BSD-3-Clause, ISC Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

func New

func New(ctx context.Context, connector *duckdb.Connector, opts ...OptionFunc) (*DB, error)

New creates a new DB instance using the provided DuckDB connector, opening a sql.DB and arrow connection. The logger is optional; if nil, it defaults to slog.Default().

func (*DB) Close

func (db *DB) Close()

Close closes any resources created by New, but does not close the underlying connector.

func (*DB) Exec

func (db *DB) Exec(ctx context.Context, query string) error

func (*DB) GetExtensions

func (db *DB) GetExtensions(ctx context.Context) ([]Extension, error)

func (*DB) QueryArrow

func (db *DB) QueryArrow(ctx context.Context, query string, allowedSchemas []string, useCache bool) ([]byte, bool, error)

func (*DB) QueryJSON

func (db *DB) QueryJSON(ctx context.Context, query string, allowedSchemas []string, useCache bool) (json.RawMessage, bool, error)

func (*DB) ValidateSQL

func (db *DB) ValidateSQL(ctx context.Context, sql string, validators ...Validator) error

ValidateSQL validates the given SQL query using the provided validators

func (*DB) WriteArrow

func (db *DB) WriteArrow(ctx context.Context, query string, allowedSchemas []string, w io.Writer) error

func (*DB) WriteJSON

func (db *DB) WriteJSON(ctx context.Context, query string, allowedSchemas []string, w io.Writer) error

type ErrorDetails

type ErrorDetails struct {
	Type     string `json:"error_type"`
	Subtype  string `json:"error_subtype"`
	Message  string `json:"error_message"`
	Position string `json:"position"`
}

func (ErrorDetails) Error

func (e ErrorDetails) Error() string

type Extension

type Extension struct {
	Name        string `json:"name"`
	Version     string `json:"version"`
	Repository  string `json:"repository"`
	InstallMode string `json:"install_mode"`
}

type OptionFunc

type OptionFunc func(*Options) error

func WithFunctionBlocklist

func WithFunctionBlocklist(blockedFunctions []string) OptionFunc

func WithLogger

func WithLogger(logger *slog.Logger) OptionFunc

func WithMaxCacheBytes

func WithMaxCacheBytes(cacheBytes int) OptionFunc

func WithMaxCacheEntries

func WithMaxCacheEntries(cacheEntries int) OptionFunc

func WithMaxConnections

func WithMaxConnections(maxConnections int) OptionFunc

func WithTTL

func WithTTL(ttl time.Duration) OptionFunc

type Options

type Options struct {
	// MaxConnections sets the maximum number of open connections to the database.
	MaxConnections int

	// MaxCacheEntries sets the maximum size of the query result cache.
	MaxCacheEntries int

	// MaxCacheBytes sets the maximum total size in bytes of all entries in the query result cache.
	MaxCacheBytes int

	// TTL sets the time-to-live for cache entries. If zero, entries do not expire.
	TTL time.Duration

	// Logger is the logger to use for logging. If nil, defaults to slog.Default().
	Logger *slog.Logger

	// FunctionBlocklist is a list of function names that are not allowed to be used in queries.
	// This is useful for blocking functions that may pose security or performance risks.
	FunctionBlocklist []string
}

type Validator

type Validator interface {
	// CheckNode is called once for each node in the AST
	// - node: the current node being processed
	// - keyStack: contains the stack of keys leading to this node, with the root being the first element,
	//   and the parent key being the last element
	//
	// This explicitly does not not return an error. Any errors found should be collected and returned
	// in the Validate() method.
	CheckNode(node map[string]any, keyStack []string)

	// Validate is called after the entire AST has been processed. It should return any errors found during
	// the CheckNode calls, or any additional validation errors that can only be determined after
	// processing the entire AST. This allows validators to collect state during the AST traversal and perform more
	// complex validation that may depend on multiple nodes or the overall structure of the AST.
	//
	// It returns a slice of errors, to encourage collecting all errors rather than stopping at the first one.
	// If no errors are found, it should return nil.
	Validate() []error
}

Jump to

Keyboard shortcuts

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