Documentation
¶
Index ¶
- type DB
- func (db *DB) Close()
- func (db *DB) Exec(ctx context.Context, query string) error
- func (db *DB) GetExtensions(ctx context.Context) ([]Extension, error)
- func (db *DB) QueryArrow(ctx context.Context, query string, allowedSchemas []string, useCache bool) ([]byte, bool, error)
- func (db *DB) QueryJSON(ctx context.Context, query string, allowedSchemas []string, useCache bool) (json.RawMessage, bool, error)
- func (db *DB) ValidateSQL(ctx context.Context, sql string, validators ...Validator) error
- func (db *DB) WriteArrow(ctx context.Context, query string, allowedSchemas []string, w io.Writer) error
- func (db *DB) WriteJSON(ctx context.Context, query string, allowedSchemas []string, w io.Writer) error
- type ErrorDetails
- type Extension
- type OptionFunc
- func WithFunctionBlocklist(blockedFunctions []string) OptionFunc
- func WithLogger(logger *slog.Logger) OptionFunc
- func WithMaxCacheBytes(cacheBytes int) OptionFunc
- func WithMaxCacheEntries(cacheEntries int) OptionFunc
- func WithMaxConnections(maxConnections int) OptionFunc
- func WithTTL(ttl time.Duration) OptionFunc
- type Options
- type Validator
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) QueryArrow ¶
func (*DB) ValidateSQL ¶
ValidateSQL validates the given SQL query using the provided validators
func (*DB) WriteArrow ¶
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 OptionFunc ¶
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 }
Click to show internal directories.
Click to hide internal directories.