1103 lines
29 KiB
Go
1103 lines
29 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"
|
|
"strings"
|
|
|
|
"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 newNotification(db *gorm.DB, opts ...gen.DOOption) notification {
|
|
_notification := notification{}
|
|
|
|
_notification.notificationDo.UseDB(db, opts...)
|
|
_notification.notificationDo.UseModel(&models.Notification{})
|
|
|
|
tableName := _notification.notificationDo.TableName()
|
|
_notification.ALL = field.NewAsterisk(tableName)
|
|
_notification.ID = field.NewUint(tableName, "id")
|
|
_notification.CreatedAt = field.NewTime(tableName, "created_at")
|
|
_notification.UpdatedAt = field.NewTime(tableName, "updated_at")
|
|
_notification.DeletedAt = field.NewField(tableName, "deleted_at")
|
|
_notification.ForUserId = field.NewString(tableName, "for_user_id")
|
|
_notification.SourceNoteId = field.NewField(tableName, "source_note_id")
|
|
_notification.SourceUserId = field.NewField(tableName, "source_user_id")
|
|
_notification.Cause = field.NewField(tableName, "cause")
|
|
_notification.ViewedState = field.NewField(tableName, "viewed_state")
|
|
_notification.ForUser = notificationBelongsToForUser{
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
RelationField: field.NewRelation("ForUser", "models.User"),
|
|
Server: struct {
|
|
field.RelationField
|
|
Icon struct {
|
|
field.RelationField
|
|
}
|
|
Metadata struct {
|
|
field.RelationField
|
|
RemoteServer struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Server", "models.RemoteServer"),
|
|
Icon: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Server.Icon", "models.MediaMetadata"),
|
|
},
|
|
Metadata: struct {
|
|
field.RelationField
|
|
RemoteServer struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Server.Metadata", "models.RemoteServerMetadata"),
|
|
RemoteServer: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Server.Metadata.RemoteServer", "models.RemoteServer"),
|
|
},
|
|
},
|
|
},
|
|
Icon: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Icon", "models.MediaMetadata"),
|
|
},
|
|
Background: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Background", "models.MediaMetadata"),
|
|
},
|
|
Banner: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Banner", "models.MediaMetadata"),
|
|
},
|
|
RemoteInfo: struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.RemoteInfo", "models.UserRemoteLinks"),
|
|
User: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.RemoteInfo.User", "models.User"),
|
|
},
|
|
},
|
|
InfoFields: struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.InfoFields", "models.UserInfoField"),
|
|
User: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.InfoFields.User", "models.User"),
|
|
},
|
|
},
|
|
BeingTypes: struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.BeingTypes", "models.UserToBeing"),
|
|
User: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.BeingTypes.User", "models.User"),
|
|
},
|
|
},
|
|
Tags: struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Tags", "models.UserToTag"),
|
|
User: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Tags.User", "models.User"),
|
|
},
|
|
},
|
|
Relations: struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
TargetUser struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Relations", "models.UserToUserRelation"),
|
|
User: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Relations.User", "models.User"),
|
|
},
|
|
TargetUser: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Relations.TargetUser", "models.User"),
|
|
},
|
|
},
|
|
Pronouns: struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Pronouns", "models.UserToPronoun"),
|
|
User: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Pronouns.User", "models.User"),
|
|
},
|
|
},
|
|
Roles: struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
Role struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Roles", "models.UserToRole"),
|
|
User: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Roles.User", "models.User"),
|
|
},
|
|
Role: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.Roles.Role", "models.Role"),
|
|
},
|
|
},
|
|
AuthMethods: struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.AuthMethods", "models.UserAuthMethod"),
|
|
User: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("ForUser.AuthMethods.User", "models.User"),
|
|
},
|
|
},
|
|
}
|
|
|
|
_notification.SourceNote = notificationBelongsToSourceNote{
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
RelationField: field.NewRelation("SourceNote", "models.Note"),
|
|
Creator: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.Creator", "models.User"),
|
|
},
|
|
Origin: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.Origin", "models.RemoteServer"),
|
|
},
|
|
AttachmentRelations: struct {
|
|
field.RelationField
|
|
Note struct {
|
|
field.RelationField
|
|
}
|
|
Attachment struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.AttachmentRelations", "models.NoteToAttachment"),
|
|
Note: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.AttachmentRelations.Note", "models.Note"),
|
|
},
|
|
Attachment: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.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("SourceNote.EmoteRelations", "models.NoteToEmote"),
|
|
Note: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.EmoteRelations.Note", "models.Note"),
|
|
},
|
|
Emote: struct {
|
|
field.RelationField
|
|
Metadata struct {
|
|
field.RelationField
|
|
}
|
|
Server struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.EmoteRelations.Emote", "models.Emote"),
|
|
Metadata: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.EmoteRelations.Emote.Metadata", "models.MediaMetadata"),
|
|
},
|
|
Server: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.EmoteRelations.Emote.Server", "models.RemoteServer"),
|
|
},
|
|
},
|
|
},
|
|
PingRelations: struct {
|
|
field.RelationField
|
|
Note struct {
|
|
field.RelationField
|
|
}
|
|
PingTarget struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.PingRelations", "models.NoteToPing"),
|
|
Note: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.PingRelations.Note", "models.Note"),
|
|
},
|
|
PingTarget: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.PingRelations.PingTarget", "models.User"),
|
|
},
|
|
},
|
|
Tags: struct {
|
|
field.RelationField
|
|
Note struct {
|
|
field.RelationField
|
|
}
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.Tags", "models.NoteTag"),
|
|
Note: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("SourceNote.Tags.Note", "models.Note"),
|
|
},
|
|
},
|
|
}
|
|
|
|
_notification.SourceUser = notificationBelongsToSourceUser{
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
RelationField: field.NewRelation("SourceUser", "models.User"),
|
|
}
|
|
|
|
_notification.fillFieldMap()
|
|
|
|
return _notification
|
|
}
|
|
|
|
type notification struct {
|
|
notificationDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Uint
|
|
CreatedAt field.Time
|
|
UpdatedAt field.Time
|
|
DeletedAt field.Field
|
|
ForUserId field.String
|
|
SourceNoteId field.Field
|
|
SourceUserId field.Field
|
|
Cause field.Field
|
|
ViewedState field.Field
|
|
ForUser notificationBelongsToForUser
|
|
|
|
SourceNote notificationBelongsToSourceNote
|
|
|
|
SourceUser notificationBelongsToSourceUser
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (n notification) Table(newTableName string) *notification {
|
|
n.notificationDo.UseTable(newTableName)
|
|
return n.updateTableName(newTableName)
|
|
}
|
|
|
|
func (n notification) As(alias string) *notification {
|
|
n.notificationDo.DO = *(n.notificationDo.As(alias).(*gen.DO))
|
|
return n.updateTableName(alias)
|
|
}
|
|
|
|
func (n *notification) updateTableName(table string) *notification {
|
|
n.ALL = field.NewAsterisk(table)
|
|
n.ID = field.NewUint(table, "id")
|
|
n.CreatedAt = field.NewTime(table, "created_at")
|
|
n.UpdatedAt = field.NewTime(table, "updated_at")
|
|
n.DeletedAt = field.NewField(table, "deleted_at")
|
|
n.ForUserId = field.NewString(table, "for_user_id")
|
|
n.SourceNoteId = field.NewField(table, "source_note_id")
|
|
n.SourceUserId = field.NewField(table, "source_user_id")
|
|
n.Cause = field.NewField(table, "cause")
|
|
n.ViewedState = field.NewField(table, "viewed_state")
|
|
|
|
n.fillFieldMap()
|
|
|
|
return n
|
|
}
|
|
|
|
func (n *notification) 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 *notification) fillFieldMap() {
|
|
n.fieldMap = make(map[string]field.Expr, 12)
|
|
n.fieldMap["id"] = n.ID
|
|
n.fieldMap["created_at"] = n.CreatedAt
|
|
n.fieldMap["updated_at"] = n.UpdatedAt
|
|
n.fieldMap["deleted_at"] = n.DeletedAt
|
|
n.fieldMap["for_user_id"] = n.ForUserId
|
|
n.fieldMap["source_note_id"] = n.SourceNoteId
|
|
n.fieldMap["source_user_id"] = n.SourceUserId
|
|
n.fieldMap["cause"] = n.Cause
|
|
n.fieldMap["viewed_state"] = n.ViewedState
|
|
|
|
}
|
|
|
|
func (n notification) clone(db *gorm.DB) notification {
|
|
n.notificationDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
return n
|
|
}
|
|
|
|
func (n notification) replaceDB(db *gorm.DB) notification {
|
|
n.notificationDo.ReplaceDB(db)
|
|
return n
|
|
}
|
|
|
|
type notificationBelongsToForUser struct {
|
|
db *gorm.DB
|
|
|
|
field.RelationField
|
|
|
|
Server struct {
|
|
field.RelationField
|
|
Icon struct {
|
|
field.RelationField
|
|
}
|
|
Metadata struct {
|
|
field.RelationField
|
|
RemoteServer struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
}
|
|
Icon struct {
|
|
field.RelationField
|
|
}
|
|
Background struct {
|
|
field.RelationField
|
|
}
|
|
Banner struct {
|
|
field.RelationField
|
|
}
|
|
RemoteInfo struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
InfoFields struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
BeingTypes struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
Tags struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
Relations struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
TargetUser struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
Pronouns struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
Roles struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
Role struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
AuthMethods struct {
|
|
field.RelationField
|
|
User struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
}
|
|
|
|
func (a notificationBelongsToForUser) Where(conds ...field.Expr) *notificationBelongsToForUser {
|
|
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 notificationBelongsToForUser) WithContext(ctx context.Context) *notificationBelongsToForUser {
|
|
a.db = a.db.WithContext(ctx)
|
|
return &a
|
|
}
|
|
|
|
func (a notificationBelongsToForUser) Session(session *gorm.Session) *notificationBelongsToForUser {
|
|
a.db = a.db.Session(session)
|
|
return &a
|
|
}
|
|
|
|
func (a notificationBelongsToForUser) Model(m *models.Notification) *notificationBelongsToForUserTx {
|
|
return ¬ificationBelongsToForUserTx{a.db.Model(m).Association(a.Name())}
|
|
}
|
|
|
|
type notificationBelongsToForUserTx struct{ tx *gorm.Association }
|
|
|
|
func (a notificationBelongsToForUserTx) Find() (result *models.User, err error) {
|
|
return result, a.tx.Find(&result)
|
|
}
|
|
|
|
func (a notificationBelongsToForUserTx) Append(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Append(targetValues...)
|
|
}
|
|
|
|
func (a notificationBelongsToForUserTx) Replace(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Replace(targetValues...)
|
|
}
|
|
|
|
func (a notificationBelongsToForUserTx) Delete(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Delete(targetValues...)
|
|
}
|
|
|
|
func (a notificationBelongsToForUserTx) Clear() error {
|
|
return a.tx.Clear()
|
|
}
|
|
|
|
func (a notificationBelongsToForUserTx) Count() int64 {
|
|
return a.tx.Count()
|
|
}
|
|
|
|
type notificationBelongsToSourceNote struct {
|
|
db *gorm.DB
|
|
|
|
field.RelationField
|
|
|
|
Creator struct {
|
|
field.RelationField
|
|
}
|
|
Origin struct {
|
|
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 notificationBelongsToSourceNote) Where(conds ...field.Expr) *notificationBelongsToSourceNote {
|
|
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 notificationBelongsToSourceNote) WithContext(ctx context.Context) *notificationBelongsToSourceNote {
|
|
a.db = a.db.WithContext(ctx)
|
|
return &a
|
|
}
|
|
|
|
func (a notificationBelongsToSourceNote) Session(session *gorm.Session) *notificationBelongsToSourceNote {
|
|
a.db = a.db.Session(session)
|
|
return &a
|
|
}
|
|
|
|
func (a notificationBelongsToSourceNote) Model(m *models.Notification) *notificationBelongsToSourceNoteTx {
|
|
return ¬ificationBelongsToSourceNoteTx{a.db.Model(m).Association(a.Name())}
|
|
}
|
|
|
|
type notificationBelongsToSourceNoteTx struct{ tx *gorm.Association }
|
|
|
|
func (a notificationBelongsToSourceNoteTx) Find() (result *models.Note, err error) {
|
|
return result, a.tx.Find(&result)
|
|
}
|
|
|
|
func (a notificationBelongsToSourceNoteTx) 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 notificationBelongsToSourceNoteTx) 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 notificationBelongsToSourceNoteTx) 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 notificationBelongsToSourceNoteTx) Clear() error {
|
|
return a.tx.Clear()
|
|
}
|
|
|
|
func (a notificationBelongsToSourceNoteTx) Count() int64 {
|
|
return a.tx.Count()
|
|
}
|
|
|
|
type notificationBelongsToSourceUser struct {
|
|
db *gorm.DB
|
|
|
|
field.RelationField
|
|
}
|
|
|
|
func (a notificationBelongsToSourceUser) Where(conds ...field.Expr) *notificationBelongsToSourceUser {
|
|
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 notificationBelongsToSourceUser) WithContext(ctx context.Context) *notificationBelongsToSourceUser {
|
|
a.db = a.db.WithContext(ctx)
|
|
return &a
|
|
}
|
|
|
|
func (a notificationBelongsToSourceUser) Session(session *gorm.Session) *notificationBelongsToSourceUser {
|
|
a.db = a.db.Session(session)
|
|
return &a
|
|
}
|
|
|
|
func (a notificationBelongsToSourceUser) Model(m *models.Notification) *notificationBelongsToSourceUserTx {
|
|
return ¬ificationBelongsToSourceUserTx{a.db.Model(m).Association(a.Name())}
|
|
}
|
|
|
|
type notificationBelongsToSourceUserTx struct{ tx *gorm.Association }
|
|
|
|
func (a notificationBelongsToSourceUserTx) Find() (result *models.User, err error) {
|
|
return result, a.tx.Find(&result)
|
|
}
|
|
|
|
func (a notificationBelongsToSourceUserTx) Append(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Append(targetValues...)
|
|
}
|
|
|
|
func (a notificationBelongsToSourceUserTx) Replace(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Replace(targetValues...)
|
|
}
|
|
|
|
func (a notificationBelongsToSourceUserTx) Delete(values ...*models.User) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Delete(targetValues...)
|
|
}
|
|
|
|
func (a notificationBelongsToSourceUserTx) Clear() error {
|
|
return a.tx.Clear()
|
|
}
|
|
|
|
func (a notificationBelongsToSourceUserTx) Count() int64 {
|
|
return a.tx.Count()
|
|
}
|
|
|
|
type notificationDo struct{ gen.DO }
|
|
|
|
type INotificationDo interface {
|
|
gen.SubQuery
|
|
Debug() INotificationDo
|
|
WithContext(ctx context.Context) INotificationDo
|
|
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
|
ReplaceDB(db *gorm.DB)
|
|
ReadDB() INotificationDo
|
|
WriteDB() INotificationDo
|
|
As(alias string) gen.Dao
|
|
Session(config *gorm.Session) INotificationDo
|
|
Columns(cols ...field.Expr) gen.Columns
|
|
Clauses(conds ...clause.Expression) INotificationDo
|
|
Not(conds ...gen.Condition) INotificationDo
|
|
Or(conds ...gen.Condition) INotificationDo
|
|
Select(conds ...field.Expr) INotificationDo
|
|
Where(conds ...gen.Condition) INotificationDo
|
|
Order(conds ...field.Expr) INotificationDo
|
|
Distinct(cols ...field.Expr) INotificationDo
|
|
Omit(cols ...field.Expr) INotificationDo
|
|
Join(table schema.Tabler, on ...field.Expr) INotificationDo
|
|
LeftJoin(table schema.Tabler, on ...field.Expr) INotificationDo
|
|
RightJoin(table schema.Tabler, on ...field.Expr) INotificationDo
|
|
Group(cols ...field.Expr) INotificationDo
|
|
Having(conds ...gen.Condition) INotificationDo
|
|
Limit(limit int) INotificationDo
|
|
Offset(offset int) INotificationDo
|
|
Count() (count int64, err error)
|
|
Scopes(funcs ...func(gen.Dao) gen.Dao) INotificationDo
|
|
Unscoped() INotificationDo
|
|
Create(values ...*models.Notification) error
|
|
CreateInBatches(values []*models.Notification, batchSize int) error
|
|
Save(values ...*models.Notification) error
|
|
First() (*models.Notification, error)
|
|
Take() (*models.Notification, error)
|
|
Last() (*models.Notification, error)
|
|
Find() ([]*models.Notification, error)
|
|
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Notification, err error)
|
|
FindInBatches(result *[]*models.Notification, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
|
Pluck(column field.Expr, dest interface{}) error
|
|
Delete(...*models.Notification) (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) INotificationDo
|
|
Assign(attrs ...field.AssignExpr) INotificationDo
|
|
Joins(fields ...field.RelationField) INotificationDo
|
|
Preload(fields ...field.RelationField) INotificationDo
|
|
FirstOrInit() (*models.Notification, error)
|
|
FirstOrCreate() (*models.Notification, error)
|
|
FindByPage(offset int, limit int) (result []*models.Notification, 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) INotificationDo
|
|
UnderlyingDB() *gorm.DB
|
|
schema.Tabler
|
|
|
|
SetState(state uint8, ids []uint) (err error)
|
|
GetLatestWithOffset(userId string, count uint, offset uint) (result []models.Notification, err error)
|
|
}
|
|
|
|
// Update a given set of notifications to a given viewed state.
|
|
// State should be a [NotificationViewedStateType]
|
|
//
|
|
// UPDATE @@table SET viewed_state = @state WHERE id IN @ids
|
|
func (n notificationDo) SetState(state uint8, ids []uint) (err error) {
|
|
var params []interface{}
|
|
|
|
var generateSQL strings.Builder
|
|
params = append(params, state)
|
|
params = append(params, ids)
|
|
generateSQL.WriteString("UPDATE notifications SET viewed_state = ? WHERE id IN ? ")
|
|
|
|
var executeSQL *gorm.DB
|
|
executeSQL = n.UnderlyingDB().Exec(generateSQL.String(), params...) // ignore_security_alert
|
|
err = executeSQL.Error
|
|
|
|
return
|
|
}
|
|
|
|
// Get the lastest count amount of notifications with a given offset for a user
|
|
//
|
|
// SELECT * FROM @@table WHERE for_user_id = @userId
|
|
// ORDER BY id DESC
|
|
// {{if count > 0 }}
|
|
//
|
|
// LIMIT @count
|
|
//
|
|
// {{else}}
|
|
//
|
|
// LIMIT 20
|
|
//
|
|
// {{end}}
|
|
// OFFSET @offset
|
|
func (n notificationDo) GetLatestWithOffset(userId string, count uint, offset uint) (result []models.Notification, err error) {
|
|
var params []interface{}
|
|
|
|
var generateSQL strings.Builder
|
|
params = append(params, userId)
|
|
generateSQL.WriteString("SELECT * FROM notifications WHERE for_user_id = ? ORDER BY id DESC ")
|
|
if count > 0 {
|
|
params = append(params, count)
|
|
generateSQL.WriteString("LIMIT ? ")
|
|
} else {
|
|
generateSQL.WriteString("LIMIT 20 ")
|
|
}
|
|
params = append(params, offset)
|
|
generateSQL.WriteString("OFFSET ? ")
|
|
|
|
var executeSQL *gorm.DB
|
|
executeSQL = n.UnderlyingDB().Raw(generateSQL.String(), params...).Find(&result) // ignore_security_alert
|
|
err = executeSQL.Error
|
|
|
|
return
|
|
}
|
|
|
|
func (n notificationDo) Debug() INotificationDo {
|
|
return n.withDO(n.DO.Debug())
|
|
}
|
|
|
|
func (n notificationDo) WithContext(ctx context.Context) INotificationDo {
|
|
return n.withDO(n.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (n notificationDo) ReadDB() INotificationDo {
|
|
return n.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (n notificationDo) WriteDB() INotificationDo {
|
|
return n.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (n notificationDo) Session(config *gorm.Session) INotificationDo {
|
|
return n.withDO(n.DO.Session(config))
|
|
}
|
|
|
|
func (n notificationDo) Clauses(conds ...clause.Expression) INotificationDo {
|
|
return n.withDO(n.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (n notificationDo) Returning(value interface{}, columns ...string) INotificationDo {
|
|
return n.withDO(n.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (n notificationDo) Not(conds ...gen.Condition) INotificationDo {
|
|
return n.withDO(n.DO.Not(conds...))
|
|
}
|
|
|
|
func (n notificationDo) Or(conds ...gen.Condition) INotificationDo {
|
|
return n.withDO(n.DO.Or(conds...))
|
|
}
|
|
|
|
func (n notificationDo) Select(conds ...field.Expr) INotificationDo {
|
|
return n.withDO(n.DO.Select(conds...))
|
|
}
|
|
|
|
func (n notificationDo) Where(conds ...gen.Condition) INotificationDo {
|
|
return n.withDO(n.DO.Where(conds...))
|
|
}
|
|
|
|
func (n notificationDo) Order(conds ...field.Expr) INotificationDo {
|
|
return n.withDO(n.DO.Order(conds...))
|
|
}
|
|
|
|
func (n notificationDo) Distinct(cols ...field.Expr) INotificationDo {
|
|
return n.withDO(n.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (n notificationDo) Omit(cols ...field.Expr) INotificationDo {
|
|
return n.withDO(n.DO.Omit(cols...))
|
|
}
|
|
|
|
func (n notificationDo) Join(table schema.Tabler, on ...field.Expr) INotificationDo {
|
|
return n.withDO(n.DO.Join(table, on...))
|
|
}
|
|
|
|
func (n notificationDo) LeftJoin(table schema.Tabler, on ...field.Expr) INotificationDo {
|
|
return n.withDO(n.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (n notificationDo) RightJoin(table schema.Tabler, on ...field.Expr) INotificationDo {
|
|
return n.withDO(n.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (n notificationDo) Group(cols ...field.Expr) INotificationDo {
|
|
return n.withDO(n.DO.Group(cols...))
|
|
}
|
|
|
|
func (n notificationDo) Having(conds ...gen.Condition) INotificationDo {
|
|
return n.withDO(n.DO.Having(conds...))
|
|
}
|
|
|
|
func (n notificationDo) Limit(limit int) INotificationDo {
|
|
return n.withDO(n.DO.Limit(limit))
|
|
}
|
|
|
|
func (n notificationDo) Offset(offset int) INotificationDo {
|
|
return n.withDO(n.DO.Offset(offset))
|
|
}
|
|
|
|
func (n notificationDo) Scopes(funcs ...func(gen.Dao) gen.Dao) INotificationDo {
|
|
return n.withDO(n.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (n notificationDo) Unscoped() INotificationDo {
|
|
return n.withDO(n.DO.Unscoped())
|
|
}
|
|
|
|
func (n notificationDo) Create(values ...*models.Notification) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return n.DO.Create(values)
|
|
}
|
|
|
|
func (n notificationDo) CreateInBatches(values []*models.Notification, 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 notificationDo) Save(values ...*models.Notification) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return n.DO.Save(values)
|
|
}
|
|
|
|
func (n notificationDo) First() (*models.Notification, error) {
|
|
if result, err := n.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Notification), nil
|
|
}
|
|
}
|
|
|
|
func (n notificationDo) Take() (*models.Notification, error) {
|
|
if result, err := n.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Notification), nil
|
|
}
|
|
}
|
|
|
|
func (n notificationDo) Last() (*models.Notification, error) {
|
|
if result, err := n.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Notification), nil
|
|
}
|
|
}
|
|
|
|
func (n notificationDo) Find() ([]*models.Notification, error) {
|
|
result, err := n.DO.Find()
|
|
return result.([]*models.Notification), err
|
|
}
|
|
|
|
func (n notificationDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Notification, err error) {
|
|
buf := make([]*models.Notification, 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 notificationDo) FindInBatches(result *[]*models.Notification, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return n.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (n notificationDo) Attrs(attrs ...field.AssignExpr) INotificationDo {
|
|
return n.withDO(n.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (n notificationDo) Assign(attrs ...field.AssignExpr) INotificationDo {
|
|
return n.withDO(n.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (n notificationDo) Joins(fields ...field.RelationField) INotificationDo {
|
|
for _, _f := range fields {
|
|
n = *n.withDO(n.DO.Joins(_f))
|
|
}
|
|
return &n
|
|
}
|
|
|
|
func (n notificationDo) Preload(fields ...field.RelationField) INotificationDo {
|
|
for _, _f := range fields {
|
|
n = *n.withDO(n.DO.Preload(_f))
|
|
}
|
|
return &n
|
|
}
|
|
|
|
func (n notificationDo) FirstOrInit() (*models.Notification, error) {
|
|
if result, err := n.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Notification), nil
|
|
}
|
|
}
|
|
|
|
func (n notificationDo) FirstOrCreate() (*models.Notification, error) {
|
|
if result, err := n.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Notification), nil
|
|
}
|
|
}
|
|
|
|
func (n notificationDo) FindByPage(offset int, limit int) (result []*models.Notification, 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 notificationDo) 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 notificationDo) Scan(result interface{}) (err error) {
|
|
return n.DO.Scan(result)
|
|
}
|
|
|
|
func (n notificationDo) Delete(models ...*models.Notification) (result gen.ResultInfo, err error) {
|
|
return n.DO.Delete(models)
|
|
}
|
|
|
|
func (n *notificationDo) withDO(do gen.Dao) *notificationDo {
|
|
n.DO = *do.(*gen.DO)
|
|
return n
|
|
}
|