| 1 | + | // Code generated by gorm.io/gen. DO NOT EDIT. |
| 2 | + | // Code generated by gorm.io/gen. DO NOT EDIT. |
| 3 | + | // Code generated by gorm.io/gen. DO NOT EDIT. |
| 4 | + | |
| 5 | + | package dao |
| 6 | + | |
| 7 | + | import ( |
| 8 | + | "context" |
| 9 | + | |
| 10 | + | "github.com/DVKunion/SeaMoon/pkg/api/models" |
| 11 | + | "gorm.io/gorm" |
| 12 | + | "gorm.io/gorm/clause" |
| 13 | + | "gorm.io/gorm/schema" |
| 14 | + | |
| 15 | + | "gorm.io/gen" |
| 16 | + | "gorm.io/gen/field" |
| 17 | + | |
| 18 | + | "gorm.io/plugin/dbresolver" |
| 19 | + | ) |
| 20 | + | |
| 21 | + | func newAuth(db *gorm.DB, opts ...gen.DOOption) auth { |
| 22 | + | _auth := auth{} |
| 23 | + | |
| 24 | + | _auth.authDo.UseDB(db, opts...) |
| 25 | + | _auth.authDo.UseModel(&models.Auth{}) |
| 26 | + | |
| 27 | + | tableName := _auth.authDo.TableName() |
| 28 | + | _auth.ALL = field.NewAsterisk(tableName) |
| 29 | + | _auth.ID = field.NewUint(tableName, "id") |
| 30 | + | _auth.CreatedAt = field.NewTime(tableName, "created_at") |
| 31 | + | _auth.UpdatedAt = field.NewTime(tableName, "updated_at") |
| 32 | + | _auth.DeletedAt = field.NewField(tableName, "deleted_at") |
| 33 | + | _auth.Type = field.NewInt8(tableName, "type") |
| 34 | + | _auth.Username = field.NewString(tableName, "username") |
| 35 | + | _auth.Password = field.NewString(tableName, "password") |
| 36 | + | _auth.LastLogin = field.NewString(tableName, "last_login") |
| 37 | + | _auth.LastAddr = field.NewString(tableName, "last_addr") |
| 38 | + | |
| 39 | + | _auth.fillFieldMap() |
| 40 | + | |
| 41 | + | return _auth |
| 42 | + | } |
| 43 | + | |
| 44 | + | type auth struct { |
| 45 | + | authDo authDo |
| 46 | + | |
| 47 | + | ALL field.Asterisk |
| 48 | + | ID field.Uint |
| 49 | + | CreatedAt field.Time |
| 50 | + | UpdatedAt field.Time |
| 51 | + | DeletedAt field.Field |
| 52 | + | Type field.Int8 |
| 53 | + | Username field.String |
| 54 | + | Password field.String |
| 55 | + | LastLogin field.String |
| 56 | + | LastAddr field.String |
| 57 | + | |
| 58 | + | fieldMap map[string]field.Expr |
| 59 | + | } |
| 60 | + | |
| 61 | + | func (a auth) Table(newTableName string) *auth { |
| 62 | + | a.authDo.UseTable(newTableName) |
| 63 | + | return a.updateTableName(newTableName) |
| 64 | + | } |
| 65 | + | |
| 66 | + | func (a auth) As(alias string) *auth { |
| 67 | + | a.authDo.DO = *(a.authDo.As(alias).(*gen.DO)) |
| 68 | + | return a.updateTableName(alias) |
| 69 | + | } |
| 70 | + | |
| 71 | + | func (a *auth) updateTableName(table string) *auth { |
| 72 | + | a.ALL = field.NewAsterisk(table) |
| 73 | + | a.ID = field.NewUint(table, "id") |
| 74 | + | a.CreatedAt = field.NewTime(table, "created_at") |
| 75 | + | a.UpdatedAt = field.NewTime(table, "updated_at") |
| 76 | + | a.DeletedAt = field.NewField(table, "deleted_at") |
| 77 | + | a.Type = field.NewInt8(table, "type") |
| 78 | + | a.Username = field.NewString(table, "username") |
| 79 | + | a.Password = field.NewString(table, "password") |
| 80 | + | a.LastLogin = field.NewString(table, "last_login") |
| 81 | + | a.LastAddr = field.NewString(table, "last_addr") |
| 82 | + | |
| 83 | + | a.fillFieldMap() |
| 84 | + | |
| 85 | + | return a |
| 86 | + | } |
| 87 | + | |
| 88 | + | func (a *auth) WithContext(ctx context.Context) IAuthDo { return a.authDo.WithContext(ctx) } |
| 89 | + | |
| 90 | + | func (a auth) TableName() string { return a.authDo.TableName() } |
| 91 | + | |
| 92 | + | func (a auth) Alias() string { return a.authDo.Alias() } |
| 93 | + | |
| 94 | + | func (a auth) Columns(cols ...field.Expr) gen.Columns { return a.authDo.Columns(cols...) } |
| 95 | + | |
| 96 | + | func (a *auth) GetFieldByName(fieldName string) (field.OrderExpr, bool) { |
| 97 | + | _f, ok := a.fieldMap[fieldName] |
| 98 | + | if !ok || _f == nil { |
| 99 | + | return nil, false |
| 100 | + | } |
| 101 | + | _oe, ok := _f.(field.OrderExpr) |
| 102 | + | return _oe, ok |
| 103 | + | } |
| 104 | + | |
| 105 | + | func (a *auth) fillFieldMap() { |
| 106 | + | a.fieldMap = make(map[string]field.Expr, 9) |
| 107 | + | a.fieldMap["id"] = a.ID |
| 108 | + | a.fieldMap["created_at"] = a.CreatedAt |
| 109 | + | a.fieldMap["updated_at"] = a.UpdatedAt |
| 110 | + | a.fieldMap["deleted_at"] = a.DeletedAt |
| 111 | + | a.fieldMap["type"] = a.Type |
| 112 | + | a.fieldMap["username"] = a.Username |
| 113 | + | a.fieldMap["password"] = a.Password |
| 114 | + | a.fieldMap["last_login"] = a.LastLogin |
| 115 | + | a.fieldMap["last_addr"] = a.LastAddr |
| 116 | + | } |
| 117 | + | |
| 118 | + | func (a auth) clone(db *gorm.DB) auth { |
| 119 | + | a.authDo.ReplaceConnPool(db.Statement.ConnPool) |
| 120 | + | return a |
| 121 | + | } |
| 122 | + | |
| 123 | + | func (a auth) replaceDB(db *gorm.DB) auth { |
| 124 | + | a.authDo.ReplaceDB(db) |
| 125 | + | return a |
| 126 | + | } |
| 127 | + | |
| 128 | + | type authDo struct{ gen.DO } |
| 129 | + | |
| 130 | + | type IAuthDo interface { |
| 131 | + | gen.SubQuery |
| 132 | + | Debug() IAuthDo |
| 133 | + | WithContext(ctx context.Context) IAuthDo |
| 134 | + | WithResult(fc func(tx gen.Dao)) gen.ResultInfo |
| 135 | + | ReplaceDB(db *gorm.DB) |
| 136 | + | ReadDB() IAuthDo |
| 137 | + | WriteDB() IAuthDo |
| 138 | + | As(alias string) gen.Dao |
| 139 | + | Session(config *gorm.Session) IAuthDo |
| 140 | + | Columns(cols ...field.Expr) gen.Columns |
| 141 | + | Clauses(conds ...clause.Expression) IAuthDo |
| 142 | + | Not(conds ...gen.Condition) IAuthDo |
| 143 | + | Or(conds ...gen.Condition) IAuthDo |
| 144 | + | Select(conds ...field.Expr) IAuthDo |
| 145 | + | Where(conds ...gen.Condition) IAuthDo |
| 146 | + | Order(conds ...field.Expr) IAuthDo |
| 147 | + | Distinct(cols ...field.Expr) IAuthDo |
| 148 | + | Omit(cols ...field.Expr) IAuthDo |
| 149 | + | Join(table schema.Tabler, on ...field.Expr) IAuthDo |
| 150 | + | LeftJoin(table schema.Tabler, on ...field.Expr) IAuthDo |
| 151 | + | RightJoin(table schema.Tabler, on ...field.Expr) IAuthDo |
| 152 | + | Group(cols ...field.Expr) IAuthDo |
| 153 | + | Having(conds ...gen.Condition) IAuthDo |
| 154 | + | Limit(limit int) IAuthDo |
| 155 | + | Offset(offset int) IAuthDo |
| 156 | + | Count() (count int64, err error) |
| 157 | + | Scopes(funcs ...func(gen.Dao) gen.Dao) IAuthDo |
| 158 | + | Unscoped() IAuthDo |
| 159 | + | Create(values ...*models.Auth) error |
| 160 | + | CreateInBatches(values []*models.Auth, batchSize int) error |
| 161 | + | Save(values ...*models.Auth) error |
| 162 | + | First() (*models.Auth, error) |
| 163 | + | Take() (*models.Auth, error) |
| 164 | + | Last() (*models.Auth, error) |
| 165 | + | Find() ([]*models.Auth, error) |
| 166 | + | FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Auth, err error) |
| 167 | + | FindInBatches(result *[]*models.Auth, batchSize int, fc func(tx gen.Dao, batch int) error) error |
| 168 | + | Pluck(column field.Expr, dest interface{}) error |
| 169 | + | Delete(...*models.Auth) (info gen.ResultInfo, err error) |
| 170 | + | Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) |
| 171 | + | UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) |
| 172 | + | Updates(value interface{}) (info gen.ResultInfo, err error) |
| 173 | + | UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) |
| 174 | + | UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) |
| 175 | + | UpdateColumns(value interface{}) (info gen.ResultInfo, err error) |
| 176 | + | UpdateFrom(q gen.SubQuery) gen.Dao |
| 177 | + | Attrs(attrs ...field.AssignExpr) IAuthDo |
| 178 | + | Assign(attrs ...field.AssignExpr) IAuthDo |
| 179 | + | Joins(fields ...field.RelationField) IAuthDo |
| 180 | + | Preload(fields ...field.RelationField) IAuthDo |
| 181 | + | FirstOrInit() (*models.Auth, error) |
| 182 | + | FirstOrCreate() (*models.Auth, error) |
| 183 | + | FindByPage(offset int, limit int) (result []*models.Auth, count int64, err error) |
| 184 | + | ScanByPage(result interface{}, offset int, limit int) (count int64, err error) |
| 185 | + | Scan(result interface{}) (err error) |
| 186 | + | Returning(value interface{}, columns ...string) IAuthDo |
| 187 | + | UnderlyingDB() *gorm.DB |
| 188 | + | schema.Tabler |
| 189 | + | } |
| 190 | + | |
| 191 | + | func (a authDo) Debug() IAuthDo { |
| 192 | + | return a.withDO(a.DO.Debug()) |
| 193 | + | } |
| 194 | + | |
| 195 | + | func (a authDo) WithContext(ctx context.Context) IAuthDo { |
| 196 | + | return a.withDO(a.DO.WithContext(ctx)) |
| 197 | + | } |
| 198 | + | |
| 199 | + | func (a authDo) ReadDB() IAuthDo { |
| 200 | + | return a.Clauses(dbresolver.Read) |
| 201 | + | } |
| 202 | + | |
| 203 | + | func (a authDo) WriteDB() IAuthDo { |
| 204 | + | return a.Clauses(dbresolver.Write) |
| 205 | + | } |
| 206 | + | |
| 207 | + | func (a authDo) Session(config *gorm.Session) IAuthDo { |
| 208 | + | return a.withDO(a.DO.Session(config)) |
| 209 | + | } |
| 210 | + | |
| 211 | + | func (a authDo) Clauses(conds ...clause.Expression) IAuthDo { |
| 212 | + | return a.withDO(a.DO.Clauses(conds...)) |
| 213 | + | } |
| 214 | + | |
| 215 | + | func (a authDo) Returning(value interface{}, columns ...string) IAuthDo { |
| 216 | + | return a.withDO(a.DO.Returning(value, columns...)) |
| 217 | + | } |
| 218 | + | |
| 219 | + | func (a authDo) Not(conds ...gen.Condition) IAuthDo { |
| 220 | + | return a.withDO(a.DO.Not(conds...)) |
| 221 | + | } |
| 222 | + | |
| 223 | + | func (a authDo) Or(conds ...gen.Condition) IAuthDo { |
| 224 | + | return a.withDO(a.DO.Or(conds...)) |
| 225 | + | } |
| 226 | + | |
| 227 | + | func (a authDo) Select(conds ...field.Expr) IAuthDo { |
| 228 | + | return a.withDO(a.DO.Select(conds...)) |
| 229 | + | } |
| 230 | + | |
| 231 | + | func (a authDo) Where(conds ...gen.Condition) IAuthDo { |
| 232 | + | return a.withDO(a.DO.Where(conds...)) |
| 233 | + | } |
| 234 | + | |
| 235 | + | func (a authDo) Order(conds ...field.Expr) IAuthDo { |
| 236 | + | return a.withDO(a.DO.Order(conds...)) |
| 237 | + | } |
| 238 | + | |
| 239 | + | func (a authDo) Distinct(cols ...field.Expr) IAuthDo { |
| 240 | + | return a.withDO(a.DO.Distinct(cols...)) |
| 241 | + | } |
| 242 | + | |
| 243 | + | func (a authDo) Omit(cols ...field.Expr) IAuthDo { |
| 244 | + | return a.withDO(a.DO.Omit(cols...)) |
| 245 | + | } |
| 246 | + | |
| 247 | + | func (a authDo) Join(table schema.Tabler, on ...field.Expr) IAuthDo { |
| 248 | + | return a.withDO(a.DO.Join(table, on...)) |
| 249 | + | } |
| 250 | + | |
| 251 | + | func (a authDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAuthDo { |
| 252 | + | return a.withDO(a.DO.LeftJoin(table, on...)) |
| 253 | + | } |
| 254 | + | |
| 255 | + | func (a authDo) RightJoin(table schema.Tabler, on ...field.Expr) IAuthDo { |
| 256 | + | return a.withDO(a.DO.RightJoin(table, on...)) |
| 257 | + | } |
| 258 | + | |
| 259 | + | func (a authDo) Group(cols ...field.Expr) IAuthDo { |
| 260 | + | return a.withDO(a.DO.Group(cols...)) |
| 261 | + | } |
| 262 | + | |
| 263 | + | func (a authDo) Having(conds ...gen.Condition) IAuthDo { |
| 264 | + | return a.withDO(a.DO.Having(conds...)) |
| 265 | + | } |
| 266 | + | |
| 267 | + | func (a authDo) Limit(limit int) IAuthDo { |
| 268 | + | return a.withDO(a.DO.Limit(limit)) |
| 269 | + | } |
| 270 | + | |
| 271 | + | func (a authDo) Offset(offset int) IAuthDo { |
| 272 | + | return a.withDO(a.DO.Offset(offset)) |
| 273 | + | } |
| 274 | + | |
| 275 | + | func (a authDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAuthDo { |
| 276 | + | return a.withDO(a.DO.Scopes(funcs...)) |
| 277 | + | } |
| 278 | + | |
| 279 | + | func (a authDo) Unscoped() IAuthDo { |
| 280 | + | return a.withDO(a.DO.Unscoped()) |
| 281 | + | } |
| 282 | + | |
| 283 | + | func (a authDo) Create(values ...*models.Auth) error { |
| 284 | + | if len(values) == 0 { |
| 285 | + | return nil |
| 286 | + | } |
| 287 | + | return a.DO.Create(values) |
| 288 | + | } |
| 289 | + | |
| 290 | + | func (a authDo) CreateInBatches(values []*models.Auth, batchSize int) error { |
| 291 | + | return a.DO.CreateInBatches(values, batchSize) |
| 292 | + | } |
| 293 | + | |
| 294 | + | // Save : !!! underlying implementation is different with GORM |
| 295 | + | // The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) |
| 296 | + | func (a authDo) Save(values ...*models.Auth) error { |
| 297 | + | if len(values) == 0 { |
| 298 | + | return nil |
| 299 | + | } |
| 300 | + | return a.DO.Save(values) |
| 301 | + | } |
| 302 | + | |
| 303 | + | func (a authDo) First() (*models.Auth, error) { |
| 304 | + | if result, err := a.DO.First(); err != nil { |
| 305 | + | return nil, err |
| 306 | + | } else { |
| 307 | + | return result.(*models.Auth), nil |
| 308 | + | } |
| 309 | + | } |
| 310 | + | |
| 311 | + | func (a authDo) Take() (*models.Auth, error) { |
| 312 | + | if result, err := a.DO.Take(); err != nil { |
| 313 | + | return nil, err |
| 314 | + | } else { |
| 315 | + | return result.(*models.Auth), nil |
| 316 | + | } |
| 317 | + | } |
| 318 | + | |
| 319 | + | func (a authDo) Last() (*models.Auth, error) { |
| 320 | + | if result, err := a.DO.Last(); err != nil { |
| 321 | + | return nil, err |
| 322 | + | } else { |
| 323 | + | return result.(*models.Auth), nil |
| 324 | + | } |
| 325 | + | } |
| 326 | + | |
| 327 | + | func (a authDo) Find() ([]*models.Auth, error) { |
| 328 | + | result, err := a.DO.Find() |
| 329 | + | return result.([]*models.Auth), err |
| 330 | + | } |
| 331 | + | |
| 332 | + | func (a authDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Auth, err error) { |
| 333 | + | buf := make([]*models.Auth, 0, batchSize) |
| 334 | + | err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { |
| 335 | + | defer func() { results = append(results, buf...) }() |
| 336 | + | return fc(tx, batch) |
| 337 | + | }) |
| 338 | + | return results, err |
| 339 | + | } |
| 340 | + | |
| 341 | + | func (a authDo) FindInBatches(result *[]*models.Auth, batchSize int, fc func(tx gen.Dao, batch int) error) error { |
| 342 | + | return a.DO.FindInBatches(result, batchSize, fc) |
| 343 | + | } |
| 344 | + | |
| 345 | + | func (a authDo) Attrs(attrs ...field.AssignExpr) IAuthDo { |
| 346 | + | return a.withDO(a.DO.Attrs(attrs...)) |
| 347 | + | } |
| 348 | + | |
| 349 | + | func (a authDo) Assign(attrs ...field.AssignExpr) IAuthDo { |
| 350 | + | return a.withDO(a.DO.Assign(attrs...)) |
| 351 | + | } |
| 352 | + | |
| 353 | + | func (a authDo) Joins(fields ...field.RelationField) IAuthDo { |
| 354 | + | for _, _f := range fields { |
| 355 | + | a = *a.withDO(a.DO.Joins(_f)) |
| 356 | + | } |
| 357 | + | return &a |
| 358 | + | } |
| 359 | + | |
| 360 | + | func (a authDo) Preload(fields ...field.RelationField) IAuthDo { |
| 361 | + | for _, _f := range fields { |
| 362 | + | a = *a.withDO(a.DO.Preload(_f)) |
| 363 | + | } |
| 364 | + | return &a |
| 365 | + | } |
| 366 | + | |
| 367 | + | func (a authDo) FirstOrInit() (*models.Auth, error) { |
| 368 | + | if result, err := a.DO.FirstOrInit(); err != nil { |
| 369 | + | return nil, err |
| 370 | + | } else { |
| 371 | + | return result.(*models.Auth), nil |
| 372 | + | } |
| 373 | + | } |
| 374 | + | |
| 375 | + | func (a authDo) FirstOrCreate() (*models.Auth, error) { |
| 376 | + | if result, err := a.DO.FirstOrCreate(); err != nil { |
| 377 | + | return nil, err |
| 378 | + | } else { |
| 379 | + | return result.(*models.Auth), nil |
| 380 | + | } |
| 381 | + | } |
| 382 | + | |
| 383 | + | func (a authDo) FindByPage(offset int, limit int) (result []*models.Auth, count int64, err error) { |
| 384 | + | result, err = a.Offset(offset).Limit(limit).Find() |
| 385 | + | if err != nil { |
| 386 | + | return |
| 387 | + | } |
| 388 | + | |
| 389 | + | if size := len(result); 0 < limit && 0 < size && size < limit { |
| 390 | + | count = int64(size + offset) |
| 391 | + | return |
| 392 | + | } |
| 393 | + | |
| 394 | + | count, err = a.Offset(-1).Limit(-1).Count() |
| 395 | + | return |
| 396 | + | } |
| 397 | + | |
| 398 | + | func (a authDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { |
| 399 | + | count, err = a.Count() |
| 400 | + | if err != nil { |
| 401 | + | return |
| 402 | + | } |
| 403 | + | |
| 404 | + | err = a.Offset(offset).Limit(limit).Scan(result) |
| 405 | + | return |
| 406 | + | } |
| 407 | + | |
| 408 | + | func (a authDo) Scan(result interface{}) (err error) { |
| 409 | + | return a.DO.Scan(result) |
| 410 | + | } |
| 411 | + | |
| 412 | + | func (a authDo) Delete(models ...*models.Auth) (result gen.ResultInfo, err error) { |
| 413 | + | return a.DO.Delete(models) |
| 414 | + | } |
| 415 | + | |
| 416 | + | func (a *authDo) withDO(do gen.Dao) *authDo { |
| 417 | + | a.DO = *do.(*gen.DO) |
| 418 | + | return a |
| 419 | + | } |
| 420 | + | |