/
product.go
134 lines (122 loc) · 2.88 KB
/
product.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
*
*
*
* @author John Aran (Ilyas Aranzhanovich Toxanbayev)
* @version 1.0.0
* @based on
* @email il.aranov@gmail.com
* @link
* @github https://github.com/ilyaran/github.com/ilyaran/Malina
* @license MIT License Copyright (c) 2017 John Aran (Ilyas Toxanbayev)
*/ package entity
import (
"time"
"database/sql"
"github.com/lib/pq"
)
type Product struct {
Id int64 `json:"id"`
Code string `json:"code"`
Category int64 `json:"category"`
Parameter []int64 `json:"parameter"`
Img []string `json:"img"`
Title string `json:"title"`
Description string `json:"description"`
Price float64 `json:"price"`
Price1 float64 `json:"price1"`
Price2 float64 `json:"price2"`
Quantity float64 `json:"quantity"`
Sold int64 `json:"sold"`
Views int64 `json:"views"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Enable bool `json:"enable"`
}
func (s *Product) Appending(rows *sql.Rows,size int64)*[]Scanable{
list := make([]Scanable, 0, size)
for rows.Next() {
item := &Product{}
if item.Scanning(nil, rows) == 'o' {
list = append(list, item)
}else {
return nil
}
}
return &list
}
func (s *Product) Item(row *sql.Row) Scanable {
item := Product{}
if item.Scanning(row, nil) == 'o' {
return &item
}
return nil
}
func (s *Product) GetId() int64 {return s.Id}
func (s *Product) SetId(id int64) {s.Id = id}
func (s *Product) GetCode() string {return s.Code}
func (s *Product) GetCategory() int64 {return s.Category}
func (s *Product) GetParameter() []int64 {return s.Parameter}
func (s *Product) GetImg() []string {return s.Img}
func (s *Product) GetTitle() string {return s.Title}
func (s *Product) GetDescription() string {return s.Description}
func (s *Product) GetPrice() float64 {return s.Price}
func (s *Product) GetPrice1() float64 {return s.Price1}
func (s *Product) GetQuantity() float64 {return s.Quantity}
func (s *Product) GetSold() int64 {return s.Sold}
func (s *Product) GetViews() int64 {return s.Views}
func (s *Product) GetCreated() time.Time {return s.Created}
func (s *Product) GetUpdated() time.Time {return s.Updated}
func (s *Product) GetEnable() bool {return s.Enable}
func (s *Product) Scanning(row *sql.Row,rows *sql.Rows)byte {
var err error
if row!=nil {
err = row.Scan(
&s.Id,
&s.Code,
&s.Category,
pq.Array(&s.Parameter),
pq.Array(&s.Img),
&s.Title,
&s.Description,
&s.Price,
&s.Price1,
&s.Price2,
&s.Quantity,
&s.Sold,
&s.Views,
&s.Created,
&s.Updated,
&s.Enable,
)
}
if rows!=nil {
err = rows.Scan(
&s.Id,
&s.Code,
&s.Category,
pq.Array(&s.Parameter),
pq.Array(&s.Img),
&s.Title,
&s.Description,
&s.Price,
&s.Price1,
&s.Price2,
&s.Quantity,
&s.Sold,
&s.Views,
&s.Created,
&s.Updated,
&s.Enable,
)
}
if err == sql.ErrNoRows {
//panic(err)
return 'n'
}
if err != nil {
panic(err)
return 'e'
}
return 'o'
}