-
Notifications
You must be signed in to change notification settings - Fork 6
/
dataDescTypeTable.go
57 lines (52 loc) · 2.22 KB
/
dataDescTypeTable.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
package db
import (
. "github.com/goradd/goradd/pkg/orm/query"
)
// TypeTableDescription describes a type table, which essentially defines an enumerated type.
// In the SQL world, they are a table with an integer key (starting index 1) and a "name" value, though
// they can have other values associated with them too. Goradd will maintain the
// relationships in SQL, but in a No-SQL situation, it will embed all the ids and values.
type TypeTableDescription struct {
// DbKey is the key used to find the database in the global database cluster
DbKey string
// DbName is the name of the table in the database
DbName string
// EnglishName is the english name of the object when describing it to the world. Use the "literalName" option in the comment to override the default.
EnglishName string
// EnglishPlural is the plural english name of the object. Use the "literalPlural" option in the comment to override the default.
EnglishPlural string
// GoName is the name of the item as a go type name.
GoName string
// GoPlural is the plural of the go type
GoPlural string
// LcGoName is the lower case version of the go name
LcGoName string
// FieldNames are the names of the fields defined in the table. The first field name MUST be the name of the id field, and 2nd MUST be the name of the name field, the others are optional extra fields.
FieldNames []string
// FieldTypes are the go column types of the fields, indexed by field name
FieldTypes map[string]GoColumnType
// Values are the constant values themselves as defined in the table, mapped to field names in each row.
Values []map[string]interface{}
// PkField is the name of the private key field
PkField string
// Filled in by analyzer
Constants map[uint]string
}
// FieldGoName returns the go name corresponding to the given field offset
func (tt *TypeTableDescription) FieldGoName(i int) string {
if i >= len(tt.FieldNames) {
return ""
}
fn := tt.FieldNames[i]
fn = UpperCaseIdentifier(fn)
return fn
}
// FieldGoColumnType returns the GoColumnType corresponding to the given field offset
func (tt *TypeTableDescription) FieldGoColumnType(i int) GoColumnType {
if i >= len(tt.FieldNames) {
return ColTypeUnknown
}
fn := tt.FieldNames[i]
ft := tt.FieldTypes[fn]
return ft
}