/
gen.go
161 lines (139 loc) · 5.62 KB
/
gen.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package query
import (
"context"
"database/sql"
"gorm.io/gorm"
"gorm.io/gen"
"gorm.io/plugin/dbresolver"
)
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Category: newCategory(db, opts...),
Item: newItem(db, opts...),
ItemVersion: newItemVersion(db, opts...),
Property: newProperty(db, opts...),
PropertyConfig: newPropertyConfig(db, opts...),
PropertyConfigEnumRelation: newPropertyConfigEnumRelation(db, opts...),
PropertyEnum: newPropertyEnum(db, opts...),
PropertyValue: newPropertyValue(db, opts...),
Sku: newSku(db, opts...),
SkuInventory: newSkuInventory(db, opts...),
SkuInventoryLog: newSkuInventoryLog(db, opts...),
SkuInventoryRelation: newSkuInventoryRelation(db, opts...),
Spu: newSpu(db, opts...),
}
}
type Query struct {
db *gorm.DB
Category category
Item item
ItemVersion itemVersion
Property property
PropertyConfig propertyConfig
PropertyConfigEnumRelation propertyConfigEnumRelation
PropertyEnum propertyEnum
PropertyValue propertyValue
Sku sku
SkuInventory skuInventory
SkuInventoryLog skuInventoryLog
SkuInventoryRelation skuInventoryRelation
Spu spu
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Category: q.Category.clone(db),
Item: q.Item.clone(db),
ItemVersion: q.ItemVersion.clone(db),
Property: q.Property.clone(db),
PropertyConfig: q.PropertyConfig.clone(db),
PropertyConfigEnumRelation: q.PropertyConfigEnumRelation.clone(db),
PropertyEnum: q.PropertyEnum.clone(db),
PropertyValue: q.PropertyValue.clone(db),
Sku: q.Sku.clone(db),
SkuInventory: q.SkuInventory.clone(db),
SkuInventoryLog: q.SkuInventoryLog.clone(db),
SkuInventoryRelation: q.SkuInventoryRelation.clone(db),
Spu: q.Spu.clone(db),
}
}
func (q *Query) ReadDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
}
func (q *Query) WriteDB() *Query {
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
}
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
Category: q.Category.replaceDB(db),
Item: q.Item.replaceDB(db),
ItemVersion: q.ItemVersion.replaceDB(db),
Property: q.Property.replaceDB(db),
PropertyConfig: q.PropertyConfig.replaceDB(db),
PropertyConfigEnumRelation: q.PropertyConfigEnumRelation.replaceDB(db),
PropertyEnum: q.PropertyEnum.replaceDB(db),
PropertyValue: q.PropertyValue.replaceDB(db),
Sku: q.Sku.replaceDB(db),
SkuInventory: q.SkuInventory.replaceDB(db),
SkuInventoryLog: q.SkuInventoryLog.replaceDB(db),
SkuInventoryRelation: q.SkuInventoryRelation.replaceDB(db),
Spu: q.Spu.replaceDB(db),
}
}
type queryCtx struct {
Category *categoryDo
Item *itemDo
ItemVersion *itemVersionDo
Property *propertyDo
PropertyConfig *propertyConfigDo
PropertyConfigEnumRelation *propertyConfigEnumRelationDo
PropertyEnum *propertyEnumDo
PropertyValue *propertyValueDo
Sku *skuDo
SkuInventory *skuInventoryDo
SkuInventoryLog *skuInventoryLogDo
SkuInventoryRelation *skuInventoryRelationDo
Spu *spuDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Category: q.Category.WithContext(ctx),
Item: q.Item.WithContext(ctx),
ItemVersion: q.ItemVersion.WithContext(ctx),
Property: q.Property.WithContext(ctx),
PropertyConfig: q.PropertyConfig.WithContext(ctx),
PropertyConfigEnumRelation: q.PropertyConfigEnumRelation.WithContext(ctx),
PropertyEnum: q.PropertyEnum.WithContext(ctx),
PropertyValue: q.PropertyValue.WithContext(ctx),
Sku: q.Sku.WithContext(ctx),
SkuInventory: q.SkuInventory.WithContext(ctx),
SkuInventoryLog: q.SkuInventoryLog.WithContext(ctx),
SkuInventoryRelation: q.SkuInventoryRelation.WithContext(ctx),
Spu: q.Spu.WithContext(ctx),
}
}
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
}
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
return &QueryTx{q.clone(q.db.Begin(opts...))}
}
type QueryTx struct{ *Query }
func (q *QueryTx) Commit() error {
return q.db.Commit().Error
}
func (q *QueryTx) Rollback() error {
return q.db.Rollback().Error
}
func (q *QueryTx) SavePoint(name string) error {
return q.db.SavePoint(name).Error
}
func (q *QueryTx) RollbackTo(name string) error {
return q.db.RollbackTo(name).Error
}