Documentation
¶
Overview ¶
Package sanitize provides field-name sanitisation for TDTP schema imports.
Many legacy databases (MS Access, older MSSQL, exported CSVs) use field names that are illegal or problematic as SQL identifiers in other databases: spaces, percent signs, Cyrillic/European characters, № signs, etc.
Usage:
opts := sanitize.Options{Clear: true, Translit: true}
changed := sanitize.ApplyToSchema(&pkt.Schema, opts)
for _, r := range changed {
fmt.Printf(" '%s' → '%s'\n", r.OriginalName, r.SafeName)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Clear replaces special ASCII symbols (%, @, #, …) with safe tokens
// and collapses any remaining non-ASCII characters to underscore.
Clear bool
// Translit converts non-ASCII characters (Cyrillic, European diacritics,
// Greek, etc.) to their closest ASCII equivalents via go-unidecode before
// applying the Clear rules. Has no effect when Clear is also false.
Translit bool
}
Options controls how field names are sanitized.
type Result ¶
type Result struct {
SafeName string // safe SQL identifier after sanitisation
OriginalName string // original name before sanitisation
}
Result holds the outcome for a single field name.
func ApplyToSchema ¶
ApplyToSchema sanitizes all field names in a TDTP schema in-place.
For each field whose name changes, Field.OriginalName is set to the pre-sanitisation value so that database adapters can store it as a column comment (PostgreSQL COMMENT ON COLUMN, MySQL inline COMMENT).
Returns a slice of changed results (empty when nothing needed renaming). Row data is positional and is never touched.
func SanitizeFieldName ¶
SanitizeFieldName transforms a single field name into a safe SQL identifier.
- If neither Clear nor Translit is set, the name is returned unchanged.
- Translit (go-unidecode) is applied first, converting non-ASCII chars to their closest ASCII representations.
- Clear then applies the symbol map and collapses any remaining non-ASCII/non-identifier characters to underscore.
- Consecutive underscores are collapsed; digits at the start are prefixed with an underscore; an empty result becomes "_field".