Regenerate
This commit is contained in:
parent
115a167e75
commit
91ff8d2ea1
9 changed files with 193 additions and 14 deletions
|
@ -255,6 +255,11 @@ func newNoteTag(db *gorm.DB, opts ...gen.DOOption) noteTag {
|
|||
},
|
||||
},
|
||||
},
|
||||
Origin: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Note.Origin", "models.RemoteServer"),
|
||||
},
|
||||
AttachmentRelations: struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
@ -497,6 +502,9 @@ type noteTagBelongsToNote struct {
|
|||
}
|
||||
}
|
||||
}
|
||||
Origin struct {
|
||||
field.RelationField
|
||||
}
|
||||
AttachmentRelations struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
|
|
@ -255,6 +255,11 @@ func newNoteToAttachment(db *gorm.DB, opts ...gen.DOOption) noteToAttachment {
|
|||
},
|
||||
},
|
||||
},
|
||||
Origin: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Note.Origin", "models.RemoteServer"),
|
||||
},
|
||||
AttachmentRelations: struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
@ -505,6 +510,9 @@ type noteToAttachmentBelongsToNote struct {
|
|||
}
|
||||
}
|
||||
}
|
||||
Origin struct {
|
||||
field.RelationField
|
||||
}
|
||||
AttachmentRelations struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
|
|
@ -193,6 +193,11 @@ func newNoteToBoost(db *gorm.DB, opts ...gen.DOOption) noteToBoost {
|
|||
}{
|
||||
RelationField: field.NewRelation("Note.Creator", "models.User"),
|
||||
},
|
||||
Origin: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Note.Origin", "models.RemoteServer"),
|
||||
},
|
||||
AttachmentRelations: struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
@ -512,6 +517,9 @@ type noteToBoostBelongsToNote struct {
|
|||
Creator struct {
|
||||
field.RelationField
|
||||
}
|
||||
Origin struct {
|
||||
field.RelationField
|
||||
}
|
||||
AttachmentRelations struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
|
|
@ -255,6 +255,11 @@ func newNoteToEmote(db *gorm.DB, opts ...gen.DOOption) noteToEmote {
|
|||
},
|
||||
},
|
||||
},
|
||||
Origin: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Note.Origin", "models.RemoteServer"),
|
||||
},
|
||||
AttachmentRelations: struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
@ -505,6 +510,9 @@ type noteToEmoteBelongsToNote struct {
|
|||
}
|
||||
}
|
||||
}
|
||||
Origin struct {
|
||||
field.RelationField
|
||||
}
|
||||
AttachmentRelations struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
|
|
@ -255,6 +255,11 @@ func newNoteToFeed(db *gorm.DB, opts ...gen.DOOption) noteToFeed {
|
|||
},
|
||||
},
|
||||
},
|
||||
Origin: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Note.Origin", "models.RemoteServer"),
|
||||
},
|
||||
AttachmentRelations: struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
@ -497,6 +502,9 @@ type noteToFeedBelongsToNote struct {
|
|||
}
|
||||
}
|
||||
}
|
||||
Origin struct {
|
||||
field.RelationField
|
||||
}
|
||||
AttachmentRelations struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
|
|
@ -255,6 +255,11 @@ func newNoteToPing(db *gorm.DB, opts ...gen.DOOption) noteToPing {
|
|||
},
|
||||
},
|
||||
},
|
||||
Origin: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Note.Origin", "models.RemoteServer"),
|
||||
},
|
||||
AttachmentRelations: struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
@ -505,6 +510,9 @@ type noteToPingBelongsToNote struct {
|
|||
}
|
||||
}
|
||||
}
|
||||
Origin struct {
|
||||
field.RelationField
|
||||
}
|
||||
AttachmentRelations struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
|
|
@ -6,6 +6,7 @@ package dbgen
|
|||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||
"gorm.io/gorm"
|
||||
|
@ -33,11 +34,11 @@ func newNote(db *gorm.DB, opts ...gen.DOOption) note {
|
|||
_note.CreatorId = field.NewString(tableName, "creator_id")
|
||||
_note.Remote = field.NewBool(tableName, "remote")
|
||||
_note.RawContent = field.NewString(tableName, "raw_content")
|
||||
_note.ContentWarning = field.NewString(tableName, "content_warning")
|
||||
_note.RepliesTo = field.NewString(tableName, "replies_to")
|
||||
_note.Quotes = field.NewString(tableName, "quotes")
|
||||
_note.ContentWarning = field.NewField(tableName, "content_warning")
|
||||
_note.RepliesTo = field.NewField(tableName, "replies_to")
|
||||
_note.Quotes = field.NewField(tableName, "quotes")
|
||||
_note.AccessLevel = field.NewField(tableName, "access_level")
|
||||
_note.OriginServer = field.NewString(tableName, "origin_server")
|
||||
_note.OriginId = field.NewUint(tableName, "origin_id")
|
||||
_note.AttachmentRelations = noteHasManyAttachmentRelations{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
|
@ -116,6 +117,9 @@ func newNote(db *gorm.DB, opts ...gen.DOOption) note {
|
|||
}
|
||||
}
|
||||
}
|
||||
Origin struct {
|
||||
field.RelationField
|
||||
}
|
||||
AttachmentRelations struct {
|
||||
field.RelationField
|
||||
}
|
||||
|
@ -373,6 +377,11 @@ func newNote(db *gorm.DB, opts ...gen.DOOption) note {
|
|||
},
|
||||
},
|
||||
},
|
||||
Origin: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("AttachmentRelations.Note.Origin", "models.RemoteServer"),
|
||||
},
|
||||
AttachmentRelations: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
|
@ -487,6 +496,12 @@ func newNote(db *gorm.DB, opts ...gen.DOOption) note {
|
|||
RelationField: field.NewRelation("Creator", "models.User"),
|
||||
}
|
||||
|
||||
_note.Origin = noteBelongsToOrigin{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Origin", "models.RemoteServer"),
|
||||
}
|
||||
|
||||
_note.fillFieldMap()
|
||||
|
||||
return _note
|
||||
|
@ -503,11 +518,11 @@ type note struct {
|
|||
CreatorId field.String
|
||||
Remote field.Bool
|
||||
RawContent field.String
|
||||
ContentWarning field.String
|
||||
RepliesTo field.String
|
||||
Quotes field.String
|
||||
ContentWarning field.Field
|
||||
RepliesTo field.Field
|
||||
Quotes field.Field
|
||||
AccessLevel field.Field
|
||||
OriginServer field.String
|
||||
OriginId field.Uint
|
||||
AttachmentRelations noteHasManyAttachmentRelations
|
||||
|
||||
EmoteRelations noteHasManyEmoteRelations
|
||||
|
@ -518,6 +533,8 @@ type note struct {
|
|||
|
||||
Creator noteBelongsToCreator
|
||||
|
||||
Origin noteBelongsToOrigin
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
|
@ -540,11 +557,11 @@ func (n *note) updateTableName(table string) *note {
|
|||
n.CreatorId = field.NewString(table, "creator_id")
|
||||
n.Remote = field.NewBool(table, "remote")
|
||||
n.RawContent = field.NewString(table, "raw_content")
|
||||
n.ContentWarning = field.NewString(table, "content_warning")
|
||||
n.RepliesTo = field.NewString(table, "replies_to")
|
||||
n.Quotes = field.NewString(table, "quotes")
|
||||
n.ContentWarning = field.NewField(table, "content_warning")
|
||||
n.RepliesTo = field.NewField(table, "replies_to")
|
||||
n.Quotes = field.NewField(table, "quotes")
|
||||
n.AccessLevel = field.NewField(table, "access_level")
|
||||
n.OriginServer = field.NewString(table, "origin_server")
|
||||
n.OriginId = field.NewUint(table, "origin_id")
|
||||
|
||||
n.fillFieldMap()
|
||||
|
||||
|
@ -561,7 +578,7 @@ func (n *note) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|||
}
|
||||
|
||||
func (n *note) fillFieldMap() {
|
||||
n.fieldMap = make(map[string]field.Expr, 17)
|
||||
n.fieldMap = make(map[string]field.Expr, 18)
|
||||
n.fieldMap["id"] = n.ID
|
||||
n.fieldMap["created_at"] = n.CreatedAt
|
||||
n.fieldMap["updated_at"] = n.UpdatedAt
|
||||
|
@ -573,7 +590,7 @@ func (n *note) fillFieldMap() {
|
|||
n.fieldMap["replies_to"] = n.RepliesTo
|
||||
n.fieldMap["quotes"] = n.Quotes
|
||||
n.fieldMap["access_level"] = n.AccessLevel
|
||||
n.fieldMap["origin_server"] = n.OriginServer
|
||||
n.fieldMap["origin_id"] = n.OriginId
|
||||
|
||||
}
|
||||
|
||||
|
@ -666,6 +683,9 @@ type noteHasManyAttachmentRelations struct {
|
|||
}
|
||||
}
|
||||
}
|
||||
Origin struct {
|
||||
field.RelationField
|
||||
}
|
||||
AttachmentRelations struct {
|
||||
field.RelationField
|
||||
}
|
||||
|
@ -1054,6 +1074,77 @@ func (a noteBelongsToCreatorTx) Count() int64 {
|
|||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type noteBelongsToOrigin struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a noteBelongsToOrigin) Where(conds ...field.Expr) *noteBelongsToOrigin {
|
||||
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 noteBelongsToOrigin) WithContext(ctx context.Context) *noteBelongsToOrigin {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a noteBelongsToOrigin) Session(session *gorm.Session) *noteBelongsToOrigin {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a noteBelongsToOrigin) Model(m *models.Note) *noteBelongsToOriginTx {
|
||||
return ¬eBelongsToOriginTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type noteBelongsToOriginTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a noteBelongsToOriginTx) Find() (result *models.RemoteServer, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a noteBelongsToOriginTx) Append(values ...*models.RemoteServer) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a noteBelongsToOriginTx) Replace(values ...*models.RemoteServer) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a noteBelongsToOriginTx) Delete(values ...*models.RemoteServer) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a noteBelongsToOriginTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a noteBelongsToOriginTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type noteDo struct{ gen.DO }
|
||||
|
||||
type INoteDo interface {
|
||||
|
@ -1115,6 +1206,30 @@ type INoteDo interface {
|
|||
Returning(value interface{}, columns ...string) INoteDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
|
||||
GetNotesPaged(userId string, pageNr uint, accessLevel uint8) (result []models.Note, err error)
|
||||
}
|
||||
|
||||
// Get all notes by a user, paged, that are a specific access level.
|
||||
// Ordered by age, descending (newest first)
|
||||
//
|
||||
// SELECT * FROM @@table
|
||||
// WHERE creator_id = @userId AND access_level = @accessLevel
|
||||
// ORDER BY created_at DESC LIMIT 50 OFFSET @pageNr * 50
|
||||
func (n noteDo) GetNotesPaged(userId string, pageNr uint, accessLevel uint8) (result []models.Note, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, userId)
|
||||
params = append(params, accessLevel)
|
||||
params = append(params, pageNr)
|
||||
generateSQL.WriteString("SELECT * FROM notes WHERE creator_id = ? AND access_level = ? ORDER BY created_at DESC LIMIT 50 OFFSET ? * 50 ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = n.UnderlyingDB().Raw(generateSQL.String(), params...).Find(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (n noteDo) Debug() INoteDo {
|
||||
|
|
|
@ -199,6 +199,11 @@ func newNotification(db *gorm.DB, opts ...gen.DOOption) notification {
|
|||
}{
|
||||
RelationField: field.NewRelation("SourceNote.Creator", "models.User"),
|
||||
},
|
||||
Origin: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("SourceNote.Origin", "models.RemoteServer"),
|
||||
},
|
||||
AttachmentRelations: struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
@ -541,6 +546,9 @@ type notificationBelongsToSourceNote struct {
|
|||
Creator struct {
|
||||
field.RelationField
|
||||
}
|
||||
Origin struct {
|
||||
field.RelationField
|
||||
}
|
||||
AttachmentRelations struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
|
|
@ -259,6 +259,11 @@ func newReaction(db *gorm.DB, opts ...gen.DOOption) reaction {
|
|||
},
|
||||
},
|
||||
},
|
||||
Origin: struct {
|
||||
field.RelationField
|
||||
}{
|
||||
RelationField: field.NewRelation("Note.Origin", "models.RemoteServer"),
|
||||
},
|
||||
AttachmentRelations: struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
@ -529,6 +534,9 @@ type reactionBelongsToNote struct {
|
|||
}
|
||||
}
|
||||
}
|
||||
Origin struct {
|
||||
field.RelationField
|
||||
}
|
||||
AttachmentRelations struct {
|
||||
field.RelationField
|
||||
Note struct {
|
||||
|
|
Loading…
Reference in a new issue