This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnaming.go
51 lines (41 loc) · 1.44 KB
/
naming.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
48
49
50
51
package sqlr
import (
"github.com/jjeffery/sqlr/private/naming"
)
// The NamingConvention interface provides methods that are used to
// infer a database column name from its associated Go struct field,
// and a database table name from the name of its associated row type.
type NamingConvention interface {
// Convert converts a Go struct field name according to the naming convention.
Convert(fieldName string) string
// Join joins two or more converted names to form a column name.
// Used for naming columns based on fields within embedded
// structures.
Join(names []string) string
// TableName converts the name of the row type into a table name.
TableName(typeName string) string
}
// Pre-defined naming conventions. If a naming convention is not specified
// for a schema, it defaults to snake_case.
var (
SnakeCase NamingConvention // eg "FieldName" -> "field_name"
SameCase NamingConvention // eg "FieldName" -> "FieldName"
LowerCase NamingConvention // eg "FieldName" -> "fieldname"
)
var (
// defaultNamingConvention is used for a schema if no naming
// convention has been specified
defaultNamingConvention = naming.SnakeCase
)
func init() {
SnakeCase = naming.SnakeCase
SameCase = naming.SameCase
LowerCase = naming.LowerCase
}
/**
// PluralizeTableNames returns a naming convention based on nc,
// that pluralizes table names.
func PluralizeTableNames(nc NamingConvention) NamingConvention {
panic("not implemented yet")
}
**/