-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcolumn.go
73 lines (63 loc) · 1.84 KB
/
column.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
package dsc
import (
"github.com/viant/toolbox"
"reflect"
)
type TableColumn struct {
ColumnName string `column:"column_name"`
DataType string `column:"data_type"`
DataTypeLength *int64 `column:"data_type_length"`
NumericPrecision *int64 `column:"numeric_precision"`
NumericScale *int64 `column:"numeric_scale"`
IsNullable interface{} `column:"is_nullable"`
Position int `column:"position"`
scanType reflect.Type
}
func (c *TableColumn) Name() string {
return c.ColumnName
}
func (c *TableColumn) Length() (length int64, ok bool) {
if c.DataTypeLength == nil {
return 0, false
}
return *c.DataTypeLength, true
}
func (c *TableColumn) DecimalSize() (precision, scale int64, ok bool) {
if c.NumericPrecision == nil || c.NumericScale == nil {
return 0, 0, false
}
return *c.NumericPrecision, *c.NumericScale, true
}
func (c *TableColumn) ScanType() reflect.Type {
return c.scanType
}
func (c *TableColumn) Nullable() (nullable, ok bool) {
if c.IsNullable == nil {
return false, false
}
return toolbox.AsBoolean(c.IsNullable), true
}
// Common type include "VARCHAR", "TEXT", "NVARCHAR", "DECIMAL", "BOOL", "INT", "BIGINT".
func (c *TableColumn) DatabaseTypeName() string {
return c.DataType
}
//NewColumn create new TableColumn
func NewColumn(name, typeName string, length, precision, scale *int64, scanType reflect.Type, nullable *bool) Column {
var result = &TableColumn{
ColumnName: name,
DataType: typeName,
DataTypeLength: length,
NumericPrecision: precision,
NumericScale: scale,
scanType: scanType,
IsNullable: nullable,
}
return result
}
//NewSimpleColumn create simple TableColumn name
func NewSimpleColumn(name, typeName string) Column {
return &TableColumn{
ColumnName: name,
DataType: typeName,
}
}