This repository has been archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.go
80 lines (67 loc) · 1.83 KB
/
schema.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package nero
import (
"github.com/jinzhu/inflection"
"github.com/stevenferrer/mira"
stringsx "github.com/stevenferrer/nero/x/strings"
)
// Schema is a schema used for generating the repository
type Schema struct {
// pkgName is the package name of the generated files
pkgName string
// table is the database table name
table string
// typeInfo is the type info of the schema model
typeInfo *mira.TypeInfo
// identity is the identity field
identity *Field
// fields is the list of fields
fields []*Field
// imports are list of package imports
imports []string
// Templates is the list of custom repository templates
templates []Template
}
// PkgName returns the pkg name
func (s *Schema) PkgName() string {
return s.pkgName
}
// Table returns the database table name
func (s *Schema) Table() string {
return s.table
}
// Identity returns the identity field
func (s *Schema) Identity() *Field {
return s.identity
}
// Fields returns the fields
func (s *Schema) Fields() []*Field {
return s.fields[:]
}
// Imports returns the pkg imports
func (s *Schema) Imports() []string {
return s.imports[:]
}
// Templates returns the templates
func (s *Schema) Templates() []Template {
return s.templates[:]
}
// TypeInfo returns the type info
func (s *Schema) TypeInfo() *mira.TypeInfo {
return s.typeInfo
}
// TypeName returns the type name
func (s *Schema) TypeName() string {
return s.typeInfo.Name()
}
// TypeNamePlural returns the plural form of the type name
func (s *Schema) TypeNamePlural() string {
return inflection.Plural(s.TypeName())
}
// TypeIdentifier returns the type identifier
func (s *Schema) TypeIdentifier() string {
return stringsx.ToLowerCamel(s.TypeName())
}
// TypeIdentifierPlural returns the plural form of type identifier
func (s *Schema) TypeIdentifierPlural() string {
return inflection.Plural(s.TypeIdentifier())
}