db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyPool

func ApplyPool(database *sql.DB, cfg PoolConfig)

func ParseQualifiedName

func ParseQualifiedName(input, defaultSchema string) (schema string, name string, err error)

func Ping

func Ping(ctx context.Context, database *sql.DB, timeout time.Duration) error

func RegisterCatalogTools

func RegisterCatalogTools(srv *server.MCPServer, service CatalogService, opts ToolsetOptions)

func RowsToMaps

func RowsToMaps(rows *sql.Rows, cfg QueryLimits) ([]map[string]any, bool, error)

func ValidateIdentifier

func ValidateIdentifier(value string) error

Types

type BaseConfig

type BaseConfig struct {
	ConnectTimeout  time.Duration
	QueryTimeout    time.Duration
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
	MaxRows         int
	MaxBytes        int
	MaxCellChars    int
	EnableWrite     bool
	WriteAck        string
}

func LoadBaseConfig

func LoadBaseConfig(prefix string) (BaseConfig, error)

func (BaseConfig) Limits

func (c BaseConfig) Limits() QueryLimits

func (BaseConfig) Pool

func (c BaseConfig) Pool() PoolConfig

func (BaseConfig) ValidateWriteOptIn

func (c BaseConfig) ValidateWriteOptIn(prefix string) error

func (BaseConfig) WriteEnabled

func (c BaseConfig) WriteEnabled() bool

type CatalogService

type CatalogService interface {
	Query(ctx context.Context, sql string, maxRows int) (QueryResult, error)
	Execute(ctx context.Context, sql string) (int64, error)
	ListDatabases(ctx context.Context, limit int) ([]map[string]any, error)
	ListSchemas(ctx context.Context, limit int) ([]map[string]any, error)
	ListTables(ctx context.Context, schema string, limit int) ([]map[string]any, error)
	DescribeTable(ctx context.Context, schema, table string) ([]map[string]any, error)
	DefaultSchema() string
}

type PoolConfig

type PoolConfig struct {
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration
	ConnMaxIdleTime time.Duration
}

type QueryLimits

type QueryLimits struct {
	MaxRows      int
	MaxBytes     int
	MaxCellChars int
}

type QueryResult

type QueryResult struct {
	JSON      string
	Rows      int
	Truncated bool
}

func RowsToJSON

func RowsToJSON(rows *sql.Rows, cfg QueryLimits) (QueryResult, error)

type ToolsetOptions

type ToolsetOptions struct {
	DefaultLimit int
	MaxLimit     int
	WriteEnabled bool
}

Jump to

Keyboard shortcuts

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