29 lines
676 B
Go
29 lines
676 B
Go
// Package database define database operation functions
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
|
|
"modelRT/orm"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// QueryComponentColumnNames returns all column names from the component table.
|
|
func QueryComponentColumnNames(ctx context.Context, db *gorm.DB) ([]string, error) {
|
|
columnTypes, err := db.WithContext(ctx).Migrator().ColumnTypes((&orm.Component{}).TableName())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
columnNames := make([]string, 0, len(columnTypes))
|
|
for _, columnType := range columnTypes {
|
|
columnName := columnType.Name()
|
|
if columnName == "" {
|
|
continue
|
|
}
|
|
columnNames = append(columnNames, columnName)
|
|
}
|
|
return columnNames, nil
|
|
}
|