linstrom/storage-new/dbgen/note_to_attachments.gen.go
mstar 68859642f3
Some checks are pending
/ test (push) Waiting to run
chore(new-storage): Auto-generate new storage impl
2025-03-27 15:57:00 +01:00

678 lines
19 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 dbgen
import (
"context"
"git.mstar.dev/mstar/linstrom/storage-new/models"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
)
func newNoteToAttachment(db *gorm.DB, opts ...gen.DOOption) noteToAttachment {
_noteToAttachment := noteToAttachment{}
_noteToAttachment.noteToAttachmentDo.UseDB(db, opts...)
_noteToAttachment.noteToAttachmentDo.UseModel(&models.NoteToAttachment{})
tableName := _noteToAttachment.noteToAttachmentDo.TableName()
_noteToAttachment.ALL = field.NewAsterisk(tableName)
_noteToAttachment.NoteId = field.NewString(tableName, "note_id")
_noteToAttachment.AttachmentId = field.NewString(tableName, "attachment_id")
_noteToAttachment.Note = noteToAttachmentBelongsToNote{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("Note", "models.Note"),
AttachmentRelations: struct {
field.RelationField
Note struct {
field.RelationField
}
Attachment struct {
field.RelationField
}
}{
RelationField: field.NewRelation("Note.AttachmentRelations", "models.NoteToAttachment"),
Note: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.AttachmentRelations.Note", "models.Note"),
},
Attachment: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.AttachmentRelations.Attachment", "models.MediaMetadata"),
},
},
EmoteRelations: struct {
field.RelationField
Note struct {
field.RelationField
}
Emote struct {
field.RelationField
Metadata struct {
field.RelationField
}
Server struct {
field.RelationField
}
}
}{
RelationField: field.NewRelation("Note.EmoteRelations", "models.NoteToEmote"),
Note: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.EmoteRelations.Note", "models.Note"),
},
Emote: struct {
field.RelationField
Metadata struct {
field.RelationField
}
Server struct {
field.RelationField
}
}{
RelationField: field.NewRelation("Note.EmoteRelations.Emote", "models.Emote"),
Metadata: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Metadata", "models.MediaMetadata"),
},
Server: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"),
},
},
},
PingRelations: struct {
field.RelationField
Note struct {
field.RelationField
}
PingTarget struct {
field.RelationField
}
}{
RelationField: field.NewRelation("Note.PingRelations", "models.NoteToPing"),
Note: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.PingRelations.Note", "models.Note"),
},
PingTarget: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.PingRelations.PingTarget", "models.User"),
},
},
Tags: struct {
field.RelationField
Note struct {
field.RelationField
}
}{
RelationField: field.NewRelation("Note.Tags", "models.NoteTag"),
Note: struct {
field.RelationField
}{
RelationField: field.NewRelation("Note.Tags.Note", "models.Note"),
},
},
}
_noteToAttachment.Attachment = noteToAttachmentBelongsToAttachment{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("Attachment", "models.MediaMetadata"),
}
_noteToAttachment.fillFieldMap()
return _noteToAttachment
}
type noteToAttachment struct {
noteToAttachmentDo
ALL field.Asterisk
NoteId field.String
AttachmentId field.String
Note noteToAttachmentBelongsToNote
Attachment noteToAttachmentBelongsToAttachment
fieldMap map[string]field.Expr
}
func (n noteToAttachment) Table(newTableName string) *noteToAttachment {
n.noteToAttachmentDo.UseTable(newTableName)
return n.updateTableName(newTableName)
}
func (n noteToAttachment) As(alias string) *noteToAttachment {
n.noteToAttachmentDo.DO = *(n.noteToAttachmentDo.As(alias).(*gen.DO))
return n.updateTableName(alias)
}
func (n *noteToAttachment) updateTableName(table string) *noteToAttachment {
n.ALL = field.NewAsterisk(table)
n.NoteId = field.NewString(table, "note_id")
n.AttachmentId = field.NewString(table, "attachment_id")
n.fillFieldMap()
return n
}
func (n *noteToAttachment) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := n.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (n *noteToAttachment) fillFieldMap() {
n.fieldMap = make(map[string]field.Expr, 4)
n.fieldMap["note_id"] = n.NoteId
n.fieldMap["attachment_id"] = n.AttachmentId
}
func (n noteToAttachment) clone(db *gorm.DB) noteToAttachment {
n.noteToAttachmentDo.ReplaceConnPool(db.Statement.ConnPool)
return n
}
func (n noteToAttachment) replaceDB(db *gorm.DB) noteToAttachment {
n.noteToAttachmentDo.ReplaceDB(db)
return n
}
type noteToAttachmentBelongsToNote struct {
db *gorm.DB
field.RelationField
AttachmentRelations struct {
field.RelationField
Note struct {
field.RelationField
}
Attachment struct {
field.RelationField
}
}
EmoteRelations struct {
field.RelationField
Note struct {
field.RelationField
}
Emote struct {
field.RelationField
Metadata struct {
field.RelationField
}
Server struct {
field.RelationField
}
}
}
PingRelations struct {
field.RelationField
Note struct {
field.RelationField
}
PingTarget struct {
field.RelationField
}
}
Tags struct {
field.RelationField
Note struct {
field.RelationField
}
}
}
func (a noteToAttachmentBelongsToNote) Where(conds ...field.Expr) *noteToAttachmentBelongsToNote {
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 noteToAttachmentBelongsToNote) WithContext(ctx context.Context) *noteToAttachmentBelongsToNote {
a.db = a.db.WithContext(ctx)
return &a
}
func (a noteToAttachmentBelongsToNote) Session(session *gorm.Session) *noteToAttachmentBelongsToNote {
a.db = a.db.Session(session)
return &a
}
func (a noteToAttachmentBelongsToNote) Model(m *models.NoteToAttachment) *noteToAttachmentBelongsToNoteTx {
return &noteToAttachmentBelongsToNoteTx{a.db.Model(m).Association(a.Name())}
}
type noteToAttachmentBelongsToNoteTx struct{ tx *gorm.Association }
func (a noteToAttachmentBelongsToNoteTx) Find() (result *models.Note, err error) {
return result, a.tx.Find(&result)
}
func (a noteToAttachmentBelongsToNoteTx) Append(values ...*models.Note) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a noteToAttachmentBelongsToNoteTx) Replace(values ...*models.Note) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a noteToAttachmentBelongsToNoteTx) Delete(values ...*models.Note) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a noteToAttachmentBelongsToNoteTx) Clear() error {
return a.tx.Clear()
}
func (a noteToAttachmentBelongsToNoteTx) Count() int64 {
return a.tx.Count()
}
type noteToAttachmentBelongsToAttachment struct {
db *gorm.DB
field.RelationField
}
func (a noteToAttachmentBelongsToAttachment) Where(conds ...field.Expr) *noteToAttachmentBelongsToAttachment {
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 noteToAttachmentBelongsToAttachment) WithContext(ctx context.Context) *noteToAttachmentBelongsToAttachment {
a.db = a.db.WithContext(ctx)
return &a
}
func (a noteToAttachmentBelongsToAttachment) Session(session *gorm.Session) *noteToAttachmentBelongsToAttachment {
a.db = a.db.Session(session)
return &a
}
func (a noteToAttachmentBelongsToAttachment) Model(m *models.NoteToAttachment) *noteToAttachmentBelongsToAttachmentTx {
return &noteToAttachmentBelongsToAttachmentTx{a.db.Model(m).Association(a.Name())}
}
type noteToAttachmentBelongsToAttachmentTx struct{ tx *gorm.Association }
func (a noteToAttachmentBelongsToAttachmentTx) Find() (result *models.MediaMetadata, err error) {
return result, a.tx.Find(&result)
}
func (a noteToAttachmentBelongsToAttachmentTx) Append(values ...*models.MediaMetadata) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a noteToAttachmentBelongsToAttachmentTx) Replace(values ...*models.MediaMetadata) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a noteToAttachmentBelongsToAttachmentTx) Delete(values ...*models.MediaMetadata) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a noteToAttachmentBelongsToAttachmentTx) Clear() error {
return a.tx.Clear()
}
func (a noteToAttachmentBelongsToAttachmentTx) Count() int64 {
return a.tx.Count()
}
type noteToAttachmentDo struct{ gen.DO }
type INoteToAttachmentDo interface {
gen.SubQuery
Debug() INoteToAttachmentDo
WithContext(ctx context.Context) INoteToAttachmentDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() INoteToAttachmentDo
WriteDB() INoteToAttachmentDo
As(alias string) gen.Dao
Session(config *gorm.Session) INoteToAttachmentDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) INoteToAttachmentDo
Not(conds ...gen.Condition) INoteToAttachmentDo
Or(conds ...gen.Condition) INoteToAttachmentDo
Select(conds ...field.Expr) INoteToAttachmentDo
Where(conds ...gen.Condition) INoteToAttachmentDo
Order(conds ...field.Expr) INoteToAttachmentDo
Distinct(cols ...field.Expr) INoteToAttachmentDo
Omit(cols ...field.Expr) INoteToAttachmentDo
Join(table schema.Tabler, on ...field.Expr) INoteToAttachmentDo
LeftJoin(table schema.Tabler, on ...field.Expr) INoteToAttachmentDo
RightJoin(table schema.Tabler, on ...field.Expr) INoteToAttachmentDo
Group(cols ...field.Expr) INoteToAttachmentDo
Having(conds ...gen.Condition) INoteToAttachmentDo
Limit(limit int) INoteToAttachmentDo
Offset(offset int) INoteToAttachmentDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) INoteToAttachmentDo
Unscoped() INoteToAttachmentDo
Create(values ...*models.NoteToAttachment) error
CreateInBatches(values []*models.NoteToAttachment, batchSize int) error
Save(values ...*models.NoteToAttachment) error
First() (*models.NoteToAttachment, error)
Take() (*models.NoteToAttachment, error)
Last() (*models.NoteToAttachment, error)
Find() ([]*models.NoteToAttachment, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.NoteToAttachment, err error)
FindInBatches(result *[]*models.NoteToAttachment, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.NoteToAttachment) (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) INoteToAttachmentDo
Assign(attrs ...field.AssignExpr) INoteToAttachmentDo
Joins(fields ...field.RelationField) INoteToAttachmentDo
Preload(fields ...field.RelationField) INoteToAttachmentDo
FirstOrInit() (*models.NoteToAttachment, error)
FirstOrCreate() (*models.NoteToAttachment, error)
FindByPage(offset int, limit int) (result []*models.NoteToAttachment, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) INoteToAttachmentDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (n noteToAttachmentDo) Debug() INoteToAttachmentDo {
return n.withDO(n.DO.Debug())
}
func (n noteToAttachmentDo) WithContext(ctx context.Context) INoteToAttachmentDo {
return n.withDO(n.DO.WithContext(ctx))
}
func (n noteToAttachmentDo) ReadDB() INoteToAttachmentDo {
return n.Clauses(dbresolver.Read)
}
func (n noteToAttachmentDo) WriteDB() INoteToAttachmentDo {
return n.Clauses(dbresolver.Write)
}
func (n noteToAttachmentDo) Session(config *gorm.Session) INoteToAttachmentDo {
return n.withDO(n.DO.Session(config))
}
func (n noteToAttachmentDo) Clauses(conds ...clause.Expression) INoteToAttachmentDo {
return n.withDO(n.DO.Clauses(conds...))
}
func (n noteToAttachmentDo) Returning(value interface{}, columns ...string) INoteToAttachmentDo {
return n.withDO(n.DO.Returning(value, columns...))
}
func (n noteToAttachmentDo) Not(conds ...gen.Condition) INoteToAttachmentDo {
return n.withDO(n.DO.Not(conds...))
}
func (n noteToAttachmentDo) Or(conds ...gen.Condition) INoteToAttachmentDo {
return n.withDO(n.DO.Or(conds...))
}
func (n noteToAttachmentDo) Select(conds ...field.Expr) INoteToAttachmentDo {
return n.withDO(n.DO.Select(conds...))
}
func (n noteToAttachmentDo) Where(conds ...gen.Condition) INoteToAttachmentDo {
return n.withDO(n.DO.Where(conds...))
}
func (n noteToAttachmentDo) Order(conds ...field.Expr) INoteToAttachmentDo {
return n.withDO(n.DO.Order(conds...))
}
func (n noteToAttachmentDo) Distinct(cols ...field.Expr) INoteToAttachmentDo {
return n.withDO(n.DO.Distinct(cols...))
}
func (n noteToAttachmentDo) Omit(cols ...field.Expr) INoteToAttachmentDo {
return n.withDO(n.DO.Omit(cols...))
}
func (n noteToAttachmentDo) Join(table schema.Tabler, on ...field.Expr) INoteToAttachmentDo {
return n.withDO(n.DO.Join(table, on...))
}
func (n noteToAttachmentDo) LeftJoin(table schema.Tabler, on ...field.Expr) INoteToAttachmentDo {
return n.withDO(n.DO.LeftJoin(table, on...))
}
func (n noteToAttachmentDo) RightJoin(table schema.Tabler, on ...field.Expr) INoteToAttachmentDo {
return n.withDO(n.DO.RightJoin(table, on...))
}
func (n noteToAttachmentDo) Group(cols ...field.Expr) INoteToAttachmentDo {
return n.withDO(n.DO.Group(cols...))
}
func (n noteToAttachmentDo) Having(conds ...gen.Condition) INoteToAttachmentDo {
return n.withDO(n.DO.Having(conds...))
}
func (n noteToAttachmentDo) Limit(limit int) INoteToAttachmentDo {
return n.withDO(n.DO.Limit(limit))
}
func (n noteToAttachmentDo) Offset(offset int) INoteToAttachmentDo {
return n.withDO(n.DO.Offset(offset))
}
func (n noteToAttachmentDo) Scopes(funcs ...func(gen.Dao) gen.Dao) INoteToAttachmentDo {
return n.withDO(n.DO.Scopes(funcs...))
}
func (n noteToAttachmentDo) Unscoped() INoteToAttachmentDo {
return n.withDO(n.DO.Unscoped())
}
func (n noteToAttachmentDo) Create(values ...*models.NoteToAttachment) error {
if len(values) == 0 {
return nil
}
return n.DO.Create(values)
}
func (n noteToAttachmentDo) CreateInBatches(values []*models.NoteToAttachment, batchSize int) error {
return n.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 (n noteToAttachmentDo) Save(values ...*models.NoteToAttachment) error {
if len(values) == 0 {
return nil
}
return n.DO.Save(values)
}
func (n noteToAttachmentDo) First() (*models.NoteToAttachment, error) {
if result, err := n.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.NoteToAttachment), nil
}
}
func (n noteToAttachmentDo) Take() (*models.NoteToAttachment, error) {
if result, err := n.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.NoteToAttachment), nil
}
}
func (n noteToAttachmentDo) Last() (*models.NoteToAttachment, error) {
if result, err := n.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.NoteToAttachment), nil
}
}
func (n noteToAttachmentDo) Find() ([]*models.NoteToAttachment, error) {
result, err := n.DO.Find()
return result.([]*models.NoteToAttachment), err
}
func (n noteToAttachmentDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.NoteToAttachment, err error) {
buf := make([]*models.NoteToAttachment, 0, batchSize)
err = n.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 (n noteToAttachmentDo) FindInBatches(result *[]*models.NoteToAttachment, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return n.DO.FindInBatches(result, batchSize, fc)
}
func (n noteToAttachmentDo) Attrs(attrs ...field.AssignExpr) INoteToAttachmentDo {
return n.withDO(n.DO.Attrs(attrs...))
}
func (n noteToAttachmentDo) Assign(attrs ...field.AssignExpr) INoteToAttachmentDo {
return n.withDO(n.DO.Assign(attrs...))
}
func (n noteToAttachmentDo) Joins(fields ...field.RelationField) INoteToAttachmentDo {
for _, _f := range fields {
n = *n.withDO(n.DO.Joins(_f))
}
return &n
}
func (n noteToAttachmentDo) Preload(fields ...field.RelationField) INoteToAttachmentDo {
for _, _f := range fields {
n = *n.withDO(n.DO.Preload(_f))
}
return &n
}
func (n noteToAttachmentDo) FirstOrInit() (*models.NoteToAttachment, error) {
if result, err := n.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.NoteToAttachment), nil
}
}
func (n noteToAttachmentDo) FirstOrCreate() (*models.NoteToAttachment, error) {
if result, err := n.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.NoteToAttachment), nil
}
}
func (n noteToAttachmentDo) FindByPage(offset int, limit int) (result []*models.NoteToAttachment, count int64, err error) {
result, err = n.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 = n.Offset(-1).Limit(-1).Count()
return
}
func (n noteToAttachmentDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = n.Count()
if err != nil {
return
}
err = n.Offset(offset).Limit(limit).Scan(result)
return
}
func (n noteToAttachmentDo) Scan(result interface{}) (err error) {
return n.DO.Scan(result)
}
func (n noteToAttachmentDo) Delete(models ...*models.NoteToAttachment) (result gen.ResultInfo, err error) {
return n.DO.Delete(models)
}
func (n *noteToAttachmentDo) withDO(do gen.Dao) *noteToAttachmentDo {
n.DO = *do.(*gen.DO)
return n
}