add jwt files

This commit is contained in:
yanghao05
2023-01-30 19:56:31 +08:00
parent 591543d2a8
commit 81e33fa544
12 changed files with 1226 additions and 47 deletions

View File

@@ -16,34 +16,39 @@ import (
)
var (
Q = new(Query)
Migration *migration
Q = new(Query)
Migration *migration
SysOperationRecord *sysOperationRecord
)
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...)
Migration = &Q.Migration
SysOperationRecord = &Q.SysOperationRecord
}
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Migration: newMigration(db, opts...),
db: db,
Migration: newMigration(db, opts...),
SysOperationRecord: newSysOperationRecord(db, opts...),
}
}
type Query struct {
db *gorm.DB
Migration migration
Migration migration
SysOperationRecord sysOperationRecord
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Migration: q.Migration.clone(db),
db: db,
Migration: q.Migration.clone(db),
SysOperationRecord: q.SysOperationRecord.clone(db),
}
}
@@ -57,18 +62,21 @@ func (q *Query) WriteDB() *Query {
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
Migration: q.Migration.replaceDB(db),
db: db,
Migration: q.Migration.replaceDB(db),
SysOperationRecord: q.SysOperationRecord.replaceDB(db),
}
}
type queryCtx struct {
Migration IMigrationDo
Migration IMigrationDo
SysOperationRecord ISysOperationRecordDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Migration: q.Migration.WithContext(ctx),
Migration: q.Migration.WithContext(ctx),
SysOperationRecord: q.SysOperationRecord.WithContext(ctx),
}
}

View File

@@ -0,0 +1,444 @@
// 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"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"atom/database/models"
)
func newSysOperationRecord(db *gorm.DB, opts ...gen.DOOption) sysOperationRecord {
_sysOperationRecord := sysOperationRecord{}
_sysOperationRecord.sysOperationRecordDo.UseDB(db, opts...)
_sysOperationRecord.sysOperationRecordDo.UseModel(&models.SysOperationRecord{})
tableName := _sysOperationRecord.sysOperationRecordDo.TableName()
_sysOperationRecord.ALL = field.NewAsterisk(tableName)
_sysOperationRecord.ID = field.NewUint64(tableName, "id")
_sysOperationRecord.CreatedAt = field.NewTime(tableName, "created_at")
_sysOperationRecord.UpdatedAt = field.NewTime(tableName, "updated_at")
_sysOperationRecord.DeletedAt = field.NewField(tableName, "deleted_at")
_sysOperationRecord.IP = field.NewString(tableName, "ip")
_sysOperationRecord.Method = field.NewString(tableName, "method")
_sysOperationRecord.Path = field.NewString(tableName, "path")
_sysOperationRecord.Status = field.NewInt64(tableName, "status")
_sysOperationRecord.Latency = field.NewInt64(tableName, "latency")
_sysOperationRecord.Agent = field.NewString(tableName, "agent")
_sysOperationRecord.ErrorMessage = field.NewString(tableName, "error_message")
_sysOperationRecord.Body = field.NewString(tableName, "body")
_sysOperationRecord.Resp = field.NewString(tableName, "resp")
_sysOperationRecord.UserID = field.NewInt64(tableName, "user_id")
_sysOperationRecord.fillFieldMap()
return _sysOperationRecord
}
type sysOperationRecord struct {
sysOperationRecordDo sysOperationRecordDo
ALL field.Asterisk
ID field.Uint64
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
IP field.String // 请求ip
Method field.String // 请求方法
Path field.String // 请求路径
Status field.Int64 // 请求状态
Latency field.Int64 // 延迟
Agent field.String // 代理
ErrorMessage field.String // 错误信息
Body field.String // 请求Body
Resp field.String // 响应Body
UserID field.Int64 // 用户id
fieldMap map[string]field.Expr
}
func (s sysOperationRecord) Table(newTableName string) *sysOperationRecord {
s.sysOperationRecordDo.UseTable(newTableName)
return s.updateTableName(newTableName)
}
func (s sysOperationRecord) As(alias string) *sysOperationRecord {
s.sysOperationRecordDo.DO = *(s.sysOperationRecordDo.As(alias).(*gen.DO))
return s.updateTableName(alias)
}
func (s *sysOperationRecord) updateTableName(table string) *sysOperationRecord {
s.ALL = field.NewAsterisk(table)
s.ID = field.NewUint64(table, "id")
s.CreatedAt = field.NewTime(table, "created_at")
s.UpdatedAt = field.NewTime(table, "updated_at")
s.DeletedAt = field.NewField(table, "deleted_at")
s.IP = field.NewString(table, "ip")
s.Method = field.NewString(table, "method")
s.Path = field.NewString(table, "path")
s.Status = field.NewInt64(table, "status")
s.Latency = field.NewInt64(table, "latency")
s.Agent = field.NewString(table, "agent")
s.ErrorMessage = field.NewString(table, "error_message")
s.Body = field.NewString(table, "body")
s.Resp = field.NewString(table, "resp")
s.UserID = field.NewInt64(table, "user_id")
s.fillFieldMap()
return s
}
func (s *sysOperationRecord) WithContext(ctx context.Context) ISysOperationRecordDo {
return s.sysOperationRecordDo.WithContext(ctx)
}
func (s sysOperationRecord) TableName() string { return s.sysOperationRecordDo.TableName() }
func (s sysOperationRecord) Alias() string { return s.sysOperationRecordDo.Alias() }
func (s *sysOperationRecord) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := s.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (s *sysOperationRecord) fillFieldMap() {
s.fieldMap = make(map[string]field.Expr, 14)
s.fieldMap["id"] = s.ID
s.fieldMap["created_at"] = s.CreatedAt
s.fieldMap["updated_at"] = s.UpdatedAt
s.fieldMap["deleted_at"] = s.DeletedAt
s.fieldMap["ip"] = s.IP
s.fieldMap["method"] = s.Method
s.fieldMap["path"] = s.Path
s.fieldMap["status"] = s.Status
s.fieldMap["latency"] = s.Latency
s.fieldMap["agent"] = s.Agent
s.fieldMap["error_message"] = s.ErrorMessage
s.fieldMap["body"] = s.Body
s.fieldMap["resp"] = s.Resp
s.fieldMap["user_id"] = s.UserID
}
func (s sysOperationRecord) clone(db *gorm.DB) sysOperationRecord {
s.sysOperationRecordDo.ReplaceConnPool(db.Statement.ConnPool)
return s
}
func (s sysOperationRecord) replaceDB(db *gorm.DB) sysOperationRecord {
s.sysOperationRecordDo.ReplaceDB(db)
return s
}
type sysOperationRecordDo struct{ gen.DO }
type ISysOperationRecordDo interface {
gen.SubQuery
Debug() ISysOperationRecordDo
WithContext(ctx context.Context) ISysOperationRecordDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() ISysOperationRecordDo
WriteDB() ISysOperationRecordDo
As(alias string) gen.Dao
Session(config *gorm.Session) ISysOperationRecordDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) ISysOperationRecordDo
Not(conds ...gen.Condition) ISysOperationRecordDo
Or(conds ...gen.Condition) ISysOperationRecordDo
Select(conds ...field.Expr) ISysOperationRecordDo
Where(conds ...gen.Condition) ISysOperationRecordDo
Order(conds ...field.Expr) ISysOperationRecordDo
Distinct(cols ...field.Expr) ISysOperationRecordDo
Omit(cols ...field.Expr) ISysOperationRecordDo
Join(table schema.Tabler, on ...field.Expr) ISysOperationRecordDo
LeftJoin(table schema.Tabler, on ...field.Expr) ISysOperationRecordDo
RightJoin(table schema.Tabler, on ...field.Expr) ISysOperationRecordDo
Group(cols ...field.Expr) ISysOperationRecordDo
Having(conds ...gen.Condition) ISysOperationRecordDo
Limit(limit int) ISysOperationRecordDo
Offset(offset int) ISysOperationRecordDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) ISysOperationRecordDo
Unscoped() ISysOperationRecordDo
Create(values ...*models.SysOperationRecord) error
CreateInBatches(values []*models.SysOperationRecord, batchSize int) error
Save(values ...*models.SysOperationRecord) error
First() (*models.SysOperationRecord, error)
Take() (*models.SysOperationRecord, error)
Last() (*models.SysOperationRecord, error)
Find() ([]*models.SysOperationRecord, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.SysOperationRecord, err error)
FindInBatches(result *[]*models.SysOperationRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.SysOperationRecord) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) ISysOperationRecordDo
Assign(attrs ...field.AssignExpr) ISysOperationRecordDo
Joins(fields ...field.RelationField) ISysOperationRecordDo
Preload(fields ...field.RelationField) ISysOperationRecordDo
FirstOrInit() (*models.SysOperationRecord, error)
FirstOrCreate() (*models.SysOperationRecord, error)
FindByPage(offset int, limit int) (result []*models.SysOperationRecord, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) ISysOperationRecordDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (s sysOperationRecordDo) Debug() ISysOperationRecordDo {
return s.withDO(s.DO.Debug())
}
func (s sysOperationRecordDo) WithContext(ctx context.Context) ISysOperationRecordDo {
return s.withDO(s.DO.WithContext(ctx))
}
func (s sysOperationRecordDo) ReadDB() ISysOperationRecordDo {
return s.Clauses(dbresolver.Read)
}
func (s sysOperationRecordDo) WriteDB() ISysOperationRecordDo {
return s.Clauses(dbresolver.Write)
}
func (s sysOperationRecordDo) Session(config *gorm.Session) ISysOperationRecordDo {
return s.withDO(s.DO.Session(config))
}
func (s sysOperationRecordDo) Clauses(conds ...clause.Expression) ISysOperationRecordDo {
return s.withDO(s.DO.Clauses(conds...))
}
func (s sysOperationRecordDo) Returning(value interface{}, columns ...string) ISysOperationRecordDo {
return s.withDO(s.DO.Returning(value, columns...))
}
func (s sysOperationRecordDo) Not(conds ...gen.Condition) ISysOperationRecordDo {
return s.withDO(s.DO.Not(conds...))
}
func (s sysOperationRecordDo) Or(conds ...gen.Condition) ISysOperationRecordDo {
return s.withDO(s.DO.Or(conds...))
}
func (s sysOperationRecordDo) Select(conds ...field.Expr) ISysOperationRecordDo {
return s.withDO(s.DO.Select(conds...))
}
func (s sysOperationRecordDo) Where(conds ...gen.Condition) ISysOperationRecordDo {
return s.withDO(s.DO.Where(conds...))
}
func (s sysOperationRecordDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) ISysOperationRecordDo {
return s.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}
func (s sysOperationRecordDo) Order(conds ...field.Expr) ISysOperationRecordDo {
return s.withDO(s.DO.Order(conds...))
}
func (s sysOperationRecordDo) Distinct(cols ...field.Expr) ISysOperationRecordDo {
return s.withDO(s.DO.Distinct(cols...))
}
func (s sysOperationRecordDo) Omit(cols ...field.Expr) ISysOperationRecordDo {
return s.withDO(s.DO.Omit(cols...))
}
func (s sysOperationRecordDo) Join(table schema.Tabler, on ...field.Expr) ISysOperationRecordDo {
return s.withDO(s.DO.Join(table, on...))
}
func (s sysOperationRecordDo) LeftJoin(table schema.Tabler, on ...field.Expr) ISysOperationRecordDo {
return s.withDO(s.DO.LeftJoin(table, on...))
}
func (s sysOperationRecordDo) RightJoin(table schema.Tabler, on ...field.Expr) ISysOperationRecordDo {
return s.withDO(s.DO.RightJoin(table, on...))
}
func (s sysOperationRecordDo) Group(cols ...field.Expr) ISysOperationRecordDo {
return s.withDO(s.DO.Group(cols...))
}
func (s sysOperationRecordDo) Having(conds ...gen.Condition) ISysOperationRecordDo {
return s.withDO(s.DO.Having(conds...))
}
func (s sysOperationRecordDo) Limit(limit int) ISysOperationRecordDo {
return s.withDO(s.DO.Limit(limit))
}
func (s sysOperationRecordDo) Offset(offset int) ISysOperationRecordDo {
return s.withDO(s.DO.Offset(offset))
}
func (s sysOperationRecordDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ISysOperationRecordDo {
return s.withDO(s.DO.Scopes(funcs...))
}
func (s sysOperationRecordDo) Unscoped() ISysOperationRecordDo {
return s.withDO(s.DO.Unscoped())
}
func (s sysOperationRecordDo) Create(values ...*models.SysOperationRecord) error {
if len(values) == 0 {
return nil
}
return s.DO.Create(values)
}
func (s sysOperationRecordDo) CreateInBatches(values []*models.SysOperationRecord, batchSize int) error {
return s.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (s sysOperationRecordDo) Save(values ...*models.SysOperationRecord) error {
if len(values) == 0 {
return nil
}
return s.DO.Save(values)
}
func (s sysOperationRecordDo) First() (*models.SysOperationRecord, error) {
if result, err := s.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.SysOperationRecord), nil
}
}
func (s sysOperationRecordDo) Take() (*models.SysOperationRecord, error) {
if result, err := s.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.SysOperationRecord), nil
}
}
func (s sysOperationRecordDo) Last() (*models.SysOperationRecord, error) {
if result, err := s.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.SysOperationRecord), nil
}
}
func (s sysOperationRecordDo) Find() ([]*models.SysOperationRecord, error) {
result, err := s.DO.Find()
return result.([]*models.SysOperationRecord), err
}
func (s sysOperationRecordDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.SysOperationRecord, err error) {
buf := make([]*models.SysOperationRecord, 0, batchSize)
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (s sysOperationRecordDo) FindInBatches(result *[]*models.SysOperationRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return s.DO.FindInBatches(result, batchSize, fc)
}
func (s sysOperationRecordDo) Attrs(attrs ...field.AssignExpr) ISysOperationRecordDo {
return s.withDO(s.DO.Attrs(attrs...))
}
func (s sysOperationRecordDo) Assign(attrs ...field.AssignExpr) ISysOperationRecordDo {
return s.withDO(s.DO.Assign(attrs...))
}
func (s sysOperationRecordDo) Joins(fields ...field.RelationField) ISysOperationRecordDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Joins(_f))
}
return &s
}
func (s sysOperationRecordDo) Preload(fields ...field.RelationField) ISysOperationRecordDo {
for _, _f := range fields {
s = *s.withDO(s.DO.Preload(_f))
}
return &s
}
func (s sysOperationRecordDo) FirstOrInit() (*models.SysOperationRecord, error) {
if result, err := s.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.SysOperationRecord), nil
}
}
func (s sysOperationRecordDo) FirstOrCreate() (*models.SysOperationRecord, error) {
if result, err := s.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.SysOperationRecord), nil
}
}
func (s sysOperationRecordDo) FindByPage(offset int, limit int) (result []*models.SysOperationRecord, count int64, err error) {
result, err = s.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = s.Offset(-1).Limit(-1).Count()
return
}
func (s sysOperationRecordDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = s.Count()
if err != nil {
return
}
err = s.Offset(offset).Limit(limit).Scan(result)
return
}
func (s sysOperationRecordDo) Scan(result interface{}) (err error) {
return s.DO.Scan(result)
}
func (s sysOperationRecordDo) Delete(models ...*models.SysOperationRecord) (result gen.ResultInfo, err error) {
return s.DO.Delete(models)
}
func (s *sysOperationRecordDo) withDO(do gen.Dao) *sysOperationRecordDo {
s.DO = *do.(*gen.DO)
return s
}