duckdbinit

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package duckdbinit builds and applies the session-scoped initialization (INSTALL/LOAD/SET/PRAGMA) that every pooled DuckDB connection must run on open. Session-scoped statements issued through the pool reach only one arbitrary connection (issues #245, #285); the connector init hook returned by MakeConnInit runs them for each new physical connection instead.

Index

Constants

View Source
const DefaultInitTimeout = 5 * time.Second

DefaultInitTimeout bounds one hook run (all init statements of a single new physical connection). It matches the 5s ping bound both constructors use, and the pre-#285 exporter's construction-time init deadline.

Variables

This section is empty.

Functions

func MakeConnInit

func MakeConnInit(steps []Step, log *zap.SugaredLogger, initTimeout time.Duration) func(driver.ExecerContext) error

MakeConnInit returns the connector init hook the driver runs for every new physical connection. Failed statements are logged and skipped so a degraded init never blocks the connection; construction-time errors are limited to the credential validation done by the statement builders.

Each hook run executes its statements under one shared initTimeout deadline: driver cancellation rides on the context passed to ExecContext, so an unbounded context would let a stalled INSTALL/LOAD block connection establishment (and thereby constructors) indefinitely. A non-positive initTimeout disables the bound.

func ValidateS3Credential

func ValidateS3Credential(name, value string) error

ValidateS3Credential checks that an S3 credential value is safe to embed in a DuckDB SET statement. DuckDB's PRAGMA/SET does not support parameterized queries, so the value is checked against a denylist of characters instead. Rejected characters: single-quote ('), double-quote ("), semicolon (;), backslash (\), and space.

Types

type Step

type Step struct {
	Stmts []Stmt
}

Step groups statements that depend on each other: when one fails, the step's remaining statements are skipped (an extension whose INSTALL fails must not be LOADed), while later steps still run.

func ExtensionStep

func ExtensionStep(ext string) Step

ExtensionStep pairs an extension's INSTALL and LOAD into one step, so a failed INSTALL skips that extension's LOAD.

func SingleStmtStep

func SingleStmtStep(sql, label string) Step

SingleStmtStep wraps one independent statement in its own step.

type Stmt

type Stmt struct {
	SQL   string
	Label string
}

Stmt is a single statement executed on every new physical DuckDB connection.

Jump to

Keyboard shortcuts

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