safe

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package safe provides SQL identifier quoting and sanitization utilities to prevent SQL injection in dynamically constructed queries. It implements PostgreSQL-style double-quote quoting by default; dialect-specific quoting is handled at the Dialect layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidIdent

func IsValidIdent(ident string) bool

IsValidIdent checks if a string is a valid unquoted SQL identifier. Valid identifiers contain only ASCII letters, digits, and underscores, and must start with a letter or underscore. An empty string is not valid.

func QuoteIdent

func QuoteIdent(ident string) string

QuoteIdent quotes an identifier (table or column name) safely. It wraps the identifier in double quotes and escapes any embedded double quotes by doubling them. This follows the PostgreSQL quoting convention.

Examples:

QuoteIdent("users")        => `"users"`
QuoteIdent(`my"table`)     => `"my""table"`
QuoteIdent("")             => `""`

func Sanitize

func Sanitize(ident string) string

Sanitize removes any characters that are not safe for SQL identifiers. It preserves only ASCII letters, digits, and underscores. If the result would start with a digit, a leading underscore is prepended. Returns an empty string if no safe characters remain.

Types

This section is empty.

Jump to

Keyboard shortcuts

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