Commit: Bulk unfinished work
This commit is contained in:
@@ -33,6 +33,7 @@ var (
|
||||
Rechnung *rechnung
|
||||
Rechnungsposition *rechnungsposition
|
||||
Scanobject *scanobject
|
||||
Task *task
|
||||
User *user
|
||||
Zahlung *zahlung
|
||||
)
|
||||
@@ -55,6 +56,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
Rechnung = &Q.Rechnung
|
||||
Rechnungsposition = &Q.Rechnungsposition
|
||||
Scanobject = &Q.Scanobject
|
||||
Task = &Q.Task
|
||||
User = &Q.User
|
||||
Zahlung = &Q.Zahlung
|
||||
}
|
||||
@@ -78,6 +80,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
Rechnung: newRechnung(db, opts...),
|
||||
Rechnungsposition: newRechnungsposition(db, opts...),
|
||||
Scanobject: newScanobject(db, opts...),
|
||||
Task: newTask(db, opts...),
|
||||
User: newUser(db, opts...),
|
||||
Zahlung: newZahlung(db, opts...),
|
||||
}
|
||||
@@ -102,6 +105,7 @@ type Query struct {
|
||||
Rechnung rechnung
|
||||
Rechnungsposition rechnungsposition
|
||||
Scanobject scanobject
|
||||
Task task
|
||||
User user
|
||||
Zahlung zahlung
|
||||
}
|
||||
@@ -127,6 +131,7 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
Rechnung: q.Rechnung.clone(db),
|
||||
Rechnungsposition: q.Rechnungsposition.clone(db),
|
||||
Scanobject: q.Scanobject.clone(db),
|
||||
Task: q.Task.clone(db),
|
||||
User: q.User.clone(db),
|
||||
Zahlung: q.Zahlung.clone(db),
|
||||
}
|
||||
@@ -159,6 +164,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
Rechnung: q.Rechnung.replaceDB(db),
|
||||
Rechnungsposition: q.Rechnungsposition.replaceDB(db),
|
||||
Scanobject: q.Scanobject.replaceDB(db),
|
||||
Task: q.Task.replaceDB(db),
|
||||
User: q.User.replaceDB(db),
|
||||
Zahlung: q.Zahlung.replaceDB(db),
|
||||
}
|
||||
@@ -181,6 +187,7 @@ type queryCtx struct {
|
||||
Rechnung IRechnungDo
|
||||
Rechnungsposition IRechnungspositionDo
|
||||
Scanobject IScanobjectDo
|
||||
Task ITaskDo
|
||||
User IUserDo
|
||||
Zahlung IZahlungDo
|
||||
}
|
||||
@@ -203,6 +210,7 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
Rechnung: q.Rechnung.WithContext(ctx),
|
||||
Rechnungsposition: q.Rechnungsposition.WithContext(ctx),
|
||||
Scanobject: q.Scanobject.WithContext(ctx),
|
||||
Task: q.Task.WithContext(ctx),
|
||||
User: q.User.WithContext(ctx),
|
||||
Zahlung: q.Zahlung.WithContext(ctx),
|
||||
}
|
||||
|
||||
607
query/tasks.gen.go
Normal file
607
query/tasks.gen.go
Normal file
@@ -0,0 +1,607 @@
|
||||
// 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"
|
||||
|
||||
"git.kocoder.xyz/kocoded/vt/model"
|
||||
)
|
||||
|
||||
func newTask(db *gorm.DB, opts ...gen.DOOption) task {
|
||||
_task := task{}
|
||||
|
||||
_task.taskDo.UseDB(db, opts...)
|
||||
_task.taskDo.UseModel(&model.Task{})
|
||||
|
||||
tableName := _task.taskDo.TableName()
|
||||
_task.ALL = field.NewAsterisk(tableName)
|
||||
_task.ID = field.NewUint(tableName, "id")
|
||||
_task.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_task.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_task.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_task.ProjektID = field.NewUint(tableName, "projekt_id")
|
||||
_task.MandantID = field.NewUint(tableName, "mandant_id")
|
||||
_task.Titel = field.NewString(tableName, "titel")
|
||||
_task.Description = field.NewString(tableName, "description")
|
||||
_task.Status = field.NewInt(tableName, "status")
|
||||
_task.Projekt = taskBelongsToProjekt{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Projekt", "model.Projekt"),
|
||||
Mandant: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Projekt.Mandant", "model.Mandant"),
|
||||
},
|
||||
}
|
||||
|
||||
_task.Mandant = taskBelongsToMandant{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Mandant", "model.Mandant"),
|
||||
}
|
||||
|
||||
_task.fillFieldMap()
|
||||
|
||||
return _task
|
||||
}
|
||||
|
||||
type task struct {
|
||||
taskDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
ProjektID field.Uint
|
||||
MandantID field.Uint
|
||||
Titel field.String
|
||||
Description field.String
|
||||
Status field.Int
|
||||
Projekt taskBelongsToProjekt
|
||||
|
||||
Mandant taskBelongsToMandant
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (t task) Table(newTableName string) *task {
|
||||
t.taskDo.UseTable(newTableName)
|
||||
return t.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (t task) As(alias string) *task {
|
||||
t.taskDo.DO = *(t.taskDo.As(alias).(*gen.DO))
|
||||
return t.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (t *task) updateTableName(table string) *task {
|
||||
t.ALL = field.NewAsterisk(table)
|
||||
t.ID = field.NewUint(table, "id")
|
||||
t.CreatedAt = field.NewTime(table, "created_at")
|
||||
t.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
t.DeletedAt = field.NewField(table, "deleted_at")
|
||||
t.ProjektID = field.NewUint(table, "projekt_id")
|
||||
t.MandantID = field.NewUint(table, "mandant_id")
|
||||
t.Titel = field.NewString(table, "titel")
|
||||
t.Description = field.NewString(table, "description")
|
||||
t.Status = field.NewInt(table, "status")
|
||||
|
||||
t.fillFieldMap()
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *task) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := t.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (t *task) fillFieldMap() {
|
||||
t.fieldMap = make(map[string]field.Expr, 11)
|
||||
t.fieldMap["id"] = t.ID
|
||||
t.fieldMap["created_at"] = t.CreatedAt
|
||||
t.fieldMap["updated_at"] = t.UpdatedAt
|
||||
t.fieldMap["deleted_at"] = t.DeletedAt
|
||||
t.fieldMap["projekt_id"] = t.ProjektID
|
||||
t.fieldMap["mandant_id"] = t.MandantID
|
||||
t.fieldMap["titel"] = t.Titel
|
||||
t.fieldMap["description"] = t.Description
|
||||
t.fieldMap["status"] = t.Status
|
||||
|
||||
}
|
||||
|
||||
func (t task) clone(db *gorm.DB) task {
|
||||
t.taskDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
t.Projekt.db = db.Session(&gorm.Session{Initialized: true})
|
||||
t.Projekt.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
t.Mandant.db = db.Session(&gorm.Session{Initialized: true})
|
||||
t.Mandant.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return t
|
||||
}
|
||||
|
||||
func (t task) replaceDB(db *gorm.DB) task {
|
||||
t.taskDo.ReplaceDB(db)
|
||||
t.Projekt.db = db.Session(&gorm.Session{})
|
||||
t.Mandant.db = db.Session(&gorm.Session{})
|
||||
return t
|
||||
}
|
||||
|
||||
type taskBelongsToProjekt struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
|
||||
Mandant struct {
|
||||
field.RelationField
|
||||
}
|
||||
}
|
||||
|
||||
func (a taskBelongsToProjekt) Where(conds ...field.Expr) *taskBelongsToProjekt {
|
||||
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 taskBelongsToProjekt) WithContext(ctx context.Context) *taskBelongsToProjekt {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a taskBelongsToProjekt) Session(session *gorm.Session) *taskBelongsToProjekt {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a taskBelongsToProjekt) Model(m *model.Task) *taskBelongsToProjektTx {
|
||||
return &taskBelongsToProjektTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a taskBelongsToProjekt) Unscoped() *taskBelongsToProjekt {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type taskBelongsToProjektTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a taskBelongsToProjektTx) Find() (result *model.Projekt, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a taskBelongsToProjektTx) Append(values ...*model.Projekt) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a taskBelongsToProjektTx) Replace(values ...*model.Projekt) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a taskBelongsToProjektTx) Delete(values ...*model.Projekt) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a taskBelongsToProjektTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a taskBelongsToProjektTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a taskBelongsToProjektTx) Unscoped() *taskBelongsToProjektTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type taskBelongsToMandant struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a taskBelongsToMandant) Where(conds ...field.Expr) *taskBelongsToMandant {
|
||||
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 taskBelongsToMandant) WithContext(ctx context.Context) *taskBelongsToMandant {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a taskBelongsToMandant) Session(session *gorm.Session) *taskBelongsToMandant {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a taskBelongsToMandant) Model(m *model.Task) *taskBelongsToMandantTx {
|
||||
return &taskBelongsToMandantTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a taskBelongsToMandant) Unscoped() *taskBelongsToMandant {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type taskBelongsToMandantTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a taskBelongsToMandantTx) Find() (result *model.Mandant, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a taskBelongsToMandantTx) Append(values ...*model.Mandant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a taskBelongsToMandantTx) Replace(values ...*model.Mandant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a taskBelongsToMandantTx) Delete(values ...*model.Mandant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a taskBelongsToMandantTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a taskBelongsToMandantTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a taskBelongsToMandantTx) Unscoped() *taskBelongsToMandantTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type taskDo struct{ gen.DO }
|
||||
|
||||
type ITaskDo interface {
|
||||
gen.SubQuery
|
||||
Debug() ITaskDo
|
||||
WithContext(ctx context.Context) ITaskDo
|
||||
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||
ReplaceDB(db *gorm.DB)
|
||||
ReadDB() ITaskDo
|
||||
WriteDB() ITaskDo
|
||||
As(alias string) gen.Dao
|
||||
Session(config *gorm.Session) ITaskDo
|
||||
Columns(cols ...field.Expr) gen.Columns
|
||||
Clauses(conds ...clause.Expression) ITaskDo
|
||||
Not(conds ...gen.Condition) ITaskDo
|
||||
Or(conds ...gen.Condition) ITaskDo
|
||||
Select(conds ...field.Expr) ITaskDo
|
||||
Where(conds ...gen.Condition) ITaskDo
|
||||
Order(conds ...field.Expr) ITaskDo
|
||||
Distinct(cols ...field.Expr) ITaskDo
|
||||
Omit(cols ...field.Expr) ITaskDo
|
||||
Join(table schema.Tabler, on ...field.Expr) ITaskDo
|
||||
LeftJoin(table schema.Tabler, on ...field.Expr) ITaskDo
|
||||
RightJoin(table schema.Tabler, on ...field.Expr) ITaskDo
|
||||
Group(cols ...field.Expr) ITaskDo
|
||||
Having(conds ...gen.Condition) ITaskDo
|
||||
Limit(limit int) ITaskDo
|
||||
Offset(offset int) ITaskDo
|
||||
Count() (count int64, err error)
|
||||
Scopes(funcs ...func(gen.Dao) gen.Dao) ITaskDo
|
||||
Unscoped() ITaskDo
|
||||
Create(values ...*model.Task) error
|
||||
CreateInBatches(values []*model.Task, batchSize int) error
|
||||
Save(values ...*model.Task) error
|
||||
First() (*model.Task, error)
|
||||
Take() (*model.Task, error)
|
||||
Last() (*model.Task, error)
|
||||
Find() ([]*model.Task, error)
|
||||
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Task, err error)
|
||||
FindInBatches(result *[]*model.Task, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||
Pluck(column field.Expr, dest interface{}) error
|
||||
Delete(...*model.Task) (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) ITaskDo
|
||||
Assign(attrs ...field.AssignExpr) ITaskDo
|
||||
Joins(fields ...field.RelationField) ITaskDo
|
||||
Preload(fields ...field.RelationField) ITaskDo
|
||||
FirstOrInit() (*model.Task, error)
|
||||
FirstOrCreate() (*model.Task, error)
|
||||
FindByPage(offset int, limit int) (result []*model.Task, 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) ITaskDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
}
|
||||
|
||||
func (t taskDo) Debug() ITaskDo {
|
||||
return t.withDO(t.DO.Debug())
|
||||
}
|
||||
|
||||
func (t taskDo) WithContext(ctx context.Context) ITaskDo {
|
||||
return t.withDO(t.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (t taskDo) ReadDB() ITaskDo {
|
||||
return t.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (t taskDo) WriteDB() ITaskDo {
|
||||
return t.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (t taskDo) Session(config *gorm.Session) ITaskDo {
|
||||
return t.withDO(t.DO.Session(config))
|
||||
}
|
||||
|
||||
func (t taskDo) Clauses(conds ...clause.Expression) ITaskDo {
|
||||
return t.withDO(t.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (t taskDo) Returning(value interface{}, columns ...string) ITaskDo {
|
||||
return t.withDO(t.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (t taskDo) Not(conds ...gen.Condition) ITaskDo {
|
||||
return t.withDO(t.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (t taskDo) Or(conds ...gen.Condition) ITaskDo {
|
||||
return t.withDO(t.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (t taskDo) Select(conds ...field.Expr) ITaskDo {
|
||||
return t.withDO(t.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (t taskDo) Where(conds ...gen.Condition) ITaskDo {
|
||||
return t.withDO(t.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (t taskDo) Order(conds ...field.Expr) ITaskDo {
|
||||
return t.withDO(t.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (t taskDo) Distinct(cols ...field.Expr) ITaskDo {
|
||||
return t.withDO(t.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (t taskDo) Omit(cols ...field.Expr) ITaskDo {
|
||||
return t.withDO(t.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (t taskDo) Join(table schema.Tabler, on ...field.Expr) ITaskDo {
|
||||
return t.withDO(t.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (t taskDo) LeftJoin(table schema.Tabler, on ...field.Expr) ITaskDo {
|
||||
return t.withDO(t.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t taskDo) RightJoin(table schema.Tabler, on ...field.Expr) ITaskDo {
|
||||
return t.withDO(t.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t taskDo) Group(cols ...field.Expr) ITaskDo {
|
||||
return t.withDO(t.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (t taskDo) Having(conds ...gen.Condition) ITaskDo {
|
||||
return t.withDO(t.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (t taskDo) Limit(limit int) ITaskDo {
|
||||
return t.withDO(t.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (t taskDo) Offset(offset int) ITaskDo {
|
||||
return t.withDO(t.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (t taskDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ITaskDo {
|
||||
return t.withDO(t.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (t taskDo) Unscoped() ITaskDo {
|
||||
return t.withDO(t.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (t taskDo) Create(values ...*model.Task) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Create(values)
|
||||
}
|
||||
|
||||
func (t taskDo) CreateInBatches(values []*model.Task, batchSize int) error {
|
||||
return t.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 (t taskDo) Save(values ...*model.Task) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Save(values)
|
||||
}
|
||||
|
||||
func (t taskDo) First() (*model.Task, error) {
|
||||
if result, err := t.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Task), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t taskDo) Take() (*model.Task, error) {
|
||||
if result, err := t.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Task), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t taskDo) Last() (*model.Task, error) {
|
||||
if result, err := t.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Task), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t taskDo) Find() ([]*model.Task, error) {
|
||||
result, err := t.DO.Find()
|
||||
return result.([]*model.Task), err
|
||||
}
|
||||
|
||||
func (t taskDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Task, err error) {
|
||||
buf := make([]*model.Task, 0, batchSize)
|
||||
err = t.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 (t taskDo) FindInBatches(result *[]*model.Task, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return t.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (t taskDo) Attrs(attrs ...field.AssignExpr) ITaskDo {
|
||||
return t.withDO(t.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (t taskDo) Assign(attrs ...field.AssignExpr) ITaskDo {
|
||||
return t.withDO(t.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (t taskDo) Joins(fields ...field.RelationField) ITaskDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Joins(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t taskDo) Preload(fields ...field.RelationField) ITaskDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Preload(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t taskDo) FirstOrInit() (*model.Task, error) {
|
||||
if result, err := t.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Task), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t taskDo) FirstOrCreate() (*model.Task, error) {
|
||||
if result, err := t.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.Task), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t taskDo) FindByPage(offset int, limit int) (result []*model.Task, count int64, err error) {
|
||||
result, err = t.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 = t.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (t taskDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = t.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = t.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (t taskDo) Scan(result interface{}) (err error) {
|
||||
return t.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (t taskDo) Delete(models ...*model.Task) (result gen.ResultInfo, err error) {
|
||||
return t.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (t *taskDo) withDO(do gen.Dao) *taskDo {
|
||||
t.DO = *do.(*gen.DO)
|
||||
return t
|
||||
}
|
||||
Reference in New Issue
Block a user