635 lines
16 KiB
Go
635 lines
16 KiB
Go
// 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 queries
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"gorm.io/gorm/schema"
|
|
|
|
"gorm.io/gen"
|
|
"gorm.io/gen/field"
|
|
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
"platform/web/models"
|
|
)
|
|
|
|
func newLogsRequest(db *gorm.DB, opts ...gen.DOOption) logsRequest {
|
|
_logsRequest := logsRequest{}
|
|
|
|
_logsRequest.logsRequestDo.UseDB(db, opts...)
|
|
_logsRequest.logsRequestDo.UseModel(&models.LogsRequest{})
|
|
|
|
tableName := _logsRequest.logsRequestDo.TableName()
|
|
_logsRequest.ALL = field.NewAsterisk(tableName)
|
|
_logsRequest.ID = field.NewInt32(tableName, "id")
|
|
_logsRequest.IP = field.NewField(tableName, "ip")
|
|
_logsRequest.UA = field.NewString(tableName, "ua")
|
|
_logsRequest.UserID = field.NewInt32(tableName, "user_id")
|
|
_logsRequest.ClientID = field.NewInt32(tableName, "client_id")
|
|
_logsRequest.Method = field.NewString(tableName, "method")
|
|
_logsRequest.Path = field.NewString(tableName, "path")
|
|
_logsRequest.Status = field.NewInt16(tableName, "status")
|
|
_logsRequest.Error = field.NewString(tableName, "error")
|
|
_logsRequest.Time = field.NewTime(tableName, "time")
|
|
_logsRequest.Latency = field.NewString(tableName, "latency")
|
|
_logsRequest.Client = logsRequestHasOneClient{
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
RelationField: field.NewRelation("Client", "models.Client"),
|
|
Permissions: struct {
|
|
field.RelationField
|
|
Parent struct {
|
|
field.RelationField
|
|
}
|
|
Children struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("Client.Permissions", "models.Permission"),
|
|
Parent: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("Client.Permissions.Parent", "models.Permission"),
|
|
},
|
|
Children: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("Client.Permissions.Children", "models.Permission"),
|
|
},
|
|
},
|
|
}
|
|
|
|
_logsRequest.User = logsRequestBelongsToUser{
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
RelationField: field.NewRelation("User", "models.User"),
|
|
Admin: struct {
|
|
field.RelationField
|
|
Roles struct {
|
|
field.RelationField
|
|
Permissions struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("User.Admin", "models.Admin"),
|
|
Roles: struct {
|
|
field.RelationField
|
|
Permissions struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("User.Admin.Roles", "models.AdminRole"),
|
|
Permissions: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("User.Admin.Roles.Permissions", "models.Permission"),
|
|
},
|
|
},
|
|
},
|
|
Discount: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("User.Discount", "models.ProductDiscount"),
|
|
},
|
|
Roles: struct {
|
|
field.RelationField
|
|
Permissions struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("User.Roles", "models.UserRole"),
|
|
Permissions: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("User.Roles.Permissions", "models.Permission"),
|
|
},
|
|
},
|
|
}
|
|
|
|
_logsRequest.fillFieldMap()
|
|
|
|
return _logsRequest
|
|
}
|
|
|
|
type logsRequest struct {
|
|
logsRequestDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32
|
|
IP field.Field
|
|
UA field.String
|
|
UserID field.Int32
|
|
ClientID field.Int32
|
|
Method field.String
|
|
Path field.String
|
|
Status field.Int16
|
|
Error field.String
|
|
Time field.Time
|
|
Latency field.String
|
|
Client logsRequestHasOneClient
|
|
|
|
User logsRequestBelongsToUser
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (l logsRequest) Table(newTableName string) *logsRequest {
|
|
l.logsRequestDo.UseTable(newTableName)
|
|
return l.updateTableName(newTableName)
|
|
}
|
|
|
|
func (l logsRequest) As(alias string) *logsRequest {
|
|
l.logsRequestDo.DO = *(l.logsRequestDo.As(alias).(*gen.DO))
|
|
return l.updateTableName(alias)
|
|
}
|
|
|
|
func (l *logsRequest) updateTableName(table string) *logsRequest {
|
|
l.ALL = field.NewAsterisk(table)
|
|
l.ID = field.NewInt32(table, "id")
|
|
l.IP = field.NewField(table, "ip")
|
|
l.UA = field.NewString(table, "ua")
|
|
l.UserID = field.NewInt32(table, "user_id")
|
|
l.ClientID = field.NewInt32(table, "client_id")
|
|
l.Method = field.NewString(table, "method")
|
|
l.Path = field.NewString(table, "path")
|
|
l.Status = field.NewInt16(table, "status")
|
|
l.Error = field.NewString(table, "error")
|
|
l.Time = field.NewTime(table, "time")
|
|
l.Latency = field.NewString(table, "latency")
|
|
|
|
l.fillFieldMap()
|
|
|
|
return l
|
|
}
|
|
|
|
func (l *logsRequest) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
_f, ok := l.fieldMap[fieldName]
|
|
if !ok || _f == nil {
|
|
return nil, false
|
|
}
|
|
_oe, ok := _f.(field.OrderExpr)
|
|
return _oe, ok
|
|
}
|
|
|
|
func (l *logsRequest) fillFieldMap() {
|
|
l.fieldMap = make(map[string]field.Expr, 13)
|
|
l.fieldMap["id"] = l.ID
|
|
l.fieldMap["ip"] = l.IP
|
|
l.fieldMap["ua"] = l.UA
|
|
l.fieldMap["user_id"] = l.UserID
|
|
l.fieldMap["client_id"] = l.ClientID
|
|
l.fieldMap["method"] = l.Method
|
|
l.fieldMap["path"] = l.Path
|
|
l.fieldMap["status"] = l.Status
|
|
l.fieldMap["error"] = l.Error
|
|
l.fieldMap["time"] = l.Time
|
|
l.fieldMap["latency"] = l.Latency
|
|
|
|
}
|
|
|
|
func (l logsRequest) clone(db *gorm.DB) logsRequest {
|
|
l.logsRequestDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
l.Client.db = db.Session(&gorm.Session{Initialized: true})
|
|
l.Client.db.Statement.ConnPool = db.Statement.ConnPool
|
|
l.User.db = db.Session(&gorm.Session{Initialized: true})
|
|
l.User.db.Statement.ConnPool = db.Statement.ConnPool
|
|
return l
|
|
}
|
|
|
|
func (l logsRequest) replaceDB(db *gorm.DB) logsRequest {
|
|
l.logsRequestDo.ReplaceDB(db)
|
|
l.Client.db = db.Session(&gorm.Session{})
|
|
l.User.db = db.Session(&gorm.Session{})
|
|
return l
|
|
}
|
|
|
|
type logsRequestHasOneClient struct {
|
|
db *gorm.DB
|
|
|
|
field.RelationField
|
|
|
|
Permissions struct {
|
|
field.RelationField
|
|
Parent struct {
|
|
field.RelationField
|
|
}
|
|
Children struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
}
|
|
|
|
func (a logsRequestHasOneClient) Where(conds ...field.Expr) *logsRequestHasOneClient {
|
|
if len(conds) == 0 {
|
|
return &a
|
|
}
|
|
|
|
exprs := make([]clause.Expression, 0, len(conds))
|
|
for _, cond := range conds {
|
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
|
}
|
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
|
return &a
|
|
}
|
|
|
|
func (a logsRequestHasOneClient) WithContext(ctx context.Context) *logsRequestHasOneClient {
|
|
a.db = a.db.WithContext(ctx)
|
|
return &a
|
|
}
|
|
|
|
func (a logsRequestHasOneClient) Session(session *gorm.Session) *logsRequestHasOneClient {
|
|
a.db = a.db.Session(session)
|
|
return &a
|
|
}
|
|
|
|
func (a logsRequestHasOneClient) Model(m *models.LogsRequest) *logsRequestHasOneClientTx {
|
|
return &logsRequestHasOneClientTx{a.db.Model(m).Association(a.Name())}
|
|
}
|
|
|
|
func (a logsRequestHasOneClient) Unscoped() *logsRequestHasOneClient {
|
|
a.db = a.db.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type logsRequestHasOneClientTx struct{ tx *gorm.Association }
|
|
|
|
func (a logsRequestHasOneClientTx) Find() (result *models.Client, err error) {
|
|
return result, a.tx.Find(&result)
|
|
}
|
|
|
|
func (a logsRequestHasOneClientTx) Append(values ...*models.Client) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Append(targetValues...)
|
|
}
|
|
|
|
func (a logsRequestHasOneClientTx) Replace(values ...*models.Client) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Replace(targetValues...)
|
|
}
|
|
|
|
func (a logsRequestHasOneClientTx) Delete(values ...*models.Client) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Delete(targetValues...)
|
|
}
|
|
|
|
func (a logsRequestHasOneClientTx) Clear() error {
|
|
return a.tx.Clear()
|
|
}
|
|
|
|
func (a logsRequestHasOneClientTx) Count() int64 {
|
|
return a.tx.Count()
|
|
}
|
|
|
|
func (a logsRequestHasOneClientTx) Unscoped() *logsRequestHasOneClientTx {
|
|
a.tx = a.tx.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type logsRequestBelongsToUser struct {
|
|
db *gorm.DB
|
|
|
|
field.RelationField
|
|
|
|
Admin struct {
|
|
field.RelationField
|
|
Roles struct {
|
|
field.RelationField
|
|
Permissions struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
}
|
|
Discount struct {
|
|
field.RelationField
|
|
}
|
|
Roles struct {
|
|
field.RelationField
|
|
Permissions struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
}
|
|
|
|
func (a logsRequestBelongsToUser) Where(conds ...field.Expr) *logsRequestBelongsToUser {
|
|
if len(conds) == 0 {
|
|
return &a
|
|
}
|
|
|
|
exprs := make([]clause.Expression, 0, len(conds))
|
|
for _, cond := range conds {
|
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
|
}
|
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
|
return &a
|
|
}
|
|
|
|
func (a logsRequestBelongsToUser) WithContext(ctx context.Context) *logsRequestBelongsToUser {
|
|
a.db = a.db.WithContext(ctx)
|
|
return &a
|
|
}
|
|
|
|
func (a logsRequestBelongsToUser) Session(session *gorm.Session) *logsRequestBelongsToUser {
|
|
a.db = a.db.Session(session)
|
|
return &a
|
|
}
|
|
|
|
func (a logsRequestBelongsToUser) Model(m *models.LogsRequest) *logsRequestBelongsToUserTx {
|
|
return &logsRequestBelongsToUserTx{a.db.Model(m).Association(a.Name())}
|
|
}
|
|
|
|
func (a logsRequestBelongsToUser) Unscoped() *logsRequestBelongsToUser {
|
|
a.db = a.db.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type logsRequestBelongsToUserTx struct{ tx *gorm.Association }
|
|
|
|
func (a logsRequestBelongsToUserTx) Find() (result *models.User, err error) {
|
|
return result, a.tx.Find(&result)
|
|
}
|
|
|
|
func (a logsRequestBelongsToUserTx) Append(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Append(targetValues...)
|
|
}
|
|
|
|
func (a logsRequestBelongsToUserTx) Replace(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Replace(targetValues...)
|
|
}
|
|
|
|
func (a logsRequestBelongsToUserTx) Delete(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Delete(targetValues...)
|
|
}
|
|
|
|
func (a logsRequestBelongsToUserTx) Clear() error {
|
|
return a.tx.Clear()
|
|
}
|
|
|
|
func (a logsRequestBelongsToUserTx) Count() int64 {
|
|
return a.tx.Count()
|
|
}
|
|
|
|
func (a logsRequestBelongsToUserTx) Unscoped() *logsRequestBelongsToUserTx {
|
|
a.tx = a.tx.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type logsRequestDo struct{ gen.DO }
|
|
|
|
func (l logsRequestDo) Debug() *logsRequestDo {
|
|
return l.withDO(l.DO.Debug())
|
|
}
|
|
|
|
func (l logsRequestDo) WithContext(ctx context.Context) *logsRequestDo {
|
|
return l.withDO(l.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (l logsRequestDo) ReadDB() *logsRequestDo {
|
|
return l.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (l logsRequestDo) WriteDB() *logsRequestDo {
|
|
return l.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (l logsRequestDo) Session(config *gorm.Session) *logsRequestDo {
|
|
return l.withDO(l.DO.Session(config))
|
|
}
|
|
|
|
func (l logsRequestDo) Clauses(conds ...clause.Expression) *logsRequestDo {
|
|
return l.withDO(l.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (l logsRequestDo) Returning(value interface{}, columns ...string) *logsRequestDo {
|
|
return l.withDO(l.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (l logsRequestDo) Not(conds ...gen.Condition) *logsRequestDo {
|
|
return l.withDO(l.DO.Not(conds...))
|
|
}
|
|
|
|
func (l logsRequestDo) Or(conds ...gen.Condition) *logsRequestDo {
|
|
return l.withDO(l.DO.Or(conds...))
|
|
}
|
|
|
|
func (l logsRequestDo) Select(conds ...field.Expr) *logsRequestDo {
|
|
return l.withDO(l.DO.Select(conds...))
|
|
}
|
|
|
|
func (l logsRequestDo) Where(conds ...gen.Condition) *logsRequestDo {
|
|
return l.withDO(l.DO.Where(conds...))
|
|
}
|
|
|
|
func (l logsRequestDo) Order(conds ...field.Expr) *logsRequestDo {
|
|
return l.withDO(l.DO.Order(conds...))
|
|
}
|
|
|
|
func (l logsRequestDo) Distinct(cols ...field.Expr) *logsRequestDo {
|
|
return l.withDO(l.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (l logsRequestDo) Omit(cols ...field.Expr) *logsRequestDo {
|
|
return l.withDO(l.DO.Omit(cols...))
|
|
}
|
|
|
|
func (l logsRequestDo) Join(table schema.Tabler, on ...field.Expr) *logsRequestDo {
|
|
return l.withDO(l.DO.Join(table, on...))
|
|
}
|
|
|
|
func (l logsRequestDo) LeftJoin(table schema.Tabler, on ...field.Expr) *logsRequestDo {
|
|
return l.withDO(l.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (l logsRequestDo) RightJoin(table schema.Tabler, on ...field.Expr) *logsRequestDo {
|
|
return l.withDO(l.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (l logsRequestDo) Group(cols ...field.Expr) *logsRequestDo {
|
|
return l.withDO(l.DO.Group(cols...))
|
|
}
|
|
|
|
func (l logsRequestDo) Having(conds ...gen.Condition) *logsRequestDo {
|
|
return l.withDO(l.DO.Having(conds...))
|
|
}
|
|
|
|
func (l logsRequestDo) Limit(limit int) *logsRequestDo {
|
|
return l.withDO(l.DO.Limit(limit))
|
|
}
|
|
|
|
func (l logsRequestDo) Offset(offset int) *logsRequestDo {
|
|
return l.withDO(l.DO.Offset(offset))
|
|
}
|
|
|
|
func (l logsRequestDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *logsRequestDo {
|
|
return l.withDO(l.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (l logsRequestDo) Unscoped() *logsRequestDo {
|
|
return l.withDO(l.DO.Unscoped())
|
|
}
|
|
|
|
func (l logsRequestDo) Create(values ...*models.LogsRequest) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return l.DO.Create(values)
|
|
}
|
|
|
|
func (l logsRequestDo) CreateInBatches(values []*models.LogsRequest, batchSize int) error {
|
|
return l.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 (l logsRequestDo) Save(values ...*models.LogsRequest) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return l.DO.Save(values)
|
|
}
|
|
|
|
func (l logsRequestDo) First() (*models.LogsRequest, error) {
|
|
if result, err := l.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.LogsRequest), nil
|
|
}
|
|
}
|
|
|
|
func (l logsRequestDo) Take() (*models.LogsRequest, error) {
|
|
if result, err := l.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.LogsRequest), nil
|
|
}
|
|
}
|
|
|
|
func (l logsRequestDo) Last() (*models.LogsRequest, error) {
|
|
if result, err := l.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.LogsRequest), nil
|
|
}
|
|
}
|
|
|
|
func (l logsRequestDo) Find() ([]*models.LogsRequest, error) {
|
|
result, err := l.DO.Find()
|
|
return result.([]*models.LogsRequest), err
|
|
}
|
|
|
|
func (l logsRequestDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.LogsRequest, err error) {
|
|
buf := make([]*models.LogsRequest, 0, batchSize)
|
|
err = l.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 (l logsRequestDo) FindInBatches(result *[]*models.LogsRequest, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return l.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (l logsRequestDo) Attrs(attrs ...field.AssignExpr) *logsRequestDo {
|
|
return l.withDO(l.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (l logsRequestDo) Assign(attrs ...field.AssignExpr) *logsRequestDo {
|
|
return l.withDO(l.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (l logsRequestDo) Joins(fields ...field.RelationField) *logsRequestDo {
|
|
for _, _f := range fields {
|
|
l = *l.withDO(l.DO.Joins(_f))
|
|
}
|
|
return &l
|
|
}
|
|
|
|
func (l logsRequestDo) Preload(fields ...field.RelationField) *logsRequestDo {
|
|
for _, _f := range fields {
|
|
l = *l.withDO(l.DO.Preload(_f))
|
|
}
|
|
return &l
|
|
}
|
|
|
|
func (l logsRequestDo) FirstOrInit() (*models.LogsRequest, error) {
|
|
if result, err := l.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.LogsRequest), nil
|
|
}
|
|
}
|
|
|
|
func (l logsRequestDo) FirstOrCreate() (*models.LogsRequest, error) {
|
|
if result, err := l.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.LogsRequest), nil
|
|
}
|
|
}
|
|
|
|
func (l logsRequestDo) FindByPage(offset int, limit int) (result []*models.LogsRequest, count int64, err error) {
|
|
result, err = l.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 = l.Offset(-1).Limit(-1).Count()
|
|
return
|
|
}
|
|
|
|
func (l logsRequestDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
count, err = l.Count()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = l.Offset(offset).Limit(limit).Scan(result)
|
|
return
|
|
}
|
|
|
|
func (l logsRequestDo) Scan(result interface{}) (err error) {
|
|
return l.DO.Scan(result)
|
|
}
|
|
|
|
func (l logsRequestDo) Delete(models ...*models.LogsRequest) (result gen.ResultInfo, err error) {
|
|
return l.DO.Delete(models)
|
|
}
|
|
|
|
func (l *logsRequestDo) withDO(do gen.Dao) *logsRequestDo {
|
|
l.DO = *do.(*gen.DO)
|
|
return l
|
|
}
|