@@ -47,27 +47,27 @@ type Matter interface {
47
47
var _ Matter = (* MatterDBQuery )(nil )
48
48
49
49
type MatterDBQuery struct {
50
- q * query. Query
50
+ DBQuery
51
51
}
52
52
53
- func NewMatterDBQuery (q * query. Query ) * MatterDBQuery {
54
- return & MatterDBQuery {q : q }
53
+ func NewMatterDBQuery (q DBQuery ) * MatterDBQuery {
54
+ return & MatterDBQuery {DBQuery : q }
55
55
}
56
56
57
57
func (db * MatterDBQuery ) Find (ctx context.Context , id int64 ) (* entity.Matter , error ) {
58
- return db .q .Matter .WithContext (ctx ).Where (db .q .Matter .Id .Eq (id )).First ()
58
+ return db .Q () .Matter .WithContext (ctx ).Where (db .Q () .Matter .Id .Eq (id )).First ()
59
59
}
60
60
61
61
func (db * MatterDBQuery ) FindWith (ctx context.Context , opt * MatterFindWithOption ) (* entity.Matter , error ) {
62
62
conds := make ([]gen.Condition , 0 )
63
63
if opt .Id != 0 {
64
- conds = append (conds , db .q .Matter .Id .Eq (opt .Id ))
64
+ conds = append (conds , db .Q () .Matter .Id .Eq (opt .Id ))
65
65
}
66
66
if opt .Alias != "" {
67
- conds = append (conds , db .q .Matter .Alias_ .Eq (opt .Alias ))
67
+ conds = append (conds , db .Q () .Matter .Alias_ .Eq (opt .Alias ))
68
68
}
69
69
70
- q := db .q .Matter .WithContext (ctx )
70
+ q := db .Q () .Matter .WithContext (ctx )
71
71
if opt .Deleted {
72
72
q = q .Unscoped ()
73
73
}
@@ -76,7 +76,7 @@ func (db *MatterDBQuery) FindWith(ctx context.Context, opt *MatterFindWithOption
76
76
}
77
77
78
78
func (db * MatterDBQuery ) FindByAlias (ctx context.Context , alias string ) (* entity.Matter , error ) {
79
- return db .q .Matter .WithContext (ctx ).Where (db .q .Matter .Alias_ .Eq (alias )).First ()
79
+ return db .Q () .Matter .WithContext (ctx ).Where (db .Q () .Matter .Alias_ .Eq (alias )).First ()
80
80
}
81
81
82
82
func (db * MatterDBQuery ) PathExist (ctx context.Context , filepath string ) bool {
@@ -92,41 +92,41 @@ func (db *MatterDBQuery) PathExist(ctx context.Context, filepath string) bool {
92
92
parent , name = path .Split (filepath )
93
93
}
94
94
95
- conds := []gen.Condition {db .q .Matter .Name .Eq (name )}
95
+ conds := []gen.Condition {db .Q () .Matter .Name .Eq (name )}
96
96
if parent != name {
97
- conds = append (conds , db .q .Matter .Parent .Eq (strings .TrimPrefix (parent , "/" )))
97
+ conds = append (conds , db .Q () .Matter .Parent .Eq (strings .TrimPrefix (parent , "/" )))
98
98
}
99
99
100
- _ , err := db .q .Matter .WithContext (ctx ).Where (conds ... ).First ()
100
+ _ , err := db .Q () .Matter .WithContext (ctx ).Where (conds ... ).First ()
101
101
return err == nil
102
102
}
103
103
104
104
func (db * MatterDBQuery ) FindAll (ctx context.Context , opts * MatterListOption ) ([]* entity.Matter , int64 , error ) {
105
105
conds := make ([]gen.Condition , 0 )
106
106
if opts .Uid != 0 {
107
- conds = append (conds , db .q .Matter .Uid .Eq (opts .Uid ))
107
+ conds = append (conds , db .Q () .Matter .Uid .Eq (opts .Uid ))
108
108
}
109
109
if opts .Sid != 0 {
110
- conds = append (conds , db .q .Matter .Sid .Eq (opts .Sid ))
110
+ conds = append (conds , db .Q () .Matter .Sid .Eq (opts .Sid ))
111
111
}
112
112
113
113
if opts .Keyword != "" {
114
- conds = append (conds , db .q .Matter .Name .Like (fmt .Sprintf ("%%%s%%" , opts .Keyword )))
114
+ conds = append (conds , db .Q () .Matter .Name .Like (fmt .Sprintf ("%%%s%%" , opts .Keyword )))
115
115
} else if ! opts .Draft {
116
- conds = append (conds , db .q .Matter .Parent .Eq (opts .Dir ))
116
+ conds = append (conds , db .Q () .Matter .Parent .Eq (opts .Dir ))
117
117
}
118
118
119
119
if opts .Type == "doc" {
120
- conds = append (conds , db .q .Matter .Type .In (entity .DocTypes ... ))
120
+ conds = append (conds , db .Q () .Matter .Type .In (entity .DocTypes ... ))
121
121
} else if opts .Type != "" {
122
- conds = append (conds , db .q .Matter .Type .Like (fmt .Sprintf ("%%%s%%" , opts .Type )))
122
+ conds = append (conds , db .Q () .Matter .Type .Like (fmt .Sprintf ("%%%s%%" , opts .Type )))
123
123
}
124
124
125
125
if ! opts .Draft {
126
- conds = append (conds , db .q .Matter .UploadedAt .IsNotNull ())
126
+ conds = append (conds , db .Q () .Matter .UploadedAt .IsNotNull ())
127
127
}
128
128
129
- q := db .q .Matter .WithContext (ctx ).Where (conds ... ).Order (db .q .Matter .DirType .Desc (), db .q .Matter .Id .Desc ())
129
+ q := db .Q () .Matter .WithContext (ctx ).Where (conds ... ).Order (db .Q () .Matter .DirType .Desc (), db .Q () .Matter .Id .Desc ())
130
130
131
131
if opts .Limit == 0 {
132
132
matters , err := q .Find ()
@@ -148,7 +148,7 @@ func (db *MatterDBQuery) Create(ctx context.Context, m *entity.Matter) error {
148
148
m .Name = strings .TrimSuffix (m .Name , ext ) + suffix + ext
149
149
}
150
150
151
- return db .q .Matter .Create (m )
151
+ return db .Q () .Matter .Create (m )
152
152
}
153
153
154
154
func (db * MatterDBQuery ) Copy (ctx context.Context , id int64 , to string ) (* entity.Matter , error ) {
@@ -165,7 +165,7 @@ func (db *MatterDBQuery) Copy(ctx context.Context, id int64, to string) (*entity
165
165
newMatter .Parent = to
166
166
if ! em .IsDir () {
167
167
// 如果是文件则只创建新的文件即可
168
- return newMatter , db .q .Matter .Create (newMatter )
168
+ return newMatter , db .Q () .Matter .Create (newMatter )
169
169
}
170
170
171
171
// 如果是文件夹则查找所有子文件/文件夹一起复制
@@ -180,7 +180,7 @@ func (db *MatterDBQuery) Copy(ctx context.Context, id int64, to string) (*entity
180
180
return newMatter
181
181
})
182
182
183
- return newMatter , db .q .Matter .Create (newMatters ... )
183
+ return newMatter , db .Q () .Matter .Create (newMatters ... )
184
184
}
185
185
186
186
func (db * MatterDBQuery ) Update (ctx context.Context , id int64 , m * entity.Matter ) error {
@@ -189,7 +189,7 @@ func (db *MatterDBQuery) Update(ctx context.Context, id int64, m *entity.Matter)
189
189
return err
190
190
}
191
191
192
- return db .q .Transaction (func (tx * query.Query ) error {
192
+ return db .Q () .Transaction (func (tx * query.Query ) error {
193
193
tq := tx .Matter .WithContext (ctx )
194
194
if m .IsDir () {
195
195
// 如果是目录,则需要把该目录下的子文件/目录一并修改
@@ -212,7 +212,7 @@ func (db *MatterDBQuery) Delete(ctx context.Context, id int64) error {
212
212
}
213
213
214
214
m .TrashedBy = uuid .New ().String ()
215
- return db .q .Transaction (func (tx * query.Query ) error {
215
+ return db .Q () .Transaction (func (tx * query.Query ) error {
216
216
tq := tx .Matter .WithContext (ctx )
217
217
if m .IsDir () {
218
218
// 如果是目录,则需要把该目录下的子文件/目录一并删除
@@ -234,7 +234,7 @@ func (db *MatterDBQuery) Delete(ctx context.Context, id int64) error {
234
234
}
235
235
236
236
func (db * MatterDBQuery ) Recovery (ctx context.Context , id int64 ) error {
237
- m , err := db .q .Matter .WithContext (ctx ).Unscoped ().Where (db .q .Matter .Id .Eq (id )).First ()
237
+ m , err := db .Q () .Matter .WithContext (ctx ).Unscoped ().Where (db .Q () .Matter .Id .Eq (id )).First ()
238
238
if err != nil {
239
239
return err
240
240
}
@@ -243,8 +243,8 @@ func (db *MatterDBQuery) Recovery(ctx context.Context, id int64) error {
243
243
return fmt .Errorf ("recovery: file parent[%s] not found" , m .Parent )
244
244
}
245
245
246
- _ , err = db .q .Matter .WithContext (ctx ).Unscoped ().Where (db .q .Matter .TrashedBy .Eq (m .TrashedBy )).
247
- UpdateSimple (db .q .Matter .TrashedBy .Value ("" ), db .q .Matter .DeletedAt .Null ())
246
+ _ , err = db .Q () .Matter .WithContext (ctx ).Unscoped ().Where (db .Q () .Matter .TrashedBy .Eq (m .TrashedBy )).
247
+ UpdateSimple (db .Q () .Matter .TrashedBy .Value ("" ), db .Q () .Matter .DeletedAt .Null ())
248
248
return err
249
249
}
250
250
@@ -271,10 +271,10 @@ func (db *MatterDBQuery) GetObjects(ctx context.Context, id int64) ([]string, er
271
271
}
272
272
273
273
func (db * MatterDBQuery ) findChildren (ctx context.Context , m * entity.Matter , withDeleted bool ) ([]* entity.Matter , error ) {
274
- q := db .q .Matter .WithContext (ctx )
274
+ q := db .Q () .Matter .WithContext (ctx )
275
275
if withDeleted {
276
276
q = q .Unscoped ()
277
277
}
278
278
279
- return q .Where (db .q .Matter .Parent .Like (m .FullPath () + "%" )).Find ()
279
+ return q .Where (db .Q () .Matter .Parent .Like (m .FullPath () + "%" )).Find ()
280
280
}
0 commit comments