Some checks failed
CI / Lint (push) Successful in -27m59s
CI / Test (1.25) (push) Successful in -27m46s
CI / Test (1.24) (push) Failing after 59s
CI / Build (push) Successful in -28m14s
Integration Tests / Integration Tests (push) Failing after -28m16s
Release / Build and Release (push) Successful in 1m1s
feat(templ): ✨ added templ to command line that reads go template and outputs code Reviewed-on: #1 Co-authored-by: Hein <hein.puth@gmail.com> Co-committed-by: Hein <hein.puth@gmail.com>
172 lines
5.1 KiB
Go
172 lines
5.1 KiB
Go
package template
|
|
|
|
import (
|
|
"text/template"
|
|
|
|
"git.warky.dev/wdevs/relspecgo/pkg/models"
|
|
)
|
|
|
|
// BuildFuncMap creates a template.FuncMap with all available helper functions
|
|
func BuildFuncMap() template.FuncMap {
|
|
return template.FuncMap{
|
|
// String manipulation functions
|
|
"toUpper": ToUpper,
|
|
"toLower": ToLower,
|
|
"toCamelCase": ToCamelCase,
|
|
"toPascalCase": ToPascalCase,
|
|
"toSnakeCase": ToSnakeCase,
|
|
"toKebabCase": ToKebabCase,
|
|
"pluralize": Pluralize,
|
|
"singularize": Singularize,
|
|
"title": Title,
|
|
"trim": Trim,
|
|
"trimPrefix": TrimPrefix,
|
|
"trimSuffix": TrimSuffix,
|
|
"replace": Replace,
|
|
"stringContains": StringContains, // Avoid conflict with slice contains
|
|
"hasPrefix": HasPrefix,
|
|
"hasSuffix": HasSuffix,
|
|
"split": Split,
|
|
"join": Join,
|
|
|
|
// Type conversion functions
|
|
"sqlToGo": SQLToGo,
|
|
"sqlToTypeScript": SQLToTypeScript,
|
|
"sqlToJava": SQLToJava,
|
|
"sqlToPython": SQLToPython,
|
|
"sqlToRust": SQLToRust,
|
|
"sqlToCSharp": SQLToCSharp,
|
|
"sqlToPhp": SQLToPhp,
|
|
|
|
// Filtering functions
|
|
"filterTables": FilterTables,
|
|
"filterTablesByPattern": FilterTablesByPattern,
|
|
"filterColumns": FilterColumns,
|
|
"filterColumnsByType": FilterColumnsByType,
|
|
"filterPrimaryKeys": FilterPrimaryKeys,
|
|
"filterForeignKeys": FilterForeignKeys,
|
|
"filterUniqueConstraints": FilterUniqueConstraints,
|
|
"filterCheckConstraints": FilterCheckConstraints,
|
|
"filterNullable": FilterNullable,
|
|
"filterNotNull": FilterNotNull,
|
|
|
|
// Formatting functions
|
|
"toJSON": ToJSON,
|
|
"toJSONPretty": ToJSONPretty,
|
|
"toYAML": ToYAML,
|
|
"indent": Indent,
|
|
"indentWith": IndentWith,
|
|
"escape": Escape,
|
|
"escapeQuotes": EscapeQuotes,
|
|
"comment": Comment,
|
|
"quoteString": QuoteString,
|
|
"unquoteString": UnquoteString,
|
|
|
|
// Loop/iteration helper functions
|
|
"enumerate": Enumerate,
|
|
"batch": Batch,
|
|
"chunk": Chunk,
|
|
"reverse": Reverse,
|
|
"first": First,
|
|
"last": Last,
|
|
"skip": Skip,
|
|
"take": Take,
|
|
"concat": Concat,
|
|
"unique": Unique,
|
|
"sortBy": SortBy,
|
|
"groupBy": GroupBy,
|
|
|
|
// Safe access functions
|
|
"get": Get,
|
|
"getOr": GetOr,
|
|
"getPath": GetPath,
|
|
"getPathOr": GetPathOr,
|
|
"safeIndex": SafeIndex,
|
|
"safeIndexOr": SafeIndexOr,
|
|
"has": Has,
|
|
"hasPath": HasPath,
|
|
"keys": Keys,
|
|
"values": Values,
|
|
"merge": Merge,
|
|
"pick": Pick,
|
|
"omit": Omit,
|
|
"sliceContains": SliceContains,
|
|
"indexOf": IndexOf,
|
|
"pluck": Pluck,
|
|
|
|
// Sorting functions
|
|
"sortSchemasByName": models.SortSchemasByName,
|
|
"sortSchemasBySequence": models.SortSchemasBySequence,
|
|
"sortTablesByName": models.SortTablesByName,
|
|
"sortTablesBySequence": models.SortTablesBySequence,
|
|
"sortColumnsByName": models.SortColumnsByName,
|
|
"sortColumnsBySequence": models.SortColumnsBySequence,
|
|
"sortColumnsMapByName": models.SortColumnsMapByName,
|
|
"sortColumnsMapBySequence": models.SortColumnsMapBySequence,
|
|
"sortViewsByName": models.SortViewsByName,
|
|
"sortViewsBySequence": models.SortViewsBySequence,
|
|
"sortSequencesByName": models.SortSequencesByName,
|
|
"sortSequencesBySequence": models.SortSequencesBySequence,
|
|
"sortIndexesByName": models.SortIndexesByName,
|
|
"sortIndexesBySequence": models.SortIndexesBySequence,
|
|
"sortIndexesMapByName": models.SortIndexesMapByName,
|
|
"sortIndexesMapBySequence": models.SortIndexesMapBySequence,
|
|
"sortConstraintsByName": models.SortConstraintsByName,
|
|
"sortConstraintsMapByName": models.SortConstraintsMapByName,
|
|
"sortRelationshipsByName": models.SortRelationshipsByName,
|
|
"sortRelationshipsMapByName": models.SortRelationshipsMapByName,
|
|
"sortScriptsByName": models.SortScriptsByName,
|
|
"sortEnumsByName": models.SortEnumsByName,
|
|
|
|
// Utility functions (built-in Go template helpers + custom)
|
|
"add": func(a, b int) int { return a + b },
|
|
"sub": func(a, b int) int { return a - b },
|
|
"mul": func(a, b int) int { return a * b },
|
|
"div": func(a, b int) int {
|
|
if b == 0 {
|
|
return 0
|
|
}
|
|
return a / b
|
|
},
|
|
"mod": func(a, b int) int {
|
|
if b == 0 {
|
|
return 0
|
|
}
|
|
return a % b
|
|
},
|
|
"default": func(defaultVal, val interface{}) interface{} {
|
|
if val == nil {
|
|
return defaultVal
|
|
}
|
|
return val
|
|
},
|
|
"dict": func(values ...interface{}) map[string]interface{} {
|
|
if len(values)%2 != 0 {
|
|
return nil
|
|
}
|
|
dict := make(map[string]interface{}, len(values)/2)
|
|
for i := 0; i < len(values); i += 2 {
|
|
key, ok := values[i].(string)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
dict[key] = values[i+1]
|
|
}
|
|
return dict
|
|
},
|
|
"list": func(values ...interface{}) []interface{} {
|
|
return values
|
|
},
|
|
"seq": func(start, end int) []int {
|
|
if start > end {
|
|
return []int{}
|
|
}
|
|
result := make([]int, end-start+1)
|
|
for i := range result {
|
|
result[i] = start + i
|
|
}
|
|
return result
|
|
},
|
|
}
|
|
}
|