forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
singular.go
47 lines (42 loc) · 1.08 KB
/
singular.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package inflection
import (
"strings"
upstream "github.com/jinzhu/inflection"
)
type SingularParams struct {
Name string
Exclusions []string
}
func Singular(s SingularParams) string {
for _, exclusion := range s.Exclusions {
if strings.EqualFold(s.Name, exclusion) {
return s.Name
}
}
// Manual fix for incorrect handling of "campus"
//
// https://github.com/sqlc-dev/sqlc/issues/430
// https://github.com/jinzhu/inflection/issues/13
if strings.ToLower(s.Name) == "campus" {
return s.Name
}
// Manual fix for incorrect handling of "meta"
//
// https://github.com/sqlc-dev/sqlc/issues/1217
// https://github.com/jinzhu/inflection/issues/21
if strings.ToLower(s.Name) == "meta" {
return s.Name
}
// Manual fix for incorrect handling of "calories"
//
// https://github.com/sqlc-dev/sqlc/issues/2017
// https://github.com/jinzhu/inflection/issues/23
if strings.ToLower(s.Name) == "calories" {
return "calorie"
}
// Manual fix for incorrect handling of "-ves" suffix
if strings.ToLower(s.Name) == "waves" {
return "wave"
}
return upstream.Singular(s.Name)
}