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>
283 lines
7.3 KiB
Go
283 lines
7.3 KiB
Go
package models
|
|
|
|
import (
|
|
"sort"
|
|
"strings"
|
|
)
|
|
|
|
// SortOrder represents the sort direction
|
|
type SortOrder bool
|
|
|
|
const (
|
|
// Ascending sort order
|
|
Ascending SortOrder = false
|
|
// Descending sort order
|
|
Descending SortOrder = true
|
|
)
|
|
|
|
// Schema Sorting
|
|
|
|
// SortSchemasByName sorts schemas by name
|
|
func SortSchemasByName(schemas []*Schema, desc bool) error {
|
|
sort.SliceStable(schemas, func(i, j int) bool {
|
|
cmp := strings.Compare(strings.ToLower(schemas[i].Name), strings.ToLower(schemas[j].Name))
|
|
if desc {
|
|
return cmp > 0
|
|
}
|
|
return cmp < 0
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// SortSchemasBySequence sorts schemas by sequence number
|
|
func SortSchemasBySequence(schemas []*Schema, desc bool) error {
|
|
sort.SliceStable(schemas, func(i, j int) bool {
|
|
if desc {
|
|
return schemas[i].Sequence > schemas[j].Sequence
|
|
}
|
|
return schemas[i].Sequence < schemas[j].Sequence
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// Table Sorting
|
|
|
|
// SortTablesByName sorts tables by name
|
|
func SortTablesByName(tables []*Table, desc bool) error {
|
|
sort.SliceStable(tables, func(i, j int) bool {
|
|
cmp := strings.Compare(strings.ToLower(tables[i].Name), strings.ToLower(tables[j].Name))
|
|
if desc {
|
|
return cmp > 0
|
|
}
|
|
return cmp < 0
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// SortTablesBySequence sorts tables by sequence number
|
|
func SortTablesBySequence(tables []*Table, desc bool) error {
|
|
sort.SliceStable(tables, func(i, j int) bool {
|
|
if desc {
|
|
return tables[i].Sequence > tables[j].Sequence
|
|
}
|
|
return tables[i].Sequence < tables[j].Sequence
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// Column Sorting
|
|
|
|
// SortColumnsMapByName converts column map to sorted slice by name
|
|
func SortColumnsMapByName(columns map[string]*Column, desc bool) []*Column {
|
|
result := make([]*Column, 0, len(columns))
|
|
for _, col := range columns {
|
|
result = append(result, col)
|
|
}
|
|
_ = SortColumnsByName(result, desc)
|
|
return result
|
|
}
|
|
|
|
// SortColumnsMapBySequence converts column map to sorted slice by sequence
|
|
func SortColumnsMapBySequence(columns map[string]*Column, desc bool) []*Column {
|
|
result := make([]*Column, 0, len(columns))
|
|
for _, col := range columns {
|
|
result = append(result, col)
|
|
}
|
|
_ = SortColumnsBySequence(result, desc)
|
|
return result
|
|
}
|
|
|
|
// SortColumnsByName sorts columns by name
|
|
func SortColumnsByName(columns []*Column, desc bool) error {
|
|
sort.SliceStable(columns, func(i, j int) bool {
|
|
cmp := strings.Compare(strings.ToLower(columns[i].Name), strings.ToLower(columns[j].Name))
|
|
if desc {
|
|
return cmp > 0
|
|
}
|
|
return cmp < 0
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// SortColumnsBySequence sorts columns by sequence number
|
|
func SortColumnsBySequence(columns []*Column, desc bool) error {
|
|
sort.SliceStable(columns, func(i, j int) bool {
|
|
if desc {
|
|
return columns[i].Sequence > columns[j].Sequence
|
|
}
|
|
return columns[i].Sequence < columns[j].Sequence
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// View Sorting
|
|
|
|
// SortViewsByName sorts views by name
|
|
func SortViewsByName(views []*View, desc bool) error {
|
|
sort.SliceStable(views, func(i, j int) bool {
|
|
cmp := strings.Compare(strings.ToLower(views[i].Name), strings.ToLower(views[j].Name))
|
|
if desc {
|
|
return cmp > 0
|
|
}
|
|
return cmp < 0
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// SortViewsBySequence sorts views by sequence number
|
|
func SortViewsBySequence(views []*View, desc bool) error {
|
|
sort.SliceStable(views, func(i, j int) bool {
|
|
if desc {
|
|
return views[i].Sequence > views[j].Sequence
|
|
}
|
|
return views[i].Sequence < views[j].Sequence
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// Sequence Sorting
|
|
|
|
// SortSequencesByName sorts sequences by name
|
|
func SortSequencesByName(sequences []*Sequence, desc bool) error {
|
|
sort.SliceStable(sequences, func(i, j int) bool {
|
|
cmp := strings.Compare(strings.ToLower(sequences[i].Name), strings.ToLower(sequences[j].Name))
|
|
if desc {
|
|
return cmp > 0
|
|
}
|
|
return cmp < 0
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// SortSequencesBySequence sorts sequences by sequence number
|
|
func SortSequencesBySequence(sequences []*Sequence, desc bool) error {
|
|
sort.SliceStable(sequences, func(i, j int) bool {
|
|
if desc {
|
|
return sequences[i].Sequence > sequences[j].Sequence
|
|
}
|
|
return sequences[i].Sequence < sequences[j].Sequence
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// Index Sorting
|
|
|
|
// SortIndexesMapByName converts index map to sorted slice by name
|
|
func SortIndexesMapByName(indexes map[string]*Index, desc bool) []*Index {
|
|
result := make([]*Index, 0, len(indexes))
|
|
for _, idx := range indexes {
|
|
result = append(result, idx)
|
|
}
|
|
_ = SortIndexesByName(result, desc)
|
|
return result
|
|
}
|
|
|
|
// SortIndexesMapBySequence converts index map to sorted slice by sequence
|
|
func SortIndexesMapBySequence(indexes map[string]*Index, desc bool) []*Index {
|
|
result := make([]*Index, 0, len(indexes))
|
|
for _, idx := range indexes {
|
|
result = append(result, idx)
|
|
}
|
|
_ = SortIndexesBySequence(result, desc)
|
|
return result
|
|
}
|
|
|
|
// SortIndexesByName sorts indexes by name
|
|
func SortIndexesByName(indexes []*Index, desc bool) error {
|
|
sort.SliceStable(indexes, func(i, j int) bool {
|
|
cmp := strings.Compare(strings.ToLower(indexes[i].Name), strings.ToLower(indexes[j].Name))
|
|
if desc {
|
|
return cmp > 0
|
|
}
|
|
return cmp < 0
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// SortIndexesBySequence sorts indexes by sequence number
|
|
func SortIndexesBySequence(indexes []*Index, desc bool) error {
|
|
sort.SliceStable(indexes, func(i, j int) bool {
|
|
if desc {
|
|
return indexes[i].Sequence > indexes[j].Sequence
|
|
}
|
|
return indexes[i].Sequence < indexes[j].Sequence
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// Constraint Sorting
|
|
|
|
// SortConstraintsMapByName converts constraint map to sorted slice by name
|
|
func SortConstraintsMapByName(constraints map[string]*Constraint, desc bool) []*Constraint {
|
|
result := make([]*Constraint, 0, len(constraints))
|
|
for _, c := range constraints {
|
|
result = append(result, c)
|
|
}
|
|
_ = SortConstraintsByName(result, desc)
|
|
return result
|
|
}
|
|
|
|
// SortConstraintsByName sorts constraints by name
|
|
func SortConstraintsByName(constraints []*Constraint, desc bool) error {
|
|
sort.SliceStable(constraints, func(i, j int) bool {
|
|
cmp := strings.Compare(strings.ToLower(constraints[i].Name), strings.ToLower(constraints[j].Name))
|
|
if desc {
|
|
return cmp > 0
|
|
}
|
|
return cmp < 0
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// Relationship Sorting
|
|
|
|
// SortRelationshipsMapByName converts relationship map to sorted slice by name
|
|
func SortRelationshipsMapByName(relationships map[string]*Relationship, desc bool) []*Relationship {
|
|
result := make([]*Relationship, 0, len(relationships))
|
|
for _, r := range relationships {
|
|
result = append(result, r)
|
|
}
|
|
_ = SortRelationshipsByName(result, desc)
|
|
return result
|
|
}
|
|
|
|
// SortRelationshipsByName sorts relationships by name
|
|
func SortRelationshipsByName(relationships []*Relationship, desc bool) error {
|
|
sort.SliceStable(relationships, func(i, j int) bool {
|
|
cmp := strings.Compare(strings.ToLower(relationships[i].Name), strings.ToLower(relationships[j].Name))
|
|
if desc {
|
|
return cmp > 0
|
|
}
|
|
return cmp < 0
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// Script Sorting
|
|
|
|
// SortScriptsByName sorts scripts by name
|
|
func SortScriptsByName(scripts []*Script, desc bool) error {
|
|
sort.SliceStable(scripts, func(i, j int) bool {
|
|
cmp := strings.Compare(strings.ToLower(scripts[i].Name), strings.ToLower(scripts[j].Name))
|
|
if desc {
|
|
return cmp > 0
|
|
}
|
|
return cmp < 0
|
|
})
|
|
return nil
|
|
}
|
|
|
|
// Enum Sorting
|
|
|
|
// SortEnumsByName sorts enums by name
|
|
func SortEnumsByName(enums []*Enum, desc bool) error {
|
|
sort.SliceStable(enums, func(i, j int) bool {
|
|
cmp := strings.Compare(strings.ToLower(enums[i].Name), strings.ToLower(enums[j].Name))
|
|
if desc {
|
|
return cmp > 0
|
|
}
|
|
return cmp < 0
|
|
})
|
|
return nil
|
|
}
|