1package sqlmock
2
3import "reflect"
4
5// Column is a mocked column Metadata for rows.ColumnTypes()
6type Column struct {
7	name       string
8	dbType     string
9	nullable   bool
10	nullableOk bool
11	length     int64
12	lengthOk   bool
13	precision  int64
14	scale      int64
15	psOk       bool
16	scanType   reflect.Type
17}
18
19func (c *Column) Name() string {
20	return c.name
21}
22
23func (c *Column) DbType() string {
24	return c.dbType
25}
26
27func (c *Column) IsNullable() (bool, bool) {
28	return c.nullable, c.nullableOk
29}
30
31func (c *Column) Length() (int64, bool) {
32	return c.length, c.lengthOk
33}
34
35func (c *Column) PrecisionScale() (int64, int64, bool) {
36	return c.precision, c.scale, c.psOk
37}
38
39func (c *Column) ScanType() reflect.Type {
40	return c.scanType
41}
42
43// NewColumn returns a Column with specified name
44func NewColumn(name string) *Column {
45	return &Column{
46		name: name,
47	}
48}
49
50// Nullable returns the column with nullable metadata set
51func (c *Column) Nullable(nullable bool) *Column {
52	c.nullable = nullable
53	c.nullableOk = true
54	return c
55}
56
57// OfType returns the column with type metadata set
58func (c *Column) OfType(dbType string, sampleValue interface{}) *Column {
59	c.dbType = dbType
60	c.scanType = reflect.TypeOf(sampleValue)
61	return c
62}
63
64// WithLength returns the column with length metadata set.
65func (c *Column) WithLength(length int64) *Column {
66	c.length = length
67	c.lengthOk = true
68	return c
69}
70
71// WithPrecisionAndScale returns the column with precision and scale metadata set.
72func (c *Column) WithPrecisionAndScale(precision, scale int64) *Column {
73	c.precision = precision
74	c.scale = scale
75	c.psOk = true
76	return c
77}
78