forked from go-reform/reform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
76 lines (65 loc) · 1.67 KB
/
models.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
package main
import (
"database/sql"
"fmt"
)
//go:generate reform
type yesNo bool
func (yn *yesNo) Scan(src interface{}) error {
var str string
switch s := src.(type) {
case string:
str = s
case []byte:
str = string(s)
default:
return fmt.Errorf("unexpected type %T (%#v)", src, src)
}
switch str {
case "YES":
*yn = true
case "NO":
*yn = false
default:
return fmt.Errorf("unexpected %q", str)
}
return nil
}
// check interface
var _ sql.Scanner = (*yesNo)(nil)
//reform:information_schema.tables
type table struct {
TableCatalog string `reform:"table_catalog"`
TableSchema string `reform:"table_schema"`
TableName string `reform:"table_name"`
TableType string `reform:"table_type"`
}
//reform:information_schema.columns
type column struct {
TableCatalog string `reform:"table_catalog"`
TableSchema string `reform:"table_schema"`
TableName string `reform:"table_name"`
Name string `reform:"column_name"`
IsNullable yesNo `reform:"is_nullable"`
Type string `reform:"data_type"`
}
//reform:information_schema.key_column_usage
type keyColumnUsage struct {
ColumnName string `reform:"column_name"`
OrdinalPosition int `reform:"ordinal_position"`
}
//reform:sqlite_master
type sqliteMaster struct {
Name string `reform:"name"`
}
// TODO This "dummy" table name is ugly. We should do better.
// See https://github.com/go-reform/reform/issues/107.
//reform:dummy
type sqliteTableInfo struct {
CID int `reform:"cid"`
Name string `reform:"name"`
Type string `reform:"type"`
NotNull bool `reform:"notnull"`
DefaultValue *string `reform:"dflt_value"`
PK bool `reform:"pk"`
}