utils

package
v1.8.7 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package utils provides shared helper functions for SQL generation and value formatting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertDefaultValue

func ConvertDefaultValue(schema *types.Schema, databaseType string, defaultValue string) string

ConvertDefaultValue converts a YAML default value to database-specific SQL This is a common utility function that all providers can use

func FormatDefaultValue

func FormatDefaultValue(value string) string

FormatDefaultValue formats a default value for use in SQL DDL. SQL expressions, numeric values, and boolean/null literals are returned verbatim. All other values are wrapped in single quotes as string literals.

func HandleFallbackDefault

func HandleFallbackDefault(defaultValue string) string

HandleFallbackDefault handles cases where no schema mapping exists. It normalises NULL to uppercase and delegates to FormatDefaultValue for expression detection and proper formatting.

func IsSQLExpression

func IsSQLExpression(value string) bool

IsSQLExpression returns true when the value is already a valid SQL expression that should be emitted verbatim rather than wrapped in single quotes. This covers:

  • Single-quoted string literals already in SQL form: 'value', '[]'::jsonb
  • SQL function calls: gen_random_uuid(), uuid_generate_v4()
  • Type cast expressions: '{}'::jsonb
  • SQL keywords (all-uppercase, letters and underscores): CURRENT_TIMESTAMP
  • NULL/null, TRUE/true, FALSE/false literals

func SafeConstraintName

func SafeConstraintName(name string) string

SafeConstraintName returns a PostgreSQL-safe constraint name (max 63 chars). If the full name exceeds 63 characters, it is truncated to 54 chars and an 8-hex-char FNV-32a hash of the original name is appended (54+1+8=63).

Types

This section is empty.

Jump to

Keyboard shortcuts

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