nginx-proxy-manager-zh/backend/internal/database/helpers.go

40 lines
923 B
Go
Raw Normal View History

package database
2023-05-30 23:52:58 -04:00
import (
"fmt"
"npm/internal/config"
"strings"
)
const (
// DateFormat for DateFormat
DateFormat = "2006-01-02"
// DateTimeFormat for DateTimeFormat
DateTimeFormat = "2006-01-02T15:04:05"
)
2023-05-30 23:52:58 -04:00
// QuoteTableName is a special function that will quote a table
// name based on the driver. Gorm normally handles this but this
// is for special cases where we run raw sql
func QuoteTableName(tbl string) string {
switch strings.ToLower(config.Configuration.DB.Driver) {
2024-09-11 05:38:41 -04:00
case config.DatabaseMysql:
// backticks for mysql
2023-05-30 23:52:58 -04:00
return fmt.Sprintf("`%s`", tbl)
2024-09-11 05:38:41 -04:00
default:
// double quotes for everything else
return fmt.Sprintf(`"%s"`, tbl)
2023-05-30 23:52:58 -04:00
}
}
2023-05-31 01:11:25 -04:00
// GetCaseInsensitiveLike returns a different operator based on
// the db driver
func GetCaseInsensitiveLike() string {
switch strings.ToLower(config.Configuration.DB.Driver) {
case config.DatabasePostgres:
return "ILIKE"
default:
return "LIKE"
}
}