Documentation
¶
Index ¶
- func Batch(slice interface{}, size int) [][]interface{}
- func BuildFuncMap() template.FuncMap
- func Chunk(slice interface{}, size int) [][]interface{}
- func Comment(s string, style string) string
- func Concat(slices ...interface{}) []interface{}
- func CountIf(slice interface{}, matches func(interface{}) bool) int
- func Escape(s string) string
- func EscapeQuotes(s string) string
- func FilterCheckConstraints(constraints map[string]*models.Constraint) []*models.Constraint
- func FilterColumns(columns map[string]*models.Column, pattern string) []*models.Column
- func FilterColumnsByType(columns map[string]*models.Column, sqlType string) []*models.Column
- func FilterForeignKeys(constraints map[string]*models.Constraint) []*models.Constraint
- func FilterNotNull(columns map[string]*models.Column) []*models.Column
- func FilterNullable(columns map[string]*models.Column) []*models.Column
- func FilterPrimaryKeys(columns map[string]*models.Column) []*models.Column
- func FilterTables(tables []*models.Table, pattern string) []*models.Table
- func FilterTablesByPattern(tables []*models.Table, pattern string) []*models.Table
- func FilterUniqueConstraints(constraints map[string]*models.Constraint) []*models.Constraint
- func First(slice interface{}, n int) []interface{}
- func Get(m interface{}, key interface{}) interface{}
- func GetOr(m interface{}, key interface{}, defaultValue interface{}) interface{}
- func GetPath(m interface{}, path string) interface{}
- func GetPathOr(m interface{}, path string, defaultValue interface{}) interface{}
- func GroupBy(slice interface{}, field string) map[interface{}][]interface{}
- func Has(m interface{}, key interface{}) bool
- func HasPath(m interface{}, path string) bool
- func HasPrefix(s, prefix string) bool
- func HasSuffix(s, suffix string) bool
- func Indent(s string, spaces int) string
- func IndentWith(s string, prefix string) string
- func IndexOf(slice interface{}, value interface{}) int
- func Join(parts []string, sep string) string
- func Keys(m interface{}) []interface{}
- func Last(slice interface{}, n int) []interface{}
- func Merge(maps ...interface{}) map[interface{}]interface{}
- func Omit(m interface{}, keys ...interface{}) map[interface{}]interface{}
- func Pick(m interface{}, keys ...interface{}) map[interface{}]interface{}
- func Pluck(slice interface{}, field string) []interface{}
- func Pluralize(s string) string
- func QuoteString(s string) string
- func Replace(s, old, newstr string, n int) string
- func Reverse(slice interface{}) []interface{}
- func SQLToCSharp(sqlType string, nullable bool) string
- func SQLToGo(sqlType string, nullable bool) string
- func SQLToJava(sqlType string, nullable bool) string
- func SQLToPhp(sqlType string, nullable bool) string
- func SQLToPython(sqlType string) string
- func SQLToRust(sqlType string, nullable bool) string
- func SQLToTypeScript(sqlType string, nullable bool) string
- func SafeIndex(slice interface{}, index int) interface{}
- func SafeIndexOr(slice interface{}, index int, defaultValue interface{}) interface{}
- func Singularize(s string) string
- func Skip(slice interface{}, n int) []interface{}
- func SliceContains(slice interface{}, value interface{}) bool
- func SortBy(slice interface{}, field string) []interface{}
- func Split(s, sep string) []string
- func StringContains(s, substr string) bool
- func Take(slice interface{}, n int) []interface{}
- func Title(s string) string
- func ToCamelCase(s string) string
- func ToJSON(v interface{}) string
- func ToJSONPretty(v interface{}, indent string) string
- func ToKebabCase(s string) string
- func ToLower(s string) string
- func ToPascalCase(s string) string
- func ToSnakeCase(s string) string
- func ToUpper(s string) string
- func ToYAML(v interface{}) string
- func Trim(s string) string
- func TrimPrefix(s, prefix string) string
- func TrimSuffix(s, suffix string) string
- func Unique(slice interface{}) []interface{}
- func UnquoteString(s string) string
- func Values(m interface{}) []interface{}
- type EntrypointMode
- type EnumeratedItem
- type TemplateData
- func NewDatabaseData(db *models.Database, metadata map[string]interface{}) *TemplateData
- func NewSchemaData(schema *models.Schema, metadata map[string]interface{}) *TemplateData
- func NewScriptData(script *models.Script, schema *models.Schema, db *models.Database, ...) *TemplateData
- func NewTableData(table *models.Table, schema *models.Schema, db *models.Database, ...) *TemplateData
- type TemplateError
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Batch ¶
func Batch(slice interface{}, size int) [][]interface{}
Batch splits a slice into chunks of specified size Usage: {{ range batch .Columns 3 }}...{{ end }}
func BuildFuncMap ¶
BuildFuncMap creates a template.FuncMap with all available helper functions
func Comment ¶
Comment adds comment prefix to a string Supports: "//" (Go, C++, etc.), "#" (Python, shell), "--" (SQL), "/* */" (block) Usage: {{ .Table.Description | comment "//" }}
func Concat ¶
func Concat(slices ...interface{}) []interface{}
Concat concatenates multiple slices Usage: {{ $all := concat .Schema1.Tables .Schema2.Tables }}
func CountIf ¶
CountIf counts items matching a condition Note: Since templates can't pass functions, this is limited Usage in code (not directly in templates)
func Escape ¶
Escape escapes special characters in a string for use in code Usage: {{ .Column.Default | escape }}
func EscapeQuotes ¶
EscapeQuotes escapes only quote characters Usage: {{ .Column.Comment | escapeQuotes }}
func FilterCheckConstraints ¶
func FilterCheckConstraints(constraints map[string]*models.Constraint) []*models.Constraint
FilterCheckConstraints returns only check constraints Usage: {{ $checks := filterCheckConstraints .Table.Constraints }}
func FilterColumns ¶
FilterColumns filters columns from a map using a pattern Usage: {{ $filtered := filterColumns .Table.Columns "*_id" }}
func FilterColumnsByType ¶
FilterColumnsByType filters columns by SQL type Usage: {{ $stringCols := filterColumnsByType .Table.Columns "varchar" }}
func FilterForeignKeys ¶
func FilterForeignKeys(constraints map[string]*models.Constraint) []*models.Constraint
FilterForeignKeys returns only foreign key constraints Usage: {{ $fks := filterForeignKeys .Table.Constraints }}
func FilterNotNull ¶
FilterNotNull returns only non-nullable columns Usage: {{ $required := filterNotNull .Table.Columns }}
func FilterNullable ¶
FilterNullable returns only nullable columns Usage: {{ $nullables := filterNullable .Table.Columns }}
func FilterPrimaryKeys ¶
FilterPrimaryKeys returns only columns that are primary keys Usage: {{ $pks := filterPrimaryKeys .Table.Columns }}
func FilterTables ¶
FilterTables filters tables using a predicate function Usage: {{ $filtered := filterTables .Schema.Tables (func $t) { return hasPrefix $t.Name "user_" } }} Note: Template functions can't pass Go funcs, so this is primarily for internal use
func FilterTablesByPattern ¶
FilterTablesByPattern filters tables by name pattern (glob-style) Usage: {{ $userTables := filterTablesByPattern .Schema.Tables "user_*" }}
func FilterUniqueConstraints ¶
func FilterUniqueConstraints(constraints map[string]*models.Constraint) []*models.Constraint
FilterUniqueConstraints returns only unique constraints Usage: {{ $uniques := filterUniqueConstraints .Table.Constraints }}
func First ¶
func First(slice interface{}, n int) []interface{}
First returns the first N items from a slice Usage: {{ range first .Tables 5 }}...{{ end }}
func Get ¶
func Get(m interface{}, key interface{}) interface{}
Get safely gets a value from a map by key Usage: {{ get .Metadata "key" }}
func GetOr ¶
func GetOr(m interface{}, key interface{}, defaultValue interface{}) interface{}
GetOr safely gets a value from a map with a default fallback Usage: {{ getOr .Metadata "key" "default" }}
func GetPath ¶
func GetPath(m interface{}, path string) interface{}
GetPath safely gets a nested value using dot notation Usage: {{ getPath .Config "database.connection.host" }}
func GetPathOr ¶
func GetPathOr(m interface{}, path string, defaultValue interface{}) interface{}
GetPathOr safely gets a nested value with a default fallback Usage: {{ getPathOr .Config "database.connection.host" "localhost" }}
func GroupBy ¶
func GroupBy(slice interface{}, field string) map[interface{}][]interface{}
GroupBy groups a slice by a field value Usage: {{ $grouped := groupBy .Tables "Schema" }}
func Has ¶
func Has(m interface{}, key interface{}) bool
Has checks if a key exists in a map Usage: {{ if has .Metadata "key" }}...{{ end }}
func HasPath ¶
HasPath checks if a nested path exists Usage: {{ if hasPath .Config "database.connection.host" }}...{{ end }}
func Indent ¶
Indent indents each line of a string by the specified number of spaces Usage: {{ .Column.Description | indent 4 }}
func IndentWith ¶
IndentWith indents each line of a string with a custom prefix Usage: {{ .Column.Description | indentWith " " }}
func IndexOf ¶
func IndexOf(slice interface{}, value interface{}) int
IndexOf returns the index of a value in a slice, or -1 if not found Usage: {{ $idx := indexOf .Names "admin" }}
func Keys ¶
func Keys(m interface{}) []interface{}
Keys returns all keys from a map Usage: {{ range keys .Metadata }}...{{ end }}
func Last ¶
func Last(slice interface{}, n int) []interface{}
Last returns the last N items from a slice Usage: {{ range last .Tables 5 }}...{{ end }}
func Merge ¶
func Merge(maps ...interface{}) map[interface{}]interface{}
Merge merges multiple maps into a new map Usage: {{ $merged := merge .Map1 .Map2 }}
func Omit ¶
func Omit(m interface{}, keys ...interface{}) map[interface{}]interface{}
Omit returns a new map without the specified keys Usage: {{ $filtered := omit .Metadata "internal" "private" }}
func Pick ¶
func Pick(m interface{}, keys ...interface{}) map[interface{}]interface{}
Pick returns a new map with only the specified keys Usage: {{ $subset := pick .Metadata "name" "description" }}
func Pluck ¶
func Pluck(slice interface{}, field string) []interface{}
Pluck extracts a field from each element in a slice Usage: {{ $names := pluck .Tables "Name" }}
func Pluralize ¶
Pluralize converts a singular word to plural Basic implementation with common English rules
func QuoteString ¶
QuoteString adds quotes around a string Usage: {{ .Column.Default | quoteString }}
func Reverse ¶
func Reverse(slice interface{}) []interface{}
Reverse reverses a slice Usage: {{ range reverse .Tables }}...{{ end }}
func SQLToCSharp ¶
SQLToCSharp converts SQL types to C# types
func SQLToPython ¶
SQLToPython converts SQL types to Python types
func SQLToTypeScript ¶
SQLToTypeScript converts SQL types to TypeScript types
func SafeIndex ¶
func SafeIndex(slice interface{}, index int) interface{}
SafeIndex safely gets an element from a slice by index Usage: {{ safeIndex .Tables 0 }}
func SafeIndexOr ¶
func SafeIndexOr(slice interface{}, index int, defaultValue interface{}) interface{}
SafeIndexOr safely gets an element from a slice with a default fallback Usage: {{ safeIndexOr .Tables 0 "default" }}
func Singularize ¶
Singularize converts a plural word to singular Basic implementation with common English rules
func Skip ¶
func Skip(slice interface{}, n int) []interface{}
Skip skips the first N items and returns the rest Usage: {{ range skip .Tables 2 }}...{{ end }}
func SliceContains ¶
func SliceContains(slice interface{}, value interface{}) bool
SliceContains checks if a slice contains a value Usage: {{ if sliceContains .Names "admin" }}...{{ end }}
func SortBy ¶
func SortBy(slice interface{}, field string) []interface{}
SortBy sorts a slice by a field name (for structs) or key (for maps) Usage: {{ $sorted := sortBy .Tables "Name" }} Note: This is a basic implementation that works for simple cases
func StringContains ¶
StringContains checks if substr is within s
func Take ¶
func Take(slice interface{}, n int) []interface{}
Take returns the first N items (alias for First) Usage: {{ range take .Tables 5 }}...{{ end }}
func ToCamelCase ¶
ToCamelCase converts snake_case to camelCase Examples: user_name → userName, http_request → httpRequest
func ToJSON ¶
func ToJSON(v interface{}) string
ToJSON converts a value to JSON string Usage: {{ .Database | toJSON }}
func ToJSONPretty ¶
ToJSONPretty converts a value to pretty-printed JSON string Usage: {{ .Database | toJSONPretty " " }}
func ToKebabCase ¶
ToKebabCase converts snake_case or PascalCase/camelCase to kebab-case Examples: user_name → user-name, UserName → user-name
func ToPascalCase ¶
ToPascalCase converts snake_case to PascalCase Examples: user_name → UserName, http_request → HTTPRequest
func ToSnakeCase ¶
ToSnakeCase converts PascalCase/camelCase to snake_case Examples: UserName → user_name, HTTPRequest → http_request
func ToYAML ¶
func ToYAML(v interface{}) string
ToYAML converts a value to YAML string Usage: {{ .Database | toYAML }}
func TrimPrefix ¶
TrimPrefix removes the prefix from the string if present
func TrimSuffix ¶
TrimSuffix removes the suffix from the string if present
func Unique ¶
func Unique(slice interface{}) []interface{}
Unique removes duplicates from a slice (compares by string representation) Usage: {{ $unique := unique .Items }}
func UnquoteString ¶
UnquoteString removes quotes from a string Usage: {{ .Value | unquoteString }}
Types ¶
type EntrypointMode ¶
type EntrypointMode string
EntrypointMode defines how the template is executed
const ( // DatabaseMode executes the template once for the entire database (single output) DatabaseMode EntrypointMode = "database" // SchemaMode executes the template once per schema (multi-file output) SchemaMode EntrypointMode = "schema" // ScriptMode executes the template once per script (multi-file output) ScriptMode EntrypointMode = "script" // TableMode executes the template once per table (multi-file output) TableMode EntrypointMode = "table" )
type EnumeratedItem ¶
type EnumeratedItem struct {
Index int
Value interface{}
}
EnumeratedItem represents an item with its index
func Enumerate ¶
func Enumerate(slice interface{}) []EnumeratedItem
Enumerate returns a slice with index-value pairs Usage: {{ range enumerate .Tables }}{{ .Index }}: {{ .Value.Name }}{{ end }}
type TemplateData ¶
type TemplateData struct {
// One of these will be populated based on execution mode
Database *models.Database
Schema *models.Schema
Script *models.Script
Table *models.Table
// Context information (parent references)
ParentSchema *models.Schema // Set for table/script modes
ParentDatabase *models.Database // Always set for full database context
// Pre-computed views for convenience
FlatColumns []*models.FlatColumn
FlatTables []*models.FlatTable
FlatConstraints []*models.FlatConstraint
FlatRelationships []*models.FlatRelationship
Summary *models.DatabaseSummary
// User metadata from WriterOptions
Metadata map[string]interface{}
}
TemplateData wraps the model data with additional context for template execution
func NewDatabaseData ¶
func NewDatabaseData(db *models.Database, metadata map[string]interface{}) *TemplateData
NewDatabaseData creates template data for database mode
func NewSchemaData ¶
func NewSchemaData(schema *models.Schema, metadata map[string]interface{}) *TemplateData
NewSchemaData creates template data for schema mode
func NewScriptData ¶
func NewScriptData(script *models.Script, schema *models.Schema, db *models.Database, metadata map[string]interface{}) *TemplateData
NewScriptData creates template data for script mode
func NewTableData ¶
func NewTableData(table *models.Table, schema *models.Schema, db *models.Database, metadata map[string]interface{}) *TemplateData
NewTableData creates template data for table mode
func (*TemplateData) Name ¶
func (td *TemplateData) Name() string
Name returns the primary name for the current template data (used for filename generation)
type TemplateError ¶
TemplateError represents an error that occurred during template operations
func NewTemplateExecuteError ¶
func NewTemplateExecuteError(msg string, err error) *TemplateError
NewTemplateExecuteError creates a new template execution error
func NewTemplateLoadError ¶
func NewTemplateLoadError(msg string, err error) *TemplateError
NewTemplateLoadError creates a new template load error
func NewTemplateParseError ¶
func NewTemplateParseError(msg string, err error) *TemplateError
NewTemplateParseError creates a new template parse error
func (*TemplateError) Error ¶
func (e *TemplateError) Error() string
Error implements the error interface
func (*TemplateError) Unwrap ¶
func (e *TemplateError) Unwrap() error
Unwrap returns the wrapped error
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer implements the writers.Writer interface for template-based output
func NewWriter ¶
func NewWriter(options *writers.WriterOptions) (*Writer, error)
NewWriter creates a new template writer with the given options
func (*Writer) WriteDatabase ¶
WriteDatabase writes a database using the template
func (*Writer) WriteSchema ¶
WriteSchema writes a schema using the template