Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
colorway
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
golang
colorway
Commits
136f12ab
Commit
136f12ab
authored
Jul 02, 2025
by
zhengyaoqiu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(colorway): 数据库 model
parent
f8385223
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
27 additions
and
20 deletions
+27
-20
manager.go
internal/pkg/database/mongo/manager.go
+1
-1
model.go
internal/pkg/database/mongo/model/base/model.go
+9
-9
option.go
internal/pkg/database/mongo/model/base/option.go
+1
-1
generate.go
internal/pkg/database/mongo/model/generate.go
+5
-0
error.go
internal/pkg/database/mongo/model/product/error.go
+0
-0
product_model.go
internal/pkg/database/mongo/model/product/product_model.go
+0
-0
product_model_gen.go
...nal/pkg/database/mongo/model/product/product_model_gen.go
+2
-2
product_types.go
internal/pkg/database/mongo/model/product/product_types.go
+0
-0
error.go
.../database/mongo/model/site_platform_price_config/error.go
+0
-0
site_platform_price_config_model.go
...platform_price_config/site_platform_price_config_model.go
+0
-0
site_platform_price_config_model_gen.go
...form_price_config/site_platform_price_config_model_gen.go
+2
-2
site_platform_price_config_types.go
...platform_price_config/site_platform_price_config_types.go
+5
-3
model.tpl
internal/pkg/database/mongo/templates/mongo/model.tpl
+2
-2
No files found.
internal/pkg/database/mongo/manager.go
View file @
136f12ab
package
mongo
package
mongo
import
productModel
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/product"
import
productModel
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/
model/
product"
const
DatabaseColorWay
=
"color_way"
const
DatabaseColorWay
=
"color_way"
...
...
internal/pkg/database/mongo/base/model.go
→
internal/pkg/database/mongo/
model/
base/model.go
View file @
136f12ab
package
base
package
model
import
(
import
(
"context"
"context"
...
@@ -16,15 +16,15 @@ type Model[T any] interface {
...
@@ -16,15 +16,15 @@ type Model[T any] interface {
BulkWrite
(
ctx
context
.
Context
,
writeModels
[]
mongo
.
WriteModel
,
opts
...*
options
.
BulkWriteOptions
)
(
*
mongo
.
BulkWriteResult
,
error
)
BulkWrite
(
ctx
context
.
Context
,
writeModels
[]
mongo
.
WriteModel
,
opts
...*
options
.
BulkWriteOptions
)
(
*
mongo
.
BulkWriteResult
,
error
)
}
}
type
Base
Model
[
T
any
]
struct
{
type
Base
[
T
any
]
struct
{
model
*
mon
.
Model
model
*
mon
.
Model
}
}
func
NewBase
Model
[
T
any
](
model
*
mon
.
Model
)
*
BaseModel
[
T
]
{
func
NewBase
[
T
any
](
model
*
mon
.
Model
)
*
Base
[
T
]
{
return
&
Base
Model
[
T
]{
model
:
model
}
return
&
Base
[
T
]{
model
:
model
}
}
}
func
(
receiver
*
Base
Model
[
T
])
Find
(
ctx
context
.
Context
,
filter
bson
.
M
,
findOptions
...*
options
.
FindOptions
)
([]
T
,
int64
,
error
)
{
func
(
receiver
*
Base
[
T
])
Find
(
ctx
context
.
Context
,
filter
bson
.
M
,
findOptions
...*
options
.
FindOptions
)
([]
T
,
int64
,
error
)
{
total
,
err
:=
receiver
.
model
.
CountDocuments
(
ctx
,
filter
)
total
,
err
:=
receiver
.
model
.
CountDocuments
(
ctx
,
filter
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
...
@@ -34,17 +34,17 @@ func (receiver *BaseModel[T]) Find(ctx context.Context, filter bson.M, findOptio
...
@@ -34,17 +34,17 @@ func (receiver *BaseModel[T]) Find(ctx context.Context, filter bson.M, findOptio
return
documents
,
total
,
err
return
documents
,
total
,
err
}
}
func
(
receiver
*
Base
Model
[
T
])
FindOne
(
ctx
context
.
Context
,
filter
bson
.
M
,
findOneOptions
...*
options
.
FindOneOptions
)
(
T
,
error
)
{
func
(
receiver
*
Base
[
T
])
FindOne
(
ctx
context
.
Context
,
filter
bson
.
M
,
findOneOptions
...*
options
.
FindOneOptions
)
(
T
,
error
)
{
var
document
T
var
document
T
err
:=
receiver
.
model
.
FindOne
(
ctx
,
&
document
,
filter
,
findOneOptions
...
)
err
:=
receiver
.
model
.
FindOne
(
ctx
,
&
document
,
filter
,
findOneOptions
...
)
return
document
,
err
return
document
,
err
}
}
func
(
receiver
*
Base
Model
[
T
])
UpdateOne
(
ctx
context
.
Context
,
filter
bson
.
M
,
update
bson
.
D
,
updateOptions
...*
options
.
UpdateOptions
)
(
*
mongo
.
UpdateResult
,
error
)
{
func
(
receiver
*
Base
[
T
])
UpdateOne
(
ctx
context
.
Context
,
filter
bson
.
M
,
update
bson
.
D
,
updateOptions
...*
options
.
UpdateOptions
)
(
*
mongo
.
UpdateResult
,
error
)
{
return
receiver
.
model
.
UpdateOne
(
ctx
,
filter
,
update
,
updateOptions
...
)
return
receiver
.
model
.
UpdateOne
(
ctx
,
filter
,
update
,
updateOptions
...
)
}
}
func
(
receiver
*
Base
Model
[
T
])
Traverse
(
ctx
context
.
Context
,
filter
bson
.
M
,
f
func
(
document
T
)
(
bool
,
error
),
findOptions
...*
options
.
FindOptions
)
error
{
func
(
receiver
*
Base
[
T
])
Traverse
(
ctx
context
.
Context
,
filter
bson
.
M
,
f
func
(
document
T
)
(
bool
,
error
),
findOptions
...*
options
.
FindOptions
)
error
{
cursor
,
err
:=
receiver
.
model
.
Collection
.
Find
(
ctx
,
filter
,
findOptions
...
)
cursor
,
err
:=
receiver
.
model
.
Collection
.
Find
(
ctx
,
filter
,
findOptions
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -67,6 +67,6 @@ func (receiver *BaseModel[T]) Traverse(ctx context.Context, filter bson.M, f fun
...
@@ -67,6 +67,6 @@ func (receiver *BaseModel[T]) Traverse(ctx context.Context, filter bson.M, f fun
return
nil
return
nil
}
}
func
(
receiver
*
Base
Model
[
T
])
BulkWrite
(
ctx
context
.
Context
,
writeModels
[]
mongo
.
WriteModel
,
opts
...*
options
.
BulkWriteOptions
)
(
*
mongo
.
BulkWriteResult
,
error
)
{
func
(
receiver
*
Base
[
T
])
BulkWrite
(
ctx
context
.
Context
,
writeModels
[]
mongo
.
WriteModel
,
opts
...*
options
.
BulkWriteOptions
)
(
*
mongo
.
BulkWriteResult
,
error
)
{
return
receiver
.
model
.
BulkWrite
(
ctx
,
writeModels
,
opts
...
)
return
receiver
.
model
.
BulkWrite
(
ctx
,
writeModels
,
opts
...
)
}
}
internal/pkg/database/mongo/base/option.go
→
internal/pkg/database/mongo/
model/
base/option.go
View file @
136f12ab
package
base
package
model
import
"go.mongodb.org/mongo-driver/mongo/options"
import
"go.mongodb.org/mongo-driver/mongo/options"
...
...
internal/pkg/database/mongo/generate.go
→
internal/pkg/database/mongo/
model/
generate.go
View file @
136f12ab
package
mo
ngo
package
mo
del
//go:generate goctl
template init --home ./templates
//go:generate goctl
model mongo --type Product --dir product --home ../templates --style go_zero
//go:generate goctl model mongo --type Product --dir product --home ./templates
//go:generate goctl model mongo --type SitePlatformPriceConfig --dir site_platform_price_config --home ../templates --style go_zero
//go:generate goctl model mongo --type SitePlatformPriceConfig --dir site_platform_price_config --home ./templates --style go_zero
internal/pkg/database/mongo/product/error.go
→
internal/pkg/database/mongo/
model/
product/error.go
View file @
136f12ab
File moved
internal/pkg/database/mongo/
product/product
model.go
→
internal/pkg/database/mongo/
model/product/product_
model.go
View file @
136f12ab
File moved
internal/pkg/database/mongo/
product/productmodel
gen.go
→
internal/pkg/database/mongo/
model/product/product_model_
gen.go
View file @
136f12ab
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
package
model
package
model
import
(
import
(
model
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/base"
model
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/
model/
base"
"github.com/zeromicro/go-zero/core/stores/mon"
"github.com/zeromicro/go-zero/core/stores/mon"
)
)
...
@@ -18,6 +18,6 @@ type defaultProductModel struct {
...
@@ -18,6 +18,6 @@ type defaultProductModel struct {
func
newDefaultProductModel
(
conn
*
mon
.
Model
)
*
defaultProductModel
{
func
newDefaultProductModel
(
conn
*
mon
.
Model
)
*
defaultProductModel
{
return
&
defaultProductModel
{
return
&
defaultProductModel
{
conn
:
conn
,
conn
:
conn
,
Model
:
model
.
NewBase
Model
[
Product
](
conn
),
Model
:
model
.
NewBase
[
Product
](
conn
),
}
}
}
}
internal/pkg/database/mongo/
product/product
types.go
→
internal/pkg/database/mongo/
model/product/product_
types.go
View file @
136f12ab
File moved
internal/pkg/database/mongo/site_platform_price_config/error.go
→
internal/pkg/database/mongo/
model/
site_platform_price_config/error.go
View file @
136f12ab
File moved
internal/pkg/database/mongo/site_platform_price_config/site_platform_price_config_model.go
→
internal/pkg/database/mongo/
model/
site_platform_price_config/site_platform_price_config_model.go
View file @
136f12ab
File moved
internal/pkg/database/mongo/site_platform_price_config/site_platform_price_config_model_gen.go
→
internal/pkg/database/mongo/
model/
site_platform_price_config/site_platform_price_config_model_gen.go
View file @
136f12ab
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
package
model
package
model
import
(
import
(
model
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/base"
model
"git.chillcy.com/golang/colorway/internal/pkg/database/mongo/
model/
base"
"github.com/zeromicro/go-zero/core/stores/mon"
"github.com/zeromicro/go-zero/core/stores/mon"
)
)
...
@@ -18,6 +18,6 @@ type defaultSitePlatformPriceConfigModel struct {
...
@@ -18,6 +18,6 @@ type defaultSitePlatformPriceConfigModel struct {
func
newDefaultSitePlatformPriceConfigModel
(
conn
*
mon
.
Model
)
*
defaultSitePlatformPriceConfigModel
{
func
newDefaultSitePlatformPriceConfigModel
(
conn
*
mon
.
Model
)
*
defaultSitePlatformPriceConfigModel
{
return
&
defaultSitePlatformPriceConfigModel
{
return
&
defaultSitePlatformPriceConfigModel
{
conn
:
conn
,
conn
:
conn
,
Model
:
model
.
NewBase
Model
[
SitePlatformPriceConfig
](
conn
),
Model
:
model
.
NewBase
[
SitePlatformPriceConfig
](
conn
),
}
}
}
}
internal/pkg/database/mongo/site_platform_price_config/site_platform_price_config_types.go
→
internal/pkg/database/mongo/
model/
site_platform_price_config/site_platform_price_config_types.go
View file @
136f12ab
package
model
package
model
import
(
import
(
"git.chillcy.com/golang/colorway/internal/pkg/platform"
"git.chillcy.com/golang/colorway/internal/pkg/store"
"time"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/bson/primitive"
...
@@ -9,7 +11,7 @@ import (
...
@@ -9,7 +11,7 @@ import (
type
SitePlatformPriceConfig
struct
{
type
SitePlatformPriceConfig
struct
{
ID
primitive
.
ObjectID
`bson:"_id,omitempty" json:"id,omitempty"`
ID
primitive
.
ObjectID
`bson:"_id,omitempty" json:"id,omitempty"`
Site
string
`json:"site" bson:"site"`
Site
string
`json:"site" bson:"site"`
Seller
embed
.
Seller
`json:"seller" bson:"seller"`
// 销售平台
Seller
Seller
`json:"seller" bson:"seller"`
// 销售平台
Enable
bool
`json:"enable" bson:"enable"`
// 是否启用
Enable
bool
`json:"enable" bson:"enable"`
// 是否启用
embed
.
RoutePriceConfig
`bson:",inline"`
// 路线价格配置
embed
.
RoutePriceConfig
`bson:",inline"`
// 路线价格配置
UpdateAt
time
.
Time
`bson:"updateAt,omitempty" json:"updateAt,omitempty"`
UpdateAt
time
.
Time
`bson:"updateAt,omitempty" json:"updateAt,omitempty"`
...
@@ -17,6 +19,6 @@ type SitePlatformPriceConfig struct {
...
@@ -17,6 +19,6 @@ type SitePlatformPriceConfig struct {
}
}
type
Seller
struct
{
type
Seller
struct
{
Platform
string
`json:"platform" bson:"platform"`
// 销售平台
Platform
platform
.
Platform
`json:"platform" bson:"platform"`
// 销售平台
Store
st
ring
`json:"store" bson:"store"`
// 销售平台具体店铺
Store
st
ore
.
Store
`json:"store" bson:"store"`
// 销售平台具体店铺
}
}
internal/pkg/database/mongo/templates/mongo/model.tpl
View file @
136f12ab
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
package model
package model
import (
import (
model "git.chillcy.com/golang/colorway/internal/pkg/database/mongo/base"
model "git.chillcy.com/golang/colorway/internal/pkg/database/mongo/
model/
base"
{
{
if
.
Cache
}
}"github.com/zeromicro/go-zero/core/stores/monc"{
{
else
}
}"github.com/zeromicro/go-zero/core/stores/mon"{
{
end
}
}
{
{
if
.
Cache
}
}"github.com/zeromicro/go-zero/core/stores/monc"{
{
else
}
}"github.com/zeromicro/go-zero/core/stores/mon"{
{
end
}
}
)
)
...
@@ -20,6 +20,6 @@ type default{{.Type}}Model struct {
...
@@ -20,6 +20,6 @@ type default{{.Type}}Model struct {
func newDefault{{.Type}}Model(conn {
{
if
.
Cache
}
}*monc.Model{
{
else
}
}*mon.Model{
{
end
}
}) *default{{.Type}}Model {
func newDefault{{.Type}}Model(conn {
{
if
.
Cache
}
}*monc.Model{
{
else
}
}*mon.Model{
{
end
}
}) *default{{.Type}}Model {
return
&
default{{.Type}}Model{
return
&
default{{.Type}}Model{
conn: conn,
conn: conn,
Model: model.NewBase
Model
[{{.Type}}](conn),
Model: model.NewBase[{{.Type}}](conn),
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment