sqlbinding

package
v0.18.8 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package sqlbinding provides helpers for bindings backed by database/sql drivers: service initialization, the RunCommand implementation, and identifier quoting primitives.

Index

Constants

View Source
const (
	ResultColumns      = "columns"
	ResultRows         = "rows"
	ResultRowsAffected = "rows_affected"
	ResultCommandTag   = "command_tag"
)

RunCommand result keys. These are a wire contract: CLI and app callers address the result with them.

Variables

This section is empty.

Functions

func InitService

func InitService(ctx context.Context, driverName, dsn string, serviceConfig map[string]string,
	runtime binding.ServiceBindingRuntime) (*sql.DB, map[string]string, error)

InitService implements the common InitializeService steps for database/sql bindings: validate the service config keys (url required, binding_hostname optional), open and ping the admin connection with the given DSN (usually the url itself; mysql converts to its DSN format first), and return the effective service config with the localhost binding hostname applied.

func QuoteIdentBracket

func QuoteIdentBracket(name string) string

QuoteIdentBracket quotes an identifier with brackets (SQL Server). Embedded closing brackets are doubled.

func QuoteIdentDouble

func QuoteIdentDouble(name string) string

QuoteIdentDouble quotes an identifier with double quotes (Oracle, Postgres). Embedded double quotes are doubled.

func QuoteStringSingle

func QuoteStringSingle(s string) string

QuoteStringSingle quotes a value as a single-quoted SQL string literal. Embedded single quotes are doubled.

func RunCommand

func RunCommand(ctx context.Context, driverName, dsn, command string, opts RunCommandOptions) (map[string]any, error)

RunCommand implements ServiceBinding.RunCommand for database/sql drivers: it connects with the binding account's DSN, runs the command as a query when it starts with a row-returning keyword and as a statement otherwise, and returns the standard result shape (ResultColumns/ResultRows/ ResultRowsAffected/ResultCommandTag).

Types

type RunCommandOptions

type RunCommandOptions struct {
	// RowReturningKeywords lists leading keywords (upper case) treated as
	// row-returning in addition to SELECT and WITH (e.g. EXEC/EXECUTE for
	// SQL Server).
	RowReturningKeywords []string
}

RunCommandOptions controls RunCommand behavior per dialect.

Jump to

Keyboard shortcuts

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