Initial commit
This commit is contained in:
127
internal/database/query/gen.go
Normal file
127
internal/database/query/gen.go
Normal file
@@ -0,0 +1,127 @@
|
||||
// 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"
|
||||
"database/sql"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"gorm.io/gen"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
var (
|
||||
Q = new(Query)
|
||||
Payment *payment
|
||||
Plan *plan
|
||||
User *user
|
||||
Video *video
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
Payment = &Q.Payment
|
||||
Plan = &Q.Plan
|
||||
User = &Q.User
|
||||
Video = &Q.Video
|
||||
}
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Payment: newPayment(db, opts...),
|
||||
Plan: newPlan(db, opts...),
|
||||
User: newUser(db, opts...),
|
||||
Video: newVideo(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
Payment payment
|
||||
Plan plan
|
||||
User user
|
||||
Video video
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Payment: q.Payment.clone(db),
|
||||
Plan: q.Plan.clone(db),
|
||||
User: q.User.clone(db),
|
||||
Video: q.Video.clone(db),
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Query) ReadDB() *Query {
|
||||
return q.ReplaceDB(q.db.Clauses(dbresolver.Read))
|
||||
}
|
||||
|
||||
func (q *Query) WriteDB() *Query {
|
||||
return q.ReplaceDB(q.db.Clauses(dbresolver.Write))
|
||||
}
|
||||
|
||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Payment: q.Payment.replaceDB(db),
|
||||
Plan: q.Plan.replaceDB(db),
|
||||
User: q.User.replaceDB(db),
|
||||
Video: q.Video.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
Payment IPaymentDo
|
||||
Plan IPlanDo
|
||||
User IUserDo
|
||||
Video IVideoDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
Payment: q.Payment.WithContext(ctx),
|
||||
Plan: q.Plan.WithContext(ctx),
|
||||
User: q.User.WithContext(ctx),
|
||||
Video: q.Video.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error {
|
||||
return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...)
|
||||
}
|
||||
|
||||
func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx {
|
||||
tx := q.db.Begin(opts...)
|
||||
return &QueryTx{Query: q.clone(tx), Error: tx.Error}
|
||||
}
|
||||
|
||||
type QueryTx struct {
|
||||
*Query
|
||||
Error error
|
||||
}
|
||||
|
||||
func (q *QueryTx) Commit() error {
|
||||
return q.db.Commit().Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) Rollback() error {
|
||||
return q.db.Rollback().Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) SavePoint(name string) error {
|
||||
return q.db.SavePoint(name).Error
|
||||
}
|
||||
|
||||
func (q *QueryTx) RollbackTo(name string) error {
|
||||
return q.db.RollbackTo(name).Error
|
||||
}
|
||||
427
internal/database/query/payment.gen.go
Normal file
427
internal/database/query/payment.gen.go
Normal file
@@ -0,0 +1,427 @@
|
||||
// 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"
|
||||
"database/sql"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"stream.api/internal/database/model"
|
||||
)
|
||||
|
||||
func newPayment(db *gorm.DB, opts ...gen.DOOption) payment {
|
||||
_payment := payment{}
|
||||
|
||||
_payment.paymentDo.UseDB(db, opts...)
|
||||
_payment.paymentDo.UseModel(&model.Payment{})
|
||||
|
||||
tableName := _payment.paymentDo.TableName()
|
||||
_payment.ALL = field.NewAsterisk(tableName)
|
||||
_payment.ID = field.NewString(tableName, "id")
|
||||
_payment.UserID = field.NewString(tableName, "user_id")
|
||||
_payment.PlanID = field.NewString(tableName, "plan_id")
|
||||
_payment.Amount = field.NewFloat64(tableName, "amount")
|
||||
_payment.Currency = field.NewString(tableName, "currency")
|
||||
_payment.Status = field.NewString(tableName, "status")
|
||||
_payment.Provider = field.NewString(tableName, "provider")
|
||||
_payment.TransactionID = field.NewString(tableName, "transaction_id")
|
||||
_payment.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_payment.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
|
||||
_payment.fillFieldMap()
|
||||
|
||||
return _payment
|
||||
}
|
||||
|
||||
type payment struct {
|
||||
paymentDo paymentDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.String
|
||||
UserID field.String
|
||||
PlanID field.String
|
||||
Amount field.Float64
|
||||
Currency field.String
|
||||
Status field.String
|
||||
Provider field.String
|
||||
TransactionID field.String
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p payment) Table(newTableName string) *payment {
|
||||
p.paymentDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p payment) As(alias string) *payment {
|
||||
p.paymentDo.DO = *(p.paymentDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *payment) updateTableName(table string) *payment {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.ID = field.NewString(table, "id")
|
||||
p.UserID = field.NewString(table, "user_id")
|
||||
p.PlanID = field.NewString(table, "plan_id")
|
||||
p.Amount = field.NewFloat64(table, "amount")
|
||||
p.Currency = field.NewString(table, "currency")
|
||||
p.Status = field.NewString(table, "status")
|
||||
p.Provider = field.NewString(table, "provider")
|
||||
p.TransactionID = field.NewString(table, "transaction_id")
|
||||
p.CreatedAt = field.NewTime(table, "created_at")
|
||||
p.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *payment) WithContext(ctx context.Context) IPaymentDo { return p.paymentDo.WithContext(ctx) }
|
||||
|
||||
func (p payment) TableName() string { return p.paymentDo.TableName() }
|
||||
|
||||
func (p payment) Alias() string { return p.paymentDo.Alias() }
|
||||
|
||||
func (p payment) Columns(cols ...field.Expr) gen.Columns { return p.paymentDo.Columns(cols...) }
|
||||
|
||||
func (p *payment) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *payment) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 10)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["user_id"] = p.UserID
|
||||
p.fieldMap["plan_id"] = p.PlanID
|
||||
p.fieldMap["amount"] = p.Amount
|
||||
p.fieldMap["currency"] = p.Currency
|
||||
p.fieldMap["status"] = p.Status
|
||||
p.fieldMap["provider"] = p.Provider
|
||||
p.fieldMap["transaction_id"] = p.TransactionID
|
||||
p.fieldMap["created_at"] = p.CreatedAt
|
||||
p.fieldMap["updated_at"] = p.UpdatedAt
|
||||
}
|
||||
|
||||
func (p payment) clone(db *gorm.DB) payment {
|
||||
p.paymentDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p payment) replaceDB(db *gorm.DB) payment {
|
||||
p.paymentDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type paymentDo struct{ gen.DO }
|
||||
|
||||
type IPaymentDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IPaymentDo
|
||||
WithContext(ctx context.Context) IPaymentDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IPaymentDo
|
||||
WriteDB() IPaymentDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IPaymentDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IPaymentDo
|
||||
Not(conds ...gen.Condition) IPaymentDo
|
||||
Or(conds ...gen.Condition) IPaymentDo
|
||||
Select(conds ...field.Expr) IPaymentDo
|
||||
Where(conds ...gen.Condition) IPaymentDo
|
||||
Order(conds ...field.Expr) IPaymentDo
|
||||
Distinct(cols ...field.Expr) IPaymentDo
|
||||
Omit(cols ...field.Expr) IPaymentDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IPaymentDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IPaymentDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IPaymentDo
|
||||
Group(cols ...field.Expr) IPaymentDo
|
||||
Having(conds ...gen.Condition) IPaymentDo
|
||||
Limit(limit int) IPaymentDo
|
||||
Offset(offset int) IPaymentDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IPaymentDo
|
||||
Unscoped() IPaymentDo
|
||||
Create(values ...*model.Payment) error
|
||||
CreateInBatches(values []*model.Payment, batchSize int) error
|
||||
Save(values ...*model.Payment) error
|
||||
First() (*model.Payment, error)
|
||||
Take() (*model.Payment, error)
|
||||
Last() (*model.Payment, error)
|
||||
Find() ([]*model.Payment, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Payment, err error)
|
||||
FindInBatches(result *[]*model.Payment, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.Payment) (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) IPaymentDo
|
||||
Assign(attrs ...field.AssignExpr) IPaymentDo
|
||||
Joins(fields ...field.RelationField) IPaymentDo
|
||||
Preload(fields ...field.RelationField) IPaymentDo
|
||||
FirstOrInit() (*model.Payment, error)
|
||||
FirstOrCreate() (*model.Payment, error)
|
||||
FindByPage(offset int, limit int) (result []*model.Payment, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Rows() (*sql.Rows, error)
|
||||
Row() *sql.Row
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IPaymentDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p paymentDo) Debug() IPaymentDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p paymentDo) WithContext(ctx context.Context) IPaymentDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p paymentDo) ReadDB() IPaymentDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p paymentDo) WriteDB() IPaymentDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p paymentDo) Session(config *gorm.Session) IPaymentDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p paymentDo) Clauses(conds ...clause.Expression) IPaymentDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Returning(value interface{}, columns ...string) IPaymentDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Not(conds ...gen.Condition) IPaymentDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Or(conds ...gen.Condition) IPaymentDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Select(conds ...field.Expr) IPaymentDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Where(conds ...gen.Condition) IPaymentDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Order(conds ...field.Expr) IPaymentDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Distinct(cols ...field.Expr) IPaymentDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Omit(cols ...field.Expr) IPaymentDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Join(table schema.Tabler, on ...field.Expr) IPaymentDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p paymentDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPaymentDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p paymentDo) RightJoin(table schema.Tabler, on ...field.Expr) IPaymentDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Group(cols ...field.Expr) IPaymentDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Having(conds ...gen.Condition) IPaymentDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Limit(limit int) IPaymentDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p paymentDo) Offset(offset int) IPaymentDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p paymentDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPaymentDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Unscoped() IPaymentDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p paymentDo) Create(values ...*model.Payment) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p paymentDo) CreateInBatches(values []*model.Payment, batchSize int) error {
|
||||
return p.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 (p paymentDo) Save(values ...*model.Payment) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p paymentDo) First() (*model.Payment, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Payment), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p paymentDo) Take() (*model.Payment, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Payment), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p paymentDo) Last() (*model.Payment, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Payment), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p paymentDo) Find() ([]*model.Payment, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*model.Payment), err
|
||||
}
|
||||
|
||||
func (p paymentDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Payment, err error) {
|
||||
buf := make([]*model.Payment, 0, batchSize)
|
||||
err = p.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 (p paymentDo) FindInBatches(result *[]*model.Payment, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p paymentDo) Attrs(attrs ...field.AssignExpr) IPaymentDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Assign(attrs ...field.AssignExpr) IPaymentDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p paymentDo) Joins(fields ...field.RelationField) IPaymentDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p paymentDo) Preload(fields ...field.RelationField) IPaymentDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p paymentDo) FirstOrInit() (*model.Payment, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Payment), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p paymentDo) FirstOrCreate() (*model.Payment, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Payment), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p paymentDo) FindByPage(offset int, limit int) (result []*model.Payment, count int64, err error) {
|
||||
result, err = p.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 = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p paymentDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p paymentDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p paymentDo) Delete(models ...*model.Payment) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *paymentDo) withDO(do gen.Dao) *paymentDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
431
internal/database/query/plan.gen.go
Normal file
431
internal/database/query/plan.gen.go
Normal file
@@ -0,0 +1,431 @@
|
||||
// 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"
|
||||
"database/sql"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"stream.api/internal/database/model"
|
||||
)
|
||||
|
||||
func newPlan(db *gorm.DB, opts ...gen.DOOption) plan {
|
||||
_plan := plan{}
|
||||
|
||||
_plan.planDo.UseDB(db, opts...)
|
||||
_plan.planDo.UseModel(&model.Plan{})
|
||||
|
||||
tableName := _plan.planDo.TableName()
|
||||
_plan.ALL = field.NewAsterisk(tableName)
|
||||
_plan.ID = field.NewString(tableName, "id")
|
||||
_plan.Name = field.NewString(tableName, "name")
|
||||
_plan.Description = field.NewString(tableName, "description")
|
||||
_plan.Price = field.NewFloat64(tableName, "price")
|
||||
_plan.Cycle = field.NewString(tableName, "cycle")
|
||||
_plan.StorageLimit = field.NewInt64(tableName, "storage_limit")
|
||||
_plan.UploadLimit = field.NewInt32(tableName, "upload_limit")
|
||||
_plan.DurationLimit = field.NewInt32(tableName, "duration_limit")
|
||||
_plan.QualityLimit = field.NewString(tableName, "quality_limit")
|
||||
_plan.Features = field.NewString(tableName, "features")
|
||||
_plan.IsActive = field.NewBool(tableName, "is_active")
|
||||
|
||||
_plan.fillFieldMap()
|
||||
|
||||
return _plan
|
||||
}
|
||||
|
||||
type plan struct {
|
||||
planDo planDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.String
|
||||
Name field.String
|
||||
Description field.String
|
||||
Price field.Float64
|
||||
Cycle field.String
|
||||
StorageLimit field.Int64
|
||||
UploadLimit field.Int32
|
||||
DurationLimit field.Int32
|
||||
QualityLimit field.String
|
||||
Features field.String
|
||||
IsActive field.Bool
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (p plan) Table(newTableName string) *plan {
|
||||
p.planDo.UseTable(newTableName)
|
||||
return p.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (p plan) As(alias string) *plan {
|
||||
p.planDo.DO = *(p.planDo.As(alias).(*gen.DO))
|
||||
return p.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (p *plan) updateTableName(table string) *plan {
|
||||
p.ALL = field.NewAsterisk(table)
|
||||
p.ID = field.NewString(table, "id")
|
||||
p.Name = field.NewString(table, "name")
|
||||
p.Description = field.NewString(table, "description")
|
||||
p.Price = field.NewFloat64(table, "price")
|
||||
p.Cycle = field.NewString(table, "cycle")
|
||||
p.StorageLimit = field.NewInt64(table, "storage_limit")
|
||||
p.UploadLimit = field.NewInt32(table, "upload_limit")
|
||||
p.DurationLimit = field.NewInt32(table, "duration_limit")
|
||||
p.QualityLimit = field.NewString(table, "quality_limit")
|
||||
p.Features = field.NewString(table, "features")
|
||||
p.IsActive = field.NewBool(table, "is_active")
|
||||
|
||||
p.fillFieldMap()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *plan) WithContext(ctx context.Context) IPlanDo { return p.planDo.WithContext(ctx) }
|
||||
|
||||
func (p plan) TableName() string { return p.planDo.TableName() }
|
||||
|
||||
func (p plan) Alias() string { return p.planDo.Alias() }
|
||||
|
||||
func (p plan) Columns(cols ...field.Expr) gen.Columns { return p.planDo.Columns(cols...) }
|
||||
|
||||
func (p *plan) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := p.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (p *plan) fillFieldMap() {
|
||||
p.fieldMap = make(map[string]field.Expr, 11)
|
||||
p.fieldMap["id"] = p.ID
|
||||
p.fieldMap["name"] = p.Name
|
||||
p.fieldMap["description"] = p.Description
|
||||
p.fieldMap["price"] = p.Price
|
||||
p.fieldMap["cycle"] = p.Cycle
|
||||
p.fieldMap["storage_limit"] = p.StorageLimit
|
||||
p.fieldMap["upload_limit"] = p.UploadLimit
|
||||
p.fieldMap["duration_limit"] = p.DurationLimit
|
||||
p.fieldMap["quality_limit"] = p.QualityLimit
|
||||
p.fieldMap["features"] = p.Features
|
||||
p.fieldMap["is_active"] = p.IsActive
|
||||
}
|
||||
|
||||
func (p plan) clone(db *gorm.DB) plan {
|
||||
p.planDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p plan) replaceDB(db *gorm.DB) plan {
|
||||
p.planDo.ReplaceDB(db)
|
||||
return p
|
||||
}
|
||||
|
||||
type planDo struct{ gen.DO }
|
||||
|
||||
type IPlanDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IPlanDo
|
||||
WithContext(ctx context.Context) IPlanDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IPlanDo
|
||||
WriteDB() IPlanDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IPlanDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IPlanDo
|
||||
Not(conds ...gen.Condition) IPlanDo
|
||||
Or(conds ...gen.Condition) IPlanDo
|
||||
Select(conds ...field.Expr) IPlanDo
|
||||
Where(conds ...gen.Condition) IPlanDo
|
||||
Order(conds ...field.Expr) IPlanDo
|
||||
Distinct(cols ...field.Expr) IPlanDo
|
||||
Omit(cols ...field.Expr) IPlanDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IPlanDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IPlanDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IPlanDo
|
||||
Group(cols ...field.Expr) IPlanDo
|
||||
Having(conds ...gen.Condition) IPlanDo
|
||||
Limit(limit int) IPlanDo
|
||||
Offset(offset int) IPlanDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IPlanDo
|
||||
Unscoped() IPlanDo
|
||||
Create(values ...*model.Plan) error
|
||||
CreateInBatches(values []*model.Plan, batchSize int) error
|
||||
Save(values ...*model.Plan) error
|
||||
First() (*model.Plan, error)
|
||||
Take() (*model.Plan, error)
|
||||
Last() (*model.Plan, error)
|
||||
Find() ([]*model.Plan, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Plan, err error)
|
||||
FindInBatches(result *[]*model.Plan, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.Plan) (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) IPlanDo
|
||||
Assign(attrs ...field.AssignExpr) IPlanDo
|
||||
Joins(fields ...field.RelationField) IPlanDo
|
||||
Preload(fields ...field.RelationField) IPlanDo
|
||||
FirstOrInit() (*model.Plan, error)
|
||||
FirstOrCreate() (*model.Plan, error)
|
||||
FindByPage(offset int, limit int) (result []*model.Plan, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Rows() (*sql.Rows, error)
|
||||
Row() *sql.Row
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IPlanDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (p planDo) Debug() IPlanDo {
|
||||
return p.withDO(p.DO.Debug())
|
||||
}
|
||||
|
||||
func (p planDo) WithContext(ctx context.Context) IPlanDo {
|
||||
return p.withDO(p.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (p planDo) ReadDB() IPlanDo {
|
||||
return p.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (p planDo) WriteDB() IPlanDo {
|
||||
return p.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (p planDo) Session(config *gorm.Session) IPlanDo {
|
||||
return p.withDO(p.DO.Session(config))
|
||||
}
|
||||
|
||||
func (p planDo) Clauses(conds ...clause.Expression) IPlanDo {
|
||||
return p.withDO(p.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (p planDo) Returning(value interface{}, columns ...string) IPlanDo {
|
||||
return p.withDO(p.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (p planDo) Not(conds ...gen.Condition) IPlanDo {
|
||||
return p.withDO(p.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (p planDo) Or(conds ...gen.Condition) IPlanDo {
|
||||
return p.withDO(p.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (p planDo) Select(conds ...field.Expr) IPlanDo {
|
||||
return p.withDO(p.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (p planDo) Where(conds ...gen.Condition) IPlanDo {
|
||||
return p.withDO(p.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (p planDo) Order(conds ...field.Expr) IPlanDo {
|
||||
return p.withDO(p.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (p planDo) Distinct(cols ...field.Expr) IPlanDo {
|
||||
return p.withDO(p.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (p planDo) Omit(cols ...field.Expr) IPlanDo {
|
||||
return p.withDO(p.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (p planDo) Join(table schema.Tabler, on ...field.Expr) IPlanDo {
|
||||
return p.withDO(p.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (p planDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPlanDo {
|
||||
return p.withDO(p.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p planDo) RightJoin(table schema.Tabler, on ...field.Expr) IPlanDo {
|
||||
return p.withDO(p.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (p planDo) Group(cols ...field.Expr) IPlanDo {
|
||||
return p.withDO(p.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (p planDo) Having(conds ...gen.Condition) IPlanDo {
|
||||
return p.withDO(p.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (p planDo) Limit(limit int) IPlanDo {
|
||||
return p.withDO(p.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (p planDo) Offset(offset int) IPlanDo {
|
||||
return p.withDO(p.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (p planDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPlanDo {
|
||||
return p.withDO(p.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (p planDo) Unscoped() IPlanDo {
|
||||
return p.withDO(p.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (p planDo) Create(values ...*model.Plan) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Create(values)
|
||||
}
|
||||
|
||||
func (p planDo) CreateInBatches(values []*model.Plan, batchSize int) error {
|
||||
return p.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 (p planDo) Save(values ...*model.Plan) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return p.DO.Save(values)
|
||||
}
|
||||
|
||||
func (p planDo) First() (*model.Plan, error) {
|
||||
if result, err := p.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Plan), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p planDo) Take() (*model.Plan, error) {
|
||||
if result, err := p.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Plan), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p planDo) Last() (*model.Plan, error) {
|
||||
if result, err := p.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Plan), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p planDo) Find() ([]*model.Plan, error) {
|
||||
result, err := p.DO.Find()
|
||||
return result.([]*model.Plan), err
|
||||
}
|
||||
|
||||
func (p planDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Plan, err error) {
|
||||
buf := make([]*model.Plan, 0, batchSize)
|
||||
err = p.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 (p planDo) FindInBatches(result *[]*model.Plan, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return p.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (p planDo) Attrs(attrs ...field.AssignExpr) IPlanDo {
|
||||
return p.withDO(p.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (p planDo) Assign(attrs ...field.AssignExpr) IPlanDo {
|
||||
return p.withDO(p.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (p planDo) Joins(fields ...field.RelationField) IPlanDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Joins(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p planDo) Preload(fields ...field.RelationField) IPlanDo {
|
||||
for _, _f := range fields {
|
||||
p = *p.withDO(p.DO.Preload(_f))
|
||||
}
|
||||
return &p
|
||||
}
|
||||
|
||||
func (p planDo) FirstOrInit() (*model.Plan, error) {
|
||||
if result, err := p.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Plan), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p planDo) FirstOrCreate() (*model.Plan, error) {
|
||||
if result, err := p.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Plan), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p planDo) FindByPage(offset int, limit int) (result []*model.Plan, count int64, err error) {
|
||||
result, err = p.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 = p.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (p planDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = p.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = p.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (p planDo) Scan(result interface{}) (err error) {
|
||||
return p.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (p planDo) Delete(models ...*model.Plan) (result gen.ResultInfo, err error) {
|
||||
return p.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (p *planDo) withDO(do gen.Dao) *planDo {
|
||||
p.DO = *do.(*gen.DO)
|
||||
return p
|
||||
}
|
||||
431
internal/database/query/user.gen.go
Normal file
431
internal/database/query/user.gen.go
Normal file
@@ -0,0 +1,431 @@
|
||||
// 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"
|
||||
"database/sql"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"stream.api/internal/database/model"
|
||||
)
|
||||
|
||||
func newUser(db *gorm.DB, opts ...gen.DOOption) user {
|
||||
_user := user{}
|
||||
|
||||
_user.userDo.UseDB(db, opts...)
|
||||
_user.userDo.UseModel(&model.User{})
|
||||
|
||||
tableName := _user.userDo.TableName()
|
||||
_user.ALL = field.NewAsterisk(tableName)
|
||||
_user.ID = field.NewString(tableName, "id")
|
||||
_user.Email = field.NewString(tableName, "email")
|
||||
_user.Password = field.NewString(tableName, "password")
|
||||
_user.Username = field.NewString(tableName, "username")
|
||||
_user.Avatar = field.NewString(tableName, "avatar")
|
||||
_user.Role = field.NewString(tableName, "role")
|
||||
_user.GoogleID = field.NewString(tableName, "google_id")
|
||||
_user.StorageUsed = field.NewInt64(tableName, "storage_used")
|
||||
_user.PlanID = field.NewString(tableName, "plan_id")
|
||||
_user.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_user.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
|
||||
_user.fillFieldMap()
|
||||
|
||||
return _user
|
||||
}
|
||||
|
||||
type user struct {
|
||||
userDo userDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.String
|
||||
Email field.String
|
||||
Password field.String
|
||||
Username field.String
|
||||
Avatar field.String
|
||||
Role field.String
|
||||
GoogleID field.String
|
||||
StorageUsed field.Int64
|
||||
PlanID field.String
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (u user) Table(newTableName string) *user {
|
||||
u.userDo.UseTable(newTableName)
|
||||
return u.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (u user) As(alias string) *user {
|
||||
u.userDo.DO = *(u.userDo.As(alias).(*gen.DO))
|
||||
return u.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (u *user) updateTableName(table string) *user {
|
||||
u.ALL = field.NewAsterisk(table)
|
||||
u.ID = field.NewString(table, "id")
|
||||
u.Email = field.NewString(table, "email")
|
||||
u.Password = field.NewString(table, "password")
|
||||
u.Username = field.NewString(table, "username")
|
||||
u.Avatar = field.NewString(table, "avatar")
|
||||
u.Role = field.NewString(table, "role")
|
||||
u.GoogleID = field.NewString(table, "google_id")
|
||||
u.StorageUsed = field.NewInt64(table, "storage_used")
|
||||
u.PlanID = field.NewString(table, "plan_id")
|
||||
u.CreatedAt = field.NewTime(table, "created_at")
|
||||
u.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
u.fillFieldMap()
|
||||
|
||||
return u
|
||||
}
|
||||
|
||||
func (u *user) WithContext(ctx context.Context) IUserDo { return u.userDo.WithContext(ctx) }
|
||||
|
||||
func (u user) TableName() string { return u.userDo.TableName() }
|
||||
|
||||
func (u user) Alias() string { return u.userDo.Alias() }
|
||||
|
||||
func (u user) Columns(cols ...field.Expr) gen.Columns { return u.userDo.Columns(cols...) }
|
||||
|
||||
func (u *user) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := u.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (u *user) fillFieldMap() {
|
||||
u.fieldMap = make(map[string]field.Expr, 11)
|
||||
u.fieldMap["id"] = u.ID
|
||||
u.fieldMap["email"] = u.Email
|
||||
u.fieldMap["password"] = u.Password
|
||||
u.fieldMap["username"] = u.Username
|
||||
u.fieldMap["avatar"] = u.Avatar
|
||||
u.fieldMap["role"] = u.Role
|
||||
u.fieldMap["google_id"] = u.GoogleID
|
||||
u.fieldMap["storage_used"] = u.StorageUsed
|
||||
u.fieldMap["plan_id"] = u.PlanID
|
||||
u.fieldMap["created_at"] = u.CreatedAt
|
||||
u.fieldMap["updated_at"] = u.UpdatedAt
|
||||
}
|
||||
|
||||
func (u user) clone(db *gorm.DB) user {
|
||||
u.userDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return u
|
||||
}
|
||||
|
||||
func (u user) replaceDB(db *gorm.DB) user {
|
||||
u.userDo.ReplaceDB(db)
|
||||
return u
|
||||
}
|
||||
|
||||
type userDo struct{ gen.DO }
|
||||
|
||||
type IUserDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IUserDo
|
||||
WithContext(ctx context.Context) IUserDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IUserDo
|
||||
WriteDB() IUserDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IUserDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IUserDo
|
||||
Not(conds ...gen.Condition) IUserDo
|
||||
Or(conds ...gen.Condition) IUserDo
|
||||
Select(conds ...field.Expr) IUserDo
|
||||
Where(conds ...gen.Condition) IUserDo
|
||||
Order(conds ...field.Expr) IUserDo
|
||||
Distinct(cols ...field.Expr) IUserDo
|
||||
Omit(cols ...field.Expr) IUserDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IUserDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IUserDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IUserDo
|
||||
Group(cols ...field.Expr) IUserDo
|
||||
Having(conds ...gen.Condition) IUserDo
|
||||
Limit(limit int) IUserDo
|
||||
Offset(offset int) IUserDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IUserDo
|
||||
Unscoped() IUserDo
|
||||
Create(values ...*model.User) error
|
||||
CreateInBatches(values []*model.User, batchSize int) error
|
||||
Save(values ...*model.User) error
|
||||
First() (*model.User, error)
|
||||
Take() (*model.User, error)
|
||||
Last() (*model.User, error)
|
||||
Find() ([]*model.User, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.User, err error)
|
||||
FindInBatches(result *[]*model.User, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.User) (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) IUserDo
|
||||
Assign(attrs ...field.AssignExpr) IUserDo
|
||||
Joins(fields ...field.RelationField) IUserDo
|
||||
Preload(fields ...field.RelationField) IUserDo
|
||||
FirstOrInit() (*model.User, error)
|
||||
FirstOrCreate() (*model.User, error)
|
||||
FindByPage(offset int, limit int) (result []*model.User, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Rows() (*sql.Rows, error)
|
||||
Row() *sql.Row
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IUserDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (u userDo) Debug() IUserDo {
|
||||
return u.withDO(u.DO.Debug())
|
||||
}
|
||||
|
||||
func (u userDo) WithContext(ctx context.Context) IUserDo {
|
||||
return u.withDO(u.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (u userDo) ReadDB() IUserDo {
|
||||
return u.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (u userDo) WriteDB() IUserDo {
|
||||
return u.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (u userDo) Session(config *gorm.Session) IUserDo {
|
||||
return u.withDO(u.DO.Session(config))
|
||||
}
|
||||
|
||||
func (u userDo) Clauses(conds ...clause.Expression) IUserDo {
|
||||
return u.withDO(u.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Returning(value interface{}, columns ...string) IUserDo {
|
||||
return u.withDO(u.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (u userDo) Not(conds ...gen.Condition) IUserDo {
|
||||
return u.withDO(u.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Or(conds ...gen.Condition) IUserDo {
|
||||
return u.withDO(u.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Select(conds ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Where(conds ...gen.Condition) IUserDo {
|
||||
return u.withDO(u.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Order(conds ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Distinct(cols ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (u userDo) Omit(cols ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (u userDo) Join(table schema.Tabler, on ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (u userDo) LeftJoin(table schema.Tabler, on ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (u userDo) RightJoin(table schema.Tabler, on ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (u userDo) Group(cols ...field.Expr) IUserDo {
|
||||
return u.withDO(u.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (u userDo) Having(conds ...gen.Condition) IUserDo {
|
||||
return u.withDO(u.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (u userDo) Limit(limit int) IUserDo {
|
||||
return u.withDO(u.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (u userDo) Offset(offset int) IUserDo {
|
||||
return u.withDO(u.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (u userDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IUserDo {
|
||||
return u.withDO(u.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (u userDo) Unscoped() IUserDo {
|
||||
return u.withDO(u.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (u userDo) Create(values ...*model.User) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return u.DO.Create(values)
|
||||
}
|
||||
|
||||
func (u userDo) CreateInBatches(values []*model.User, batchSize int) error {
|
||||
return u.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 (u userDo) Save(values ...*model.User) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return u.DO.Save(values)
|
||||
}
|
||||
|
||||
func (u userDo) First() (*model.User, error) {
|
||||
if result, err := u.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.User), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userDo) Take() (*model.User, error) {
|
||||
if result, err := u.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.User), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userDo) Last() (*model.User, error) {
|
||||
if result, err := u.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.User), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userDo) Find() ([]*model.User, error) {
|
||||
result, err := u.DO.Find()
|
||||
return result.([]*model.User), err
|
||||
}
|
||||
|
||||
func (u userDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.User, err error) {
|
||||
buf := make([]*model.User, 0, batchSize)
|
||||
err = u.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 (u userDo) FindInBatches(result *[]*model.User, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return u.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (u userDo) Attrs(attrs ...field.AssignExpr) IUserDo {
|
||||
return u.withDO(u.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (u userDo) Assign(attrs ...field.AssignExpr) IUserDo {
|
||||
return u.withDO(u.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (u userDo) Joins(fields ...field.RelationField) IUserDo {
|
||||
for _, _f := range fields {
|
||||
u = *u.withDO(u.DO.Joins(_f))
|
||||
}
|
||||
return &u
|
||||
}
|
||||
|
||||
func (u userDo) Preload(fields ...field.RelationField) IUserDo {
|
||||
for _, _f := range fields {
|
||||
u = *u.withDO(u.DO.Preload(_f))
|
||||
}
|
||||
return &u
|
||||
}
|
||||
|
||||
func (u userDo) FirstOrInit() (*model.User, error) {
|
||||
if result, err := u.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.User), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userDo) FirstOrCreate() (*model.User, error) {
|
||||
if result, err := u.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.User), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (u userDo) FindByPage(offset int, limit int) (result []*model.User, count int64, err error) {
|
||||
result, err = u.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 = u.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (u userDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = u.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = u.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (u userDo) Scan(result interface{}) (err error) {
|
||||
return u.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (u userDo) Delete(models ...*model.User) (result gen.ResultInfo, err error) {
|
||||
return u.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (u *userDo) withDO(do gen.Dao) *userDo {
|
||||
u.DO = *do.(*gen.DO)
|
||||
return u
|
||||
}
|
||||
459
internal/database/query/video.gen.go
Normal file
459
internal/database/query/video.gen.go
Normal file
@@ -0,0 +1,459 @@
|
||||
// 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"
|
||||
"database/sql"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"stream.api/internal/database/model"
|
||||
)
|
||||
|
||||
func newVideo(db *gorm.DB, opts ...gen.DOOption) video {
|
||||
_video := video{}
|
||||
|
||||
_video.videoDo.UseDB(db, opts...)
|
||||
_video.videoDo.UseModel(&model.Video{})
|
||||
|
||||
tableName := _video.videoDo.TableName()
|
||||
_video.ALL = field.NewAsterisk(tableName)
|
||||
_video.ID = field.NewString(tableName, "id")
|
||||
_video.Name = field.NewString(tableName, "name")
|
||||
_video.Title = field.NewString(tableName, "title")
|
||||
_video.Description = field.NewString(tableName, "description")
|
||||
_video.URL = field.NewString(tableName, "url")
|
||||
_video.Thumbnail = field.NewString(tableName, "thumbnail")
|
||||
_video.HlsToken = field.NewString(tableName, "hls_token")
|
||||
_video.HlsPath = field.NewString(tableName, "hls_path")
|
||||
_video.Duration = field.NewInt32(tableName, "duration")
|
||||
_video.Size = field.NewInt64(tableName, "size")
|
||||
_video.StorageType = field.NewString(tableName, "storage_type")
|
||||
_video.Format = field.NewString(tableName, "format")
|
||||
_video.Status = field.NewString(tableName, "status")
|
||||
_video.ProcessingStatus = field.NewString(tableName, "processing_status")
|
||||
_video.Views = field.NewInt32(tableName, "views")
|
||||
_video.UserID = field.NewString(tableName, "user_id")
|
||||
_video.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_video.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
|
||||
_video.fillFieldMap()
|
||||
|
||||
return _video
|
||||
}
|
||||
|
||||
type video struct {
|
||||
videoDo videoDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.String
|
||||
Name field.String
|
||||
Title field.String
|
||||
Description field.String
|
||||
URL field.String
|
||||
Thumbnail field.String
|
||||
HlsToken field.String
|
||||
HlsPath field.String
|
||||
Duration field.Int32
|
||||
Size field.Int64
|
||||
StorageType field.String
|
||||
Format field.String
|
||||
Status field.String
|
||||
ProcessingStatus field.String
|
||||
Views field.Int32
|
||||
UserID field.String
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (v video) Table(newTableName string) *video {
|
||||
v.videoDo.UseTable(newTableName)
|
||||
return v.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (v video) As(alias string) *video {
|
||||
v.videoDo.DO = *(v.videoDo.As(alias).(*gen.DO))
|
||||
return v.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (v *video) updateTableName(table string) *video {
|
||||
v.ALL = field.NewAsterisk(table)
|
||||
v.ID = field.NewString(table, "id")
|
||||
v.Name = field.NewString(table, "name")
|
||||
v.Title = field.NewString(table, "title")
|
||||
v.Description = field.NewString(table, "description")
|
||||
v.URL = field.NewString(table, "url")
|
||||
v.Thumbnail = field.NewString(table, "thumbnail")
|
||||
v.HlsToken = field.NewString(table, "hls_token")
|
||||
v.HlsPath = field.NewString(table, "hls_path")
|
||||
v.Duration = field.NewInt32(table, "duration")
|
||||
v.Size = field.NewInt64(table, "size")
|
||||
v.StorageType = field.NewString(table, "storage_type")
|
||||
v.Format = field.NewString(table, "format")
|
||||
v.Status = field.NewString(table, "status")
|
||||
v.ProcessingStatus = field.NewString(table, "processing_status")
|
||||
v.Views = field.NewInt32(table, "views")
|
||||
v.UserID = field.NewString(table, "user_id")
|
||||
v.CreatedAt = field.NewTime(table, "created_at")
|
||||
v.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
v.fillFieldMap()
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *video) WithContext(ctx context.Context) IVideoDo { return v.videoDo.WithContext(ctx) }
|
||||
|
||||
func (v video) TableName() string { return v.videoDo.TableName() }
|
||||
|
||||
func (v video) Alias() string { return v.videoDo.Alias() }
|
||||
|
||||
func (v video) Columns(cols ...field.Expr) gen.Columns { return v.videoDo.Columns(cols...) }
|
||||
|
||||
func (v *video) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := v.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (v *video) fillFieldMap() {
|
||||
v.fieldMap = make(map[string]field.Expr, 18)
|
||||
v.fieldMap["id"] = v.ID
|
||||
v.fieldMap["name"] = v.Name
|
||||
v.fieldMap["title"] = v.Title
|
||||
v.fieldMap["description"] = v.Description
|
||||
v.fieldMap["url"] = v.URL
|
||||
v.fieldMap["thumbnail"] = v.Thumbnail
|
||||
v.fieldMap["hls_token"] = v.HlsToken
|
||||
v.fieldMap["hls_path"] = v.HlsPath
|
||||
v.fieldMap["duration"] = v.Duration
|
||||
v.fieldMap["size"] = v.Size
|
||||
v.fieldMap["storage_type"] = v.StorageType
|
||||
v.fieldMap["format"] = v.Format
|
||||
v.fieldMap["status"] = v.Status
|
||||
v.fieldMap["processing_status"] = v.ProcessingStatus
|
||||
v.fieldMap["views"] = v.Views
|
||||
v.fieldMap["user_id"] = v.UserID
|
||||
v.fieldMap["created_at"] = v.CreatedAt
|
||||
v.fieldMap["updated_at"] = v.UpdatedAt
|
||||
}
|
||||
|
||||
func (v video) clone(db *gorm.DB) video {
|
||||
v.videoDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return v
|
||||
}
|
||||
|
||||
func (v video) replaceDB(db *gorm.DB) video {
|
||||
v.videoDo.ReplaceDB(db)
|
||||
return v
|
||||
}
|
||||
|
||||
type videoDo struct{ gen.DO }
|
||||
|
||||
type IVideoDo interface {
|
||||
gen.SubQuery
|
||||
Debug() IVideoDo
|
||||
WithContext(ctx context.Context) IVideoDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() IVideoDo
|
||||
WriteDB() IVideoDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) IVideoDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) IVideoDo
|
||||
Not(conds ...gen.Condition) IVideoDo
|
||||
Or(conds ...gen.Condition) IVideoDo
|
||||
Select(conds ...field.Expr) IVideoDo
|
||||
Where(conds ...gen.Condition) IVideoDo
|
||||
Order(conds ...field.Expr) IVideoDo
|
||||
Distinct(cols ...field.Expr) IVideoDo
|
||||
Omit(cols ...field.Expr) IVideoDo
|
||||
Join(table schema.Tabler, on ...field.Expr) IVideoDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) IVideoDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) IVideoDo
|
||||
Group(cols ...field.Expr) IVideoDo
|
||||
Having(conds ...gen.Condition) IVideoDo
|
||||
Limit(limit int) IVideoDo
|
||||
Offset(offset int) IVideoDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) IVideoDo
|
||||
Unscoped() IVideoDo
|
||||
Create(values ...*model.Video) error
|
||||
CreateInBatches(values []*model.Video, batchSize int) error
|
||||
Save(values ...*model.Video) error
|
||||
First() (*model.Video, error)
|
||||
Take() (*model.Video, error)
|
||||
Last() (*model.Video, error)
|
||||
Find() ([]*model.Video, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Video, err error)
|
||||
FindInBatches(result *[]*model.Video, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.Video) (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) IVideoDo
|
||||
Assign(attrs ...field.AssignExpr) IVideoDo
|
||||
Joins(fields ...field.RelationField) IVideoDo
|
||||
Preload(fields ...field.RelationField) IVideoDo
|
||||
FirstOrInit() (*model.Video, error)
|
||||
FirstOrCreate() (*model.Video, error)
|
||||
FindByPage(offset int, limit int) (result []*model.Video, count int64, err error)
|
||||
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||
Rows() (*sql.Rows, error)
|
||||
Row() *sql.Row
|
||||
Scan(result interface{}) (err error)
|
||||
Returning(value interface{}, columns ...string) IVideoDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (v videoDo) Debug() IVideoDo {
|
||||
return v.withDO(v.DO.Debug())
|
||||
}
|
||||
|
||||
func (v videoDo) WithContext(ctx context.Context) IVideoDo {
|
||||
return v.withDO(v.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (v videoDo) ReadDB() IVideoDo {
|
||||
return v.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (v videoDo) WriteDB() IVideoDo {
|
||||
return v.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (v videoDo) Session(config *gorm.Session) IVideoDo {
|
||||
return v.withDO(v.DO.Session(config))
|
||||
}
|
||||
|
||||
func (v videoDo) Clauses(conds ...clause.Expression) IVideoDo {
|
||||
return v.withDO(v.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (v videoDo) Returning(value interface{}, columns ...string) IVideoDo {
|
||||
return v.withDO(v.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (v videoDo) Not(conds ...gen.Condition) IVideoDo {
|
||||
return v.withDO(v.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (v videoDo) Or(conds ...gen.Condition) IVideoDo {
|
||||
return v.withDO(v.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (v videoDo) Select(conds ...field.Expr) IVideoDo {
|
||||
return v.withDO(v.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (v videoDo) Where(conds ...gen.Condition) IVideoDo {
|
||||
return v.withDO(v.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (v videoDo) Order(conds ...field.Expr) IVideoDo {
|
||||
return v.withDO(v.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (v videoDo) Distinct(cols ...field.Expr) IVideoDo {
|
||||
return v.withDO(v.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (v videoDo) Omit(cols ...field.Expr) IVideoDo {
|
||||
return v.withDO(v.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (v videoDo) Join(table schema.Tabler, on ...field.Expr) IVideoDo {
|
||||
return v.withDO(v.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (v videoDo) LeftJoin(table schema.Tabler, on ...field.Expr) IVideoDo {
|
||||
return v.withDO(v.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (v videoDo) RightJoin(table schema.Tabler, on ...field.Expr) IVideoDo {
|
||||
return v.withDO(v.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (v videoDo) Group(cols ...field.Expr) IVideoDo {
|
||||
return v.withDO(v.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (v videoDo) Having(conds ...gen.Condition) IVideoDo {
|
||||
return v.withDO(v.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (v videoDo) Limit(limit int) IVideoDo {
|
||||
return v.withDO(v.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (v videoDo) Offset(offset int) IVideoDo {
|
||||
return v.withDO(v.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (v videoDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IVideoDo {
|
||||
return v.withDO(v.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (v videoDo) Unscoped() IVideoDo {
|
||||
return v.withDO(v.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (v videoDo) Create(values ...*model.Video) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return v.DO.Create(values)
|
||||
}
|
||||
|
||||
func (v videoDo) CreateInBatches(values []*model.Video, batchSize int) error {
|
||||
return v.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 (v videoDo) Save(values ...*model.Video) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return v.DO.Save(values)
|
||||
}
|
||||
|
||||
func (v videoDo) First() (*model.Video, error) {
|
||||
if result, err := v.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Video), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v videoDo) Take() (*model.Video, error) {
|
||||
if result, err := v.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Video), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v videoDo) Last() (*model.Video, error) {
|
||||
if result, err := v.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Video), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v videoDo) Find() ([]*model.Video, error) {
|
||||
result, err := v.DO.Find()
|
||||
return result.([]*model.Video), err
|
||||
}
|
||||
|
||||
func (v videoDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Video, err error) {
|
||||
buf := make([]*model.Video, 0, batchSize)
|
||||
err = v.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 (v videoDo) FindInBatches(result *[]*model.Video, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return v.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (v videoDo) Attrs(attrs ...field.AssignExpr) IVideoDo {
|
||||
return v.withDO(v.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (v videoDo) Assign(attrs ...field.AssignExpr) IVideoDo {
|
||||
return v.withDO(v.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (v videoDo) Joins(fields ...field.RelationField) IVideoDo {
|
||||
for _, _f := range fields {
|
||||
v = *v.withDO(v.DO.Joins(_f))
|
||||
}
|
||||
return &v
|
||||
}
|
||||
|
||||
func (v videoDo) Preload(fields ...field.RelationField) IVideoDo {
|
||||
for _, _f := range fields {
|
||||
v = *v.withDO(v.DO.Preload(_f))
|
||||
}
|
||||
return &v
|
||||
}
|
||||
|
||||
func (v videoDo) FirstOrInit() (*model.Video, error) {
|
||||
if result, err := v.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Video), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v videoDo) FirstOrCreate() (*model.Video, error) {
|
||||
if result, err := v.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Video), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (v videoDo) FindByPage(offset int, limit int) (result []*model.Video, count int64, err error) {
|
||||
result, err = v.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 = v.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (v videoDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = v.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = v.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (v videoDo) Scan(result interface{}) (err error) {
|
||||
return v.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (v videoDo) Delete(models ...*model.Video) (result gen.ResultInfo, err error) {
|
||||
return v.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (v *videoDo) withDO(do gen.Dao) *videoDo {
|
||||
v.DO = *do.(*gen.DO)
|
||||
return v
|
||||
}
|
||||
Reference in New Issue
Block a user