Documentation
¶
Overview ¶
Package sqlbinding provides helpers for bindings backed by database/sql drivers: service initialization, the RunCommand implementation, and identifier quoting primitives.
Index ¶
- Constants
- func InitService(ctx context.Context, driverName, dsn string, serviceConfig map[string]string, ...) (*sql.DB, map[string]string, error)
- func QuoteIdentBracket(name string) string
- func QuoteIdentDouble(name string) string
- func QuoteStringSingle(s string) string
- func RunCommand(ctx context.Context, driverName, dsn, command string, opts RunCommandOptions) (map[string]any, error)
- type RunCommandOptions
Constants ¶
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 ¶
QuoteIdentBracket quotes an identifier with brackets (SQL Server). Embedded closing brackets are doubled.
func QuoteIdentDouble ¶
QuoteIdentDouble quotes an identifier with double quotes (Oracle, Postgres). Embedded double quotes are doubled.
func QuoteStringSingle ¶
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.