Merge branch 'main' of git.mstar.dev:mstar/linstrom
Some checks are pending
/ test (push) Waiting to run
Some checks are pending
/ test (push) Waiting to run
This commit is contained in:
commit
9cca79ec4c
25 changed files with 3882 additions and 55 deletions
29
auth-new/accessTokens.go
Normal file
29
auth-new/accessTokens.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.mstar.dev/mstar/goutils/other"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||||
|
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Check whether a given access token is valid (exists and hasn't expired).
|
||||||
|
// If it is, returns the user it belongs to
|
||||||
|
func (a *Authenticator) IsValidAccessToken(token string) (*models.User, error) {
|
||||||
|
dbToken, err := dbgen.AccessToken.GetTokenIfValid(token)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
if dbToken.ExpiresAt.Before(time.Now()) {
|
||||||
|
return nil, ErrTokenExpired
|
||||||
|
} else {
|
||||||
|
return &dbToken.User, nil
|
||||||
|
}
|
||||||
|
case gorm.ErrRecordNotFound:
|
||||||
|
return nil, ErrTokenNotFound
|
||||||
|
default:
|
||||||
|
return nil, other.Error("auth", "failed to check for token", err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,10 @@ var (
|
||||||
ErrInvalidPasskeyRegistrationData = errors.New(
|
ErrInvalidPasskeyRegistrationData = errors.New(
|
||||||
"stored passkey registration data was formatted badly",
|
"stored passkey registration data was formatted badly",
|
||||||
)
|
)
|
||||||
|
// The given token has expired
|
||||||
|
ErrTokenExpired = errors.New("token expired")
|
||||||
|
// The given token doesn't exist
|
||||||
|
ErrTokenNotFound = errors.New("token not found")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Helper error type to combine two errors into one
|
// Helper error type to combine two errors into one
|
||||||
|
|
|
@ -177,7 +177,7 @@ func oneStorageAuthToLoginState(in models.AuthenticationMethodType) LoginNextSta
|
||||||
//
|
//
|
||||||
// TODO: Decide whether to include the reason for disallowed login
|
// TODO: Decide whether to include the reason for disallowed login
|
||||||
func (a *Authenticator) canUsernameLogin(username string) (bool, error) {
|
func (a *Authenticator) canUsernameLogin(username string) (bool, error) {
|
||||||
acc, err := dbgen.User.Where(dbgen.User.Username.Eq(username)).First()
|
acc, err := dbgen.User.GetByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ func (a *Authenticator) StartPasskeyLogin(
|
||||||
if ok, err := a.canUsernameLogin(username); !ok {
|
if ok, err := a.canUsernameLogin(username); !ok {
|
||||||
return nil, "", other.Error("auth", "user may not login", err)
|
return nil, "", other.Error("auth", "user may not login", err)
|
||||||
}
|
}
|
||||||
acc, err := dbgen.User.Where(dbgen.User.Username.Eq(username)).First()
|
acc, err := dbgen.User.GetByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", other.Error("auth", "failed to acquire user for login", err)
|
return nil, "", other.Error("auth", "failed to acquire user for login", err)
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ func (a *Authenticator) CompletePasskeyLogin(
|
||||||
response *http.Request,
|
response *http.Request,
|
||||||
) (accessToken string, err error) {
|
) (accessToken string, err error) {
|
||||||
// Get user in question
|
// Get user in question
|
||||||
acc, err := dbgen.User.Where(dbgen.User.Username.Eq(username)).First()
|
acc, err := dbgen.User.GetByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", other.Error("auth", "failed to get user for passkey login completion", err)
|
return "", other.Error("auth", "failed to get user for passkey login completion", err)
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ func (a *Authenticator) StartPasskeyRegistration(
|
||||||
if ok, err := a.canUsernameLogin(username); !ok {
|
if ok, err := a.canUsernameLogin(username); !ok {
|
||||||
return nil, "", other.Error("auth", "user may not login", err)
|
return nil, "", other.Error("auth", "user may not login", err)
|
||||||
}
|
}
|
||||||
acc, err := dbgen.User.Where(dbgen.User.Username.Eq(username)).First()
|
acc, err := dbgen.User.GetByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", other.Error("auth", "failed to acquire user for login", err)
|
return nil, "", other.Error("auth", "failed to acquire user for login", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ func (a *Authenticator) PerformPasswordLogin(
|
||||||
if ok, err := a.canUsernameLogin(username); !ok {
|
if ok, err := a.canUsernameLogin(username); !ok {
|
||||||
return LoginNextFailure, "", other.Error("auth", "user may not login", err)
|
return LoginNextFailure, "", other.Error("auth", "user may not login", err)
|
||||||
}
|
}
|
||||||
acc, err := dbgen.User.Where(dbgen.User.Username.Eq(username)).First()
|
acc, err := dbgen.User.GetByUsername(username)
|
||||||
switch err {
|
switch err {
|
||||||
case nil:
|
case nil:
|
||||||
break
|
break
|
||||||
|
@ -110,7 +110,7 @@ func (a *Authenticator) PerformPasswordLogin(
|
||||||
// If there is no password set yet (i.e. during account registration or passkey only so far)
|
// If there is no password set yet (i.e. during account registration or passkey only so far)
|
||||||
// it creates the password link
|
// it creates the password link
|
||||||
func (a *Authenticator) PerformPasswordRegister(username, password string) error {
|
func (a *Authenticator) PerformPasswordRegister(username, password string) error {
|
||||||
acc, err := dbgen.User.Where(dbgen.User.Username.Eq(username)).First()
|
acc, err := dbgen.User.GetByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return other.Error("auth", "failed to get user to add a password to", err)
|
return other.Error("auth", "failed to get user to add a password to", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ func (a *Authenticator) StartTotpRegistration(
|
||||||
if ok, err := a.canUsernameLogin(username); !ok {
|
if ok, err := a.canUsernameLogin(username); !ok {
|
||||||
return nil, other.Error("auth", "user may not login", err)
|
return nil, other.Error("auth", "user may not login", err)
|
||||||
}
|
}
|
||||||
acc, err := dbgen.User.Where(dbgen.User.Username.Eq(username)).First()
|
acc, err := dbgen.User.GetByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, other.Error("auth", "failed to find account", err)
|
return nil, other.Error("auth", "failed to find account", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,54 +18,14 @@ import (
|
||||||
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// "git.mstar.dev/mstar/linstrom/config"
|
|
||||||
|
|
||||||
// "context"
|
|
||||||
// "time"
|
|
||||||
// postgresContainer "github.com/testcontainers/testcontainers-go/modules/postgres"
|
|
||||||
// "github.com/testcontainers/testcontainers-go"
|
|
||||||
// "github.com/testcontainers/testcontainers-go/wait"
|
|
||||||
|
|
||||||
const (
|
|
||||||
dbName = "linstrom"
|
|
||||||
dbUser = "linstrom"
|
|
||||||
dbPass = "linstrom"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
other.SetupFlags()
|
other.SetupFlags()
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
other.ConfigureLogging(nil)
|
other.ConfigureLogging(nil)
|
||||||
config.ReadAndWriteToGlobal(*shared.FlagConfigFile)
|
config.ReadAndWriteToGlobal(*shared.FlagConfigFile)
|
||||||
|
|
||||||
// Set up a temporary postgres container for gorm-gen to do its thing
|
|
||||||
// log.Info().Msg("Starting temporary postgres container")
|
|
||||||
// pgContainer, err := postgresContainer.Run(
|
|
||||||
// context.Background(),
|
|
||||||
// "postgres:16.4-alpine",
|
|
||||||
// postgresContainer.WithDatabase(dbName),
|
|
||||||
// postgresContainer.WithUsername(dbUser),
|
|
||||||
// postgresContainer.WithPassword(dbPass),
|
|
||||||
// testcontainers.WithWaitStrategyAndDeadline(
|
|
||||||
// time.Minute,
|
|
||||||
// wait.ForLog("database system is ready to accept connections").
|
|
||||||
// WithOccurrence(2).
|
|
||||||
// WithStartupTimeout(time.Second*5),
|
|
||||||
// ),
|
|
||||||
// )
|
|
||||||
// if err != nil {
|
|
||||||
// log.Fatal().Err(err).Msg("Failed to setup temporary postgres container")
|
|
||||||
// }
|
|
||||||
// log.Info().Msg("Temporary postgres container started")
|
|
||||||
// defer func() {
|
|
||||||
// if err := testcontainers.TerminateContainer(pgContainer); err != nil {
|
|
||||||
// log.Fatal().Err(err).Msg("Failed to terminate temporary postgres container")
|
|
||||||
// }
|
|
||||||
// log.Info().Msg("Temporary postgres container stopped")
|
|
||||||
// }()
|
|
||||||
db, err := gorm.Open(
|
db, err := gorm.Open(
|
||||||
postgres.Open(config.GlobalConfig.Storage.BuildPostgresDSN()),
|
postgres.Open(config.GlobalConfig.Storage.BuildPostgresDSN()),
|
||||||
// postgres.Open(pgContainer.MustConnectionString(context.Background())),
|
|
||||||
&gorm.Config{
|
&gorm.Config{
|
||||||
PrepareStmt: false,
|
PrepareStmt: false,
|
||||||
Logger: shared.NewGormLogger(log.Logger),
|
Logger: shared.NewGormLogger(log.Logger),
|
||||||
|
@ -84,7 +44,12 @@ func main() {
|
||||||
log.Info().Msg("Applying basic operations on all datatypes")
|
log.Info().Msg("Applying basic operations on all datatypes")
|
||||||
g.ApplyBasic(models.AllTypes...)
|
g.ApplyBasic(models.AllTypes...)
|
||||||
|
|
||||||
log.Info().Msg("Starting generation")
|
log.Info().Msg("Basic operations applied, applying extra features")
|
||||||
|
g.ApplyInterface(func(models.INotification) {}, models.Notification{})
|
||||||
|
g.ApplyInterface(func(models.IUser) {}, models.User{})
|
||||||
|
g.ApplyInterface(func(models.IAccessToken) {}, models.AccessToken{})
|
||||||
|
|
||||||
|
log.Info().Msg("Extra features applied, starting generation")
|
||||||
g.Execute()
|
g.Execute()
|
||||||
log.Info().Msg("Code generation complete")
|
log.Info().Msg("Code generation complete")
|
||||||
}
|
}
|
||||||
|
|
19
storage-new/cleaners/ExpireAccessTokens.go
Normal file
19
storage-new/cleaners/ExpireAccessTokens.go
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package cleaners
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cleanerBuilders = append(cleanerBuilders, buildExpireAccessTokens)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tickExpireAccessTokens(now time.Time) {
|
||||||
|
dbgen.AccessToken.Where(dbgen.AccessToken.ExpiresAt.Lt(time.Now())).Delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildExpireAccessTokens() (onTick func(time.Time), name string, tickSpeed time.Duration) {
|
||||||
|
return tickExpireAccessTokens, "expire-access-tokens", time.Hour
|
||||||
|
}
|
70
storage-new/cleaners/manager.go
Normal file
70
storage-new/cleaners/manager.go
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
package cleaners
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CleanerManager struct {
|
||||||
|
activeCleaners map[string]bool
|
||||||
|
activeCleanerLock sync.Mutex
|
||||||
|
exitChans []chan any
|
||||||
|
}
|
||||||
|
|
||||||
|
var cleanerBuilders = []func() (onTick func(time.Time), name string, tickSpeed time.Duration){}
|
||||||
|
|
||||||
|
func NewManager() *CleanerManager {
|
||||||
|
activeCleaners := make(map[string]bool)
|
||||||
|
exitChans := []chan any{}
|
||||||
|
cm := &CleanerManager{
|
||||||
|
activeCleaners: activeCleaners,
|
||||||
|
exitChans: exitChans,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Launch all cleaner tickers in a new goroutine each
|
||||||
|
for _, builder := range cleanerBuilders {
|
||||||
|
exitChan := make(chan any, 1)
|
||||||
|
onTick, name, tickSpeed := builder()
|
||||||
|
cm.exitChans = append(cm.exitChans, exitChan)
|
||||||
|
go cm.tickOrExit(tickSpeed, name, exitChan, onTick)
|
||||||
|
}
|
||||||
|
|
||||||
|
return cm
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *CleanerManager) Stop() {
|
||||||
|
for _, exitChan := range m.exitChans {
|
||||||
|
exitChan <- 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *CleanerManager) tickOrExit(
|
||||||
|
tickSpeed time.Duration,
|
||||||
|
name string,
|
||||||
|
exitChan chan any,
|
||||||
|
onTick func(time.Time),
|
||||||
|
) {
|
||||||
|
ticker := time.Tick(tickSpeed)
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case now := <-ticker:
|
||||||
|
go m.wrapOnTick(name, now, onTick)
|
||||||
|
case <-exitChan:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *CleanerManager) wrapOnTick(name string, now time.Time, onTick func(time.Time)) {
|
||||||
|
m.activeCleanerLock.Lock()
|
||||||
|
if m.activeCleaners[name] {
|
||||||
|
m.activeCleanerLock.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m.activeCleaners[name] = true
|
||||||
|
m.activeCleanerLock.Unlock()
|
||||||
|
onTick(now)
|
||||||
|
m.activeCleanerLock.Lock()
|
||||||
|
m.activeCleaners[name] = false
|
||||||
|
m.activeCleanerLock.Unlock()
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ package dbgen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
@ -435,6 +436,25 @@ type IAccessTokenDo interface {
|
||||||
Returning(value interface{}, columns ...string) IAccessTokenDo
|
Returning(value interface{}, columns ...string) IAccessTokenDo
|
||||||
UnderlyingDB() *gorm.DB
|
UnderlyingDB() *gorm.DB
|
||||||
schema.Tabler
|
schema.Tabler
|
||||||
|
|
||||||
|
GetTokenIfValid(token string) (result *models.AccessToken, err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the data for a token if it hasn't expired yet
|
||||||
|
//
|
||||||
|
// SELECT * FROM @@table WHERE token = @token AND expires_at < NOW() LIMIT 1
|
||||||
|
func (a accessTokenDo) GetTokenIfValid(token string) (result *models.AccessToken, err error) {
|
||||||
|
var params []interface{}
|
||||||
|
|
||||||
|
var generateSQL strings.Builder
|
||||||
|
params = append(params, token)
|
||||||
|
generateSQL.WriteString("SELECT * FROM access_tokens WHERE token = ? AND expires_at < NOW() LIMIT 1 ")
|
||||||
|
|
||||||
|
var executeSQL *gorm.DB
|
||||||
|
executeSQL = a.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert
|
||||||
|
err = executeSQL.Error
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a accessTokenDo) Debug() IAccessTokenDo {
|
func (a accessTokenDo) Debug() IAccessTokenDo {
|
||||||
|
|
684
storage-new/dbgen/feeds.gen.go
Normal file
684
storage-new/dbgen/feeds.gen.go
Normal file
|
@ -0,0 +1,684 @@
|
||||||
|
// 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 newFeed(db *gorm.DB, opts ...gen.DOOption) feed {
|
||||||
|
_feed := feed{}
|
||||||
|
|
||||||
|
_feed.feedDo.UseDB(db, opts...)
|
||||||
|
_feed.feedDo.UseModel(&models.Feed{})
|
||||||
|
|
||||||
|
tableName := _feed.feedDo.TableName()
|
||||||
|
_feed.ALL = field.NewAsterisk(tableName)
|
||||||
|
_feed.ID = field.NewUint(tableName, "id")
|
||||||
|
_feed.CreatedAt = field.NewTime(tableName, "created_at")
|
||||||
|
_feed.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||||
|
_feed.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||||
|
_feed.Name = field.NewString(tableName, "name")
|
||||||
|
_feed.OwnerId = field.NewString(tableName, "owner_id")
|
||||||
|
_feed.IsDefault = field.NewBool(tableName, "is_default")
|
||||||
|
_feed.PublicKey = field.NewField(tableName, "public_key")
|
||||||
|
_feed.Owner = feedBelongsToOwner{
|
||||||
|
db: db.Session(&gorm.Session{}),
|
||||||
|
|
||||||
|
RelationField: field.NewRelation("Owner", "models.User"),
|
||||||
|
Icon: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Icon", "models.MediaMetadata"),
|
||||||
|
},
|
||||||
|
Background: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Background", "models.MediaMetadata"),
|
||||||
|
},
|
||||||
|
Banner: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Banner", "models.MediaMetadata"),
|
||||||
|
},
|
||||||
|
RemoteInfo: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.RemoteInfo", "models.UserRemoteLinks"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.RemoteInfo.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
InfoFields: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.InfoFields", "models.UserInfoField"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.InfoFields.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
BeingTypes: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.BeingTypes", "models.UserToBeing"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.BeingTypes.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Tags: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Tags", "models.UserToTag"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Tags.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Relations: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
TargetUser struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Relations", "models.UserToUserRelation"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Relations.User", "models.User"),
|
||||||
|
},
|
||||||
|
TargetUser: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Relations.TargetUser", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Pronouns: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Pronouns", "models.UserToPronoun"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Pronouns.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Roles: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
Role struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Roles", "models.UserToRole"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Roles.User", "models.User"),
|
||||||
|
},
|
||||||
|
Role: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.Roles.Role", "models.Role"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
AuthMethods: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.AuthMethods", "models.UserAuthMethod"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Owner.AuthMethods.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_feed.fillFieldMap()
|
||||||
|
|
||||||
|
return _feed
|
||||||
|
}
|
||||||
|
|
||||||
|
type feed struct {
|
||||||
|
feedDo
|
||||||
|
|
||||||
|
ALL field.Asterisk
|
||||||
|
ID field.Uint
|
||||||
|
CreatedAt field.Time
|
||||||
|
UpdatedAt field.Time
|
||||||
|
DeletedAt field.Field
|
||||||
|
Name field.String
|
||||||
|
OwnerId field.String
|
||||||
|
IsDefault field.Bool
|
||||||
|
PublicKey field.Field
|
||||||
|
Owner feedBelongsToOwner
|
||||||
|
|
||||||
|
fieldMap map[string]field.Expr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feed) Table(newTableName string) *feed {
|
||||||
|
f.feedDo.UseTable(newTableName)
|
||||||
|
return f.updateTableName(newTableName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feed) As(alias string) *feed {
|
||||||
|
f.feedDo.DO = *(f.feedDo.As(alias).(*gen.DO))
|
||||||
|
return f.updateTableName(alias)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *feed) updateTableName(table string) *feed {
|
||||||
|
f.ALL = field.NewAsterisk(table)
|
||||||
|
f.ID = field.NewUint(table, "id")
|
||||||
|
f.CreatedAt = field.NewTime(table, "created_at")
|
||||||
|
f.UpdatedAt = field.NewTime(table, "updated_at")
|
||||||
|
f.DeletedAt = field.NewField(table, "deleted_at")
|
||||||
|
f.Name = field.NewString(table, "name")
|
||||||
|
f.OwnerId = field.NewString(table, "owner_id")
|
||||||
|
f.IsDefault = field.NewBool(table, "is_default")
|
||||||
|
f.PublicKey = field.NewField(table, "public_key")
|
||||||
|
|
||||||
|
f.fillFieldMap()
|
||||||
|
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *feed) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||||
|
_f, ok := f.fieldMap[fieldName]
|
||||||
|
if !ok || _f == nil {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
_oe, ok := _f.(field.OrderExpr)
|
||||||
|
return _oe, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *feed) fillFieldMap() {
|
||||||
|
f.fieldMap = make(map[string]field.Expr, 9)
|
||||||
|
f.fieldMap["id"] = f.ID
|
||||||
|
f.fieldMap["created_at"] = f.CreatedAt
|
||||||
|
f.fieldMap["updated_at"] = f.UpdatedAt
|
||||||
|
f.fieldMap["deleted_at"] = f.DeletedAt
|
||||||
|
f.fieldMap["name"] = f.Name
|
||||||
|
f.fieldMap["owner_id"] = f.OwnerId
|
||||||
|
f.fieldMap["is_default"] = f.IsDefault
|
||||||
|
f.fieldMap["public_key"] = f.PublicKey
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feed) clone(db *gorm.DB) feed {
|
||||||
|
f.feedDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feed) replaceDB(db *gorm.DB) feed {
|
||||||
|
f.feedDo.ReplaceDB(db)
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
type feedBelongsToOwner struct {
|
||||||
|
db *gorm.DB
|
||||||
|
|
||||||
|
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 feedBelongsToOwner) Where(conds ...field.Expr) *feedBelongsToOwner {
|
||||||
|
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 feedBelongsToOwner) WithContext(ctx context.Context) *feedBelongsToOwner {
|
||||||
|
a.db = a.db.WithContext(ctx)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a feedBelongsToOwner) Session(session *gorm.Session) *feedBelongsToOwner {
|
||||||
|
a.db = a.db.Session(session)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a feedBelongsToOwner) Model(m *models.Feed) *feedBelongsToOwnerTx {
|
||||||
|
return &feedBelongsToOwnerTx{a.db.Model(m).Association(a.Name())}
|
||||||
|
}
|
||||||
|
|
||||||
|
type feedBelongsToOwnerTx struct{ tx *gorm.Association }
|
||||||
|
|
||||||
|
func (a feedBelongsToOwnerTx) Find() (result *models.User, err error) {
|
||||||
|
return result, a.tx.Find(&result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a feedBelongsToOwnerTx) 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 feedBelongsToOwnerTx) 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 feedBelongsToOwnerTx) 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 feedBelongsToOwnerTx) Clear() error {
|
||||||
|
return a.tx.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a feedBelongsToOwnerTx) Count() int64 {
|
||||||
|
return a.tx.Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
type feedDo struct{ gen.DO }
|
||||||
|
|
||||||
|
type IFeedDo interface {
|
||||||
|
gen.SubQuery
|
||||||
|
Debug() IFeedDo
|
||||||
|
WithContext(ctx context.Context) IFeedDo
|
||||||
|
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||||
|
ReplaceDB(db *gorm.DB)
|
||||||
|
ReadDB() IFeedDo
|
||||||
|
WriteDB() IFeedDo
|
||||||
|
As(alias string) gen.Dao
|
||||||
|
Session(config *gorm.Session) IFeedDo
|
||||||
|
Columns(cols ...field.Expr) gen.Columns
|
||||||
|
Clauses(conds ...clause.Expression) IFeedDo
|
||||||
|
Not(conds ...gen.Condition) IFeedDo
|
||||||
|
Or(conds ...gen.Condition) IFeedDo
|
||||||
|
Select(conds ...field.Expr) IFeedDo
|
||||||
|
Where(conds ...gen.Condition) IFeedDo
|
||||||
|
Order(conds ...field.Expr) IFeedDo
|
||||||
|
Distinct(cols ...field.Expr) IFeedDo
|
||||||
|
Omit(cols ...field.Expr) IFeedDo
|
||||||
|
Join(table schema.Tabler, on ...field.Expr) IFeedDo
|
||||||
|
LeftJoin(table schema.Tabler, on ...field.Expr) IFeedDo
|
||||||
|
RightJoin(table schema.Tabler, on ...field.Expr) IFeedDo
|
||||||
|
Group(cols ...field.Expr) IFeedDo
|
||||||
|
Having(conds ...gen.Condition) IFeedDo
|
||||||
|
Limit(limit int) IFeedDo
|
||||||
|
Offset(offset int) IFeedDo
|
||||||
|
Count() (count int64, err error)
|
||||||
|
Scopes(funcs ...func(gen.Dao) gen.Dao) IFeedDo
|
||||||
|
Unscoped() IFeedDo
|
||||||
|
Create(values ...*models.Feed) error
|
||||||
|
CreateInBatches(values []*models.Feed, batchSize int) error
|
||||||
|
Save(values ...*models.Feed) error
|
||||||
|
First() (*models.Feed, error)
|
||||||
|
Take() (*models.Feed, error)
|
||||||
|
Last() (*models.Feed, error)
|
||||||
|
Find() ([]*models.Feed, error)
|
||||||
|
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Feed, err error)
|
||||||
|
FindInBatches(result *[]*models.Feed, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||||
|
Pluck(column field.Expr, dest interface{}) error
|
||||||
|
Delete(...*models.Feed) (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) IFeedDo
|
||||||
|
Assign(attrs ...field.AssignExpr) IFeedDo
|
||||||
|
Joins(fields ...field.RelationField) IFeedDo
|
||||||
|
Preload(fields ...field.RelationField) IFeedDo
|
||||||
|
FirstOrInit() (*models.Feed, error)
|
||||||
|
FirstOrCreate() (*models.Feed, error)
|
||||||
|
FindByPage(offset int, limit int) (result []*models.Feed, 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) IFeedDo
|
||||||
|
UnderlyingDB() *gorm.DB
|
||||||
|
schema.Tabler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Debug() IFeedDo {
|
||||||
|
return f.withDO(f.DO.Debug())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) WithContext(ctx context.Context) IFeedDo {
|
||||||
|
return f.withDO(f.DO.WithContext(ctx))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) ReadDB() IFeedDo {
|
||||||
|
return f.Clauses(dbresolver.Read)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) WriteDB() IFeedDo {
|
||||||
|
return f.Clauses(dbresolver.Write)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Session(config *gorm.Session) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Session(config))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Clauses(conds ...clause.Expression) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Clauses(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Returning(value interface{}, columns ...string) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Returning(value, columns...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Not(conds ...gen.Condition) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Not(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Or(conds ...gen.Condition) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Or(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Select(conds ...field.Expr) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Select(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Where(conds ...gen.Condition) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Where(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Order(conds ...field.Expr) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Order(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Distinct(cols ...field.Expr) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Distinct(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Omit(cols ...field.Expr) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Omit(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Join(table schema.Tabler, on ...field.Expr) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Join(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) LeftJoin(table schema.Tabler, on ...field.Expr) IFeedDo {
|
||||||
|
return f.withDO(f.DO.LeftJoin(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) RightJoin(table schema.Tabler, on ...field.Expr) IFeedDo {
|
||||||
|
return f.withDO(f.DO.RightJoin(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Group(cols ...field.Expr) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Group(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Having(conds ...gen.Condition) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Having(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Limit(limit int) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Limit(limit))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Offset(offset int) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Offset(offset))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Scopes(funcs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Unscoped() IFeedDo {
|
||||||
|
return f.withDO(f.DO.Unscoped())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Create(values ...*models.Feed) error {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return f.DO.Create(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) CreateInBatches(values []*models.Feed, batchSize int) error {
|
||||||
|
return f.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 (f feedDo) Save(values ...*models.Feed) error {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return f.DO.Save(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) First() (*models.Feed, error) {
|
||||||
|
if result, err := f.DO.First(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.Feed), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Take() (*models.Feed, error) {
|
||||||
|
if result, err := f.DO.Take(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.Feed), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Last() (*models.Feed, error) {
|
||||||
|
if result, err := f.DO.Last(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.Feed), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Find() ([]*models.Feed, error) {
|
||||||
|
result, err := f.DO.Find()
|
||||||
|
return result.([]*models.Feed), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Feed, err error) {
|
||||||
|
buf := make([]*models.Feed, 0, batchSize)
|
||||||
|
err = f.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 (f feedDo) FindInBatches(result *[]*models.Feed, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||||
|
return f.DO.FindInBatches(result, batchSize, fc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Attrs(attrs ...field.AssignExpr) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Attrs(attrs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Assign(attrs ...field.AssignExpr) IFeedDo {
|
||||||
|
return f.withDO(f.DO.Assign(attrs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Joins(fields ...field.RelationField) IFeedDo {
|
||||||
|
for _, _f := range fields {
|
||||||
|
f = *f.withDO(f.DO.Joins(_f))
|
||||||
|
}
|
||||||
|
return &f
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Preload(fields ...field.RelationField) IFeedDo {
|
||||||
|
for _, _f := range fields {
|
||||||
|
f = *f.withDO(f.DO.Preload(_f))
|
||||||
|
}
|
||||||
|
return &f
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) FirstOrInit() (*models.Feed, error) {
|
||||||
|
if result, err := f.DO.FirstOrInit(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.Feed), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) FirstOrCreate() (*models.Feed, error) {
|
||||||
|
if result, err := f.DO.FirstOrCreate(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.Feed), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) FindByPage(offset int, limit int) (result []*models.Feed, count int64, err error) {
|
||||||
|
result, err = f.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 = f.Offset(-1).Limit(-1).Count()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||||
|
count, err = f.Count()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = f.Offset(offset).Limit(limit).Scan(result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Scan(result interface{}) (err error) {
|
||||||
|
return f.DO.Scan(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f feedDo) Delete(models ...*models.Feed) (result gen.ResultInfo, err error) {
|
||||||
|
return f.DO.Delete(models)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *feedDo) withDO(do gen.Dao) *feedDo {
|
||||||
|
f.DO = *do.(*gen.DO)
|
||||||
|
return f
|
||||||
|
}
|
|
@ -19,13 +19,17 @@ var (
|
||||||
Q = new(Query)
|
Q = new(Query)
|
||||||
AccessToken *accessToken
|
AccessToken *accessToken
|
||||||
Emote *emote
|
Emote *emote
|
||||||
|
Feed *feed
|
||||||
LoginProcessToken *loginProcessToken
|
LoginProcessToken *loginProcessToken
|
||||||
MediaMetadata *mediaMetadata
|
MediaMetadata *mediaMetadata
|
||||||
Note *note
|
Note *note
|
||||||
NoteTag *noteTag
|
NoteTag *noteTag
|
||||||
NoteToAttachment *noteToAttachment
|
NoteToAttachment *noteToAttachment
|
||||||
|
NoteToBoost *noteToBoost
|
||||||
NoteToEmote *noteToEmote
|
NoteToEmote *noteToEmote
|
||||||
|
NoteToFeed *noteToFeed
|
||||||
NoteToPing *noteToPing
|
NoteToPing *noteToPing
|
||||||
|
Notification *notification
|
||||||
Reaction *reaction
|
Reaction *reaction
|
||||||
RemoteServer *remoteServer
|
RemoteServer *remoteServer
|
||||||
Role *role
|
Role *role
|
||||||
|
@ -44,13 +48,17 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||||
*Q = *Use(db, opts...)
|
*Q = *Use(db, opts...)
|
||||||
AccessToken = &Q.AccessToken
|
AccessToken = &Q.AccessToken
|
||||||
Emote = &Q.Emote
|
Emote = &Q.Emote
|
||||||
|
Feed = &Q.Feed
|
||||||
LoginProcessToken = &Q.LoginProcessToken
|
LoginProcessToken = &Q.LoginProcessToken
|
||||||
MediaMetadata = &Q.MediaMetadata
|
MediaMetadata = &Q.MediaMetadata
|
||||||
Note = &Q.Note
|
Note = &Q.Note
|
||||||
NoteTag = &Q.NoteTag
|
NoteTag = &Q.NoteTag
|
||||||
NoteToAttachment = &Q.NoteToAttachment
|
NoteToAttachment = &Q.NoteToAttachment
|
||||||
|
NoteToBoost = &Q.NoteToBoost
|
||||||
NoteToEmote = &Q.NoteToEmote
|
NoteToEmote = &Q.NoteToEmote
|
||||||
|
NoteToFeed = &Q.NoteToFeed
|
||||||
NoteToPing = &Q.NoteToPing
|
NoteToPing = &Q.NoteToPing
|
||||||
|
Notification = &Q.Notification
|
||||||
Reaction = &Q.Reaction
|
Reaction = &Q.Reaction
|
||||||
RemoteServer = &Q.RemoteServer
|
RemoteServer = &Q.RemoteServer
|
||||||
Role = &Q.Role
|
Role = &Q.Role
|
||||||
|
@ -70,13 +78,17 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||||
db: db,
|
db: db,
|
||||||
AccessToken: newAccessToken(db, opts...),
|
AccessToken: newAccessToken(db, opts...),
|
||||||
Emote: newEmote(db, opts...),
|
Emote: newEmote(db, opts...),
|
||||||
|
Feed: newFeed(db, opts...),
|
||||||
LoginProcessToken: newLoginProcessToken(db, opts...),
|
LoginProcessToken: newLoginProcessToken(db, opts...),
|
||||||
MediaMetadata: newMediaMetadata(db, opts...),
|
MediaMetadata: newMediaMetadata(db, opts...),
|
||||||
Note: newNote(db, opts...),
|
Note: newNote(db, opts...),
|
||||||
NoteTag: newNoteTag(db, opts...),
|
NoteTag: newNoteTag(db, opts...),
|
||||||
NoteToAttachment: newNoteToAttachment(db, opts...),
|
NoteToAttachment: newNoteToAttachment(db, opts...),
|
||||||
|
NoteToBoost: newNoteToBoost(db, opts...),
|
||||||
NoteToEmote: newNoteToEmote(db, opts...),
|
NoteToEmote: newNoteToEmote(db, opts...),
|
||||||
|
NoteToFeed: newNoteToFeed(db, opts...),
|
||||||
NoteToPing: newNoteToPing(db, opts...),
|
NoteToPing: newNoteToPing(db, opts...),
|
||||||
|
Notification: newNotification(db, opts...),
|
||||||
Reaction: newReaction(db, opts...),
|
Reaction: newReaction(db, opts...),
|
||||||
RemoteServer: newRemoteServer(db, opts...),
|
RemoteServer: newRemoteServer(db, opts...),
|
||||||
Role: newRole(db, opts...),
|
Role: newRole(db, opts...),
|
||||||
|
@ -97,13 +109,17 @@ type Query struct {
|
||||||
|
|
||||||
AccessToken accessToken
|
AccessToken accessToken
|
||||||
Emote emote
|
Emote emote
|
||||||
|
Feed feed
|
||||||
LoginProcessToken loginProcessToken
|
LoginProcessToken loginProcessToken
|
||||||
MediaMetadata mediaMetadata
|
MediaMetadata mediaMetadata
|
||||||
Note note
|
Note note
|
||||||
NoteTag noteTag
|
NoteTag noteTag
|
||||||
NoteToAttachment noteToAttachment
|
NoteToAttachment noteToAttachment
|
||||||
|
NoteToBoost noteToBoost
|
||||||
NoteToEmote noteToEmote
|
NoteToEmote noteToEmote
|
||||||
|
NoteToFeed noteToFeed
|
||||||
NoteToPing noteToPing
|
NoteToPing noteToPing
|
||||||
|
Notification notification
|
||||||
Reaction reaction
|
Reaction reaction
|
||||||
RemoteServer remoteServer
|
RemoteServer remoteServer
|
||||||
Role role
|
Role role
|
||||||
|
@ -125,13 +141,17 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||||
db: db,
|
db: db,
|
||||||
AccessToken: q.AccessToken.clone(db),
|
AccessToken: q.AccessToken.clone(db),
|
||||||
Emote: q.Emote.clone(db),
|
Emote: q.Emote.clone(db),
|
||||||
|
Feed: q.Feed.clone(db),
|
||||||
LoginProcessToken: q.LoginProcessToken.clone(db),
|
LoginProcessToken: q.LoginProcessToken.clone(db),
|
||||||
MediaMetadata: q.MediaMetadata.clone(db),
|
MediaMetadata: q.MediaMetadata.clone(db),
|
||||||
Note: q.Note.clone(db),
|
Note: q.Note.clone(db),
|
||||||
NoteTag: q.NoteTag.clone(db),
|
NoteTag: q.NoteTag.clone(db),
|
||||||
NoteToAttachment: q.NoteToAttachment.clone(db),
|
NoteToAttachment: q.NoteToAttachment.clone(db),
|
||||||
|
NoteToBoost: q.NoteToBoost.clone(db),
|
||||||
NoteToEmote: q.NoteToEmote.clone(db),
|
NoteToEmote: q.NoteToEmote.clone(db),
|
||||||
|
NoteToFeed: q.NoteToFeed.clone(db),
|
||||||
NoteToPing: q.NoteToPing.clone(db),
|
NoteToPing: q.NoteToPing.clone(db),
|
||||||
|
Notification: q.Notification.clone(db),
|
||||||
Reaction: q.Reaction.clone(db),
|
Reaction: q.Reaction.clone(db),
|
||||||
RemoteServer: q.RemoteServer.clone(db),
|
RemoteServer: q.RemoteServer.clone(db),
|
||||||
Role: q.Role.clone(db),
|
Role: q.Role.clone(db),
|
||||||
|
@ -160,13 +180,17 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||||
db: db,
|
db: db,
|
||||||
AccessToken: q.AccessToken.replaceDB(db),
|
AccessToken: q.AccessToken.replaceDB(db),
|
||||||
Emote: q.Emote.replaceDB(db),
|
Emote: q.Emote.replaceDB(db),
|
||||||
|
Feed: q.Feed.replaceDB(db),
|
||||||
LoginProcessToken: q.LoginProcessToken.replaceDB(db),
|
LoginProcessToken: q.LoginProcessToken.replaceDB(db),
|
||||||
MediaMetadata: q.MediaMetadata.replaceDB(db),
|
MediaMetadata: q.MediaMetadata.replaceDB(db),
|
||||||
Note: q.Note.replaceDB(db),
|
Note: q.Note.replaceDB(db),
|
||||||
NoteTag: q.NoteTag.replaceDB(db),
|
NoteTag: q.NoteTag.replaceDB(db),
|
||||||
NoteToAttachment: q.NoteToAttachment.replaceDB(db),
|
NoteToAttachment: q.NoteToAttachment.replaceDB(db),
|
||||||
|
NoteToBoost: q.NoteToBoost.replaceDB(db),
|
||||||
NoteToEmote: q.NoteToEmote.replaceDB(db),
|
NoteToEmote: q.NoteToEmote.replaceDB(db),
|
||||||
|
NoteToFeed: q.NoteToFeed.replaceDB(db),
|
||||||
NoteToPing: q.NoteToPing.replaceDB(db),
|
NoteToPing: q.NoteToPing.replaceDB(db),
|
||||||
|
Notification: q.Notification.replaceDB(db),
|
||||||
Reaction: q.Reaction.replaceDB(db),
|
Reaction: q.Reaction.replaceDB(db),
|
||||||
RemoteServer: q.RemoteServer.replaceDB(db),
|
RemoteServer: q.RemoteServer.replaceDB(db),
|
||||||
Role: q.Role.replaceDB(db),
|
Role: q.Role.replaceDB(db),
|
||||||
|
@ -185,13 +209,17 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||||
type queryCtx struct {
|
type queryCtx struct {
|
||||||
AccessToken IAccessTokenDo
|
AccessToken IAccessTokenDo
|
||||||
Emote IEmoteDo
|
Emote IEmoteDo
|
||||||
|
Feed IFeedDo
|
||||||
LoginProcessToken ILoginProcessTokenDo
|
LoginProcessToken ILoginProcessTokenDo
|
||||||
MediaMetadata IMediaMetadataDo
|
MediaMetadata IMediaMetadataDo
|
||||||
Note INoteDo
|
Note INoteDo
|
||||||
NoteTag INoteTagDo
|
NoteTag INoteTagDo
|
||||||
NoteToAttachment INoteToAttachmentDo
|
NoteToAttachment INoteToAttachmentDo
|
||||||
|
NoteToBoost INoteToBoostDo
|
||||||
NoteToEmote INoteToEmoteDo
|
NoteToEmote INoteToEmoteDo
|
||||||
|
NoteToFeed INoteToFeedDo
|
||||||
NoteToPing INoteToPingDo
|
NoteToPing INoteToPingDo
|
||||||
|
Notification INotificationDo
|
||||||
Reaction IReactionDo
|
Reaction IReactionDo
|
||||||
RemoteServer IRemoteServerDo
|
RemoteServer IRemoteServerDo
|
||||||
Role IRoleDo
|
Role IRoleDo
|
||||||
|
@ -210,13 +238,17 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||||
return &queryCtx{
|
return &queryCtx{
|
||||||
AccessToken: q.AccessToken.WithContext(ctx),
|
AccessToken: q.AccessToken.WithContext(ctx),
|
||||||
Emote: q.Emote.WithContext(ctx),
|
Emote: q.Emote.WithContext(ctx),
|
||||||
|
Feed: q.Feed.WithContext(ctx),
|
||||||
LoginProcessToken: q.LoginProcessToken.WithContext(ctx),
|
LoginProcessToken: q.LoginProcessToken.WithContext(ctx),
|
||||||
MediaMetadata: q.MediaMetadata.WithContext(ctx),
|
MediaMetadata: q.MediaMetadata.WithContext(ctx),
|
||||||
Note: q.Note.WithContext(ctx),
|
Note: q.Note.WithContext(ctx),
|
||||||
NoteTag: q.NoteTag.WithContext(ctx),
|
NoteTag: q.NoteTag.WithContext(ctx),
|
||||||
NoteToAttachment: q.NoteToAttachment.WithContext(ctx),
|
NoteToAttachment: q.NoteToAttachment.WithContext(ctx),
|
||||||
|
NoteToBoost: q.NoteToBoost.WithContext(ctx),
|
||||||
NoteToEmote: q.NoteToEmote.WithContext(ctx),
|
NoteToEmote: q.NoteToEmote.WithContext(ctx),
|
||||||
|
NoteToFeed: q.NoteToFeed.WithContext(ctx),
|
||||||
NoteToPing: q.NoteToPing.WithContext(ctx),
|
NoteToPing: q.NoteToPing.WithContext(ctx),
|
||||||
|
Notification: q.Notification.WithContext(ctx),
|
||||||
Reaction: q.Reaction.WithContext(ctx),
|
Reaction: q.Reaction.WithContext(ctx),
|
||||||
RemoteServer: q.RemoteServer.WithContext(ctx),
|
RemoteServer: q.RemoteServer.WithContext(ctx),
|
||||||
Role: q.Role.WithContext(ctx),
|
Role: q.Role.WithContext(ctx),
|
||||||
|
|
|
@ -30,7 +30,7 @@ func newMediaMetadata(db *gorm.DB, opts ...gen.DOOption) mediaMetadata {
|
||||||
_mediaMetadata.CreatedAt = field.NewTime(tableName, "created_at")
|
_mediaMetadata.CreatedAt = field.NewTime(tableName, "created_at")
|
||||||
_mediaMetadata.UpdatedAt = field.NewTime(tableName, "updated_at")
|
_mediaMetadata.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||||
_mediaMetadata.DeletedAt = field.NewField(tableName, "deleted_at")
|
_mediaMetadata.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||||
_mediaMetadata.OwnedBy = field.NewString(tableName, "owned_by")
|
_mediaMetadata.OwnedById = field.NewString(tableName, "owned_by_id")
|
||||||
_mediaMetadata.Remote = field.NewBool(tableName, "remote")
|
_mediaMetadata.Remote = field.NewBool(tableName, "remote")
|
||||||
_mediaMetadata.Location = field.NewString(tableName, "location")
|
_mediaMetadata.Location = field.NewString(tableName, "location")
|
||||||
_mediaMetadata.Type = field.NewString(tableName, "type")
|
_mediaMetadata.Type = field.NewString(tableName, "type")
|
||||||
|
@ -51,7 +51,7 @@ type mediaMetadata struct {
|
||||||
CreatedAt field.Time
|
CreatedAt field.Time
|
||||||
UpdatedAt field.Time
|
UpdatedAt field.Time
|
||||||
DeletedAt field.Field
|
DeletedAt field.Field
|
||||||
OwnedBy field.String
|
OwnedById field.String
|
||||||
Remote field.Bool
|
Remote field.Bool
|
||||||
Location field.String
|
Location field.String
|
||||||
Type field.String
|
Type field.String
|
||||||
|
@ -78,7 +78,7 @@ func (m *mediaMetadata) updateTableName(table string) *mediaMetadata {
|
||||||
m.CreatedAt = field.NewTime(table, "created_at")
|
m.CreatedAt = field.NewTime(table, "created_at")
|
||||||
m.UpdatedAt = field.NewTime(table, "updated_at")
|
m.UpdatedAt = field.NewTime(table, "updated_at")
|
||||||
m.DeletedAt = field.NewField(table, "deleted_at")
|
m.DeletedAt = field.NewField(table, "deleted_at")
|
||||||
m.OwnedBy = field.NewString(table, "owned_by")
|
m.OwnedById = field.NewString(table, "owned_by_id")
|
||||||
m.Remote = field.NewBool(table, "remote")
|
m.Remote = field.NewBool(table, "remote")
|
||||||
m.Location = field.NewString(table, "location")
|
m.Location = field.NewString(table, "location")
|
||||||
m.Type = field.NewString(table, "type")
|
m.Type = field.NewString(table, "type")
|
||||||
|
@ -106,7 +106,7 @@ func (m *mediaMetadata) fillFieldMap() {
|
||||||
m.fieldMap["created_at"] = m.CreatedAt
|
m.fieldMap["created_at"] = m.CreatedAt
|
||||||
m.fieldMap["updated_at"] = m.UpdatedAt
|
m.fieldMap["updated_at"] = m.UpdatedAt
|
||||||
m.fieldMap["deleted_at"] = m.DeletedAt
|
m.fieldMap["deleted_at"] = m.DeletedAt
|
||||||
m.fieldMap["owned_by"] = m.OwnedBy
|
m.fieldMap["owned_by_id"] = m.OwnedById
|
||||||
m.fieldMap["remote"] = m.Remote
|
m.fieldMap["remote"] = m.Remote
|
||||||
m.fieldMap["location"] = m.Location
|
m.fieldMap["location"] = m.Location
|
||||||
m.fieldMap["type"] = m.Type
|
m.fieldMap["type"] = m.Type
|
||||||
|
|
910
storage-new/dbgen/note_to_boosts.gen.go
Normal file
910
storage-new/dbgen/note_to_boosts.gen.go
Normal file
|
@ -0,0 +1,910 @@
|
||||||
|
// 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 newNoteToBoost(db *gorm.DB, opts ...gen.DOOption) noteToBoost {
|
||||||
|
_noteToBoost := noteToBoost{}
|
||||||
|
|
||||||
|
_noteToBoost.noteToBoostDo.UseDB(db, opts...)
|
||||||
|
_noteToBoost.noteToBoostDo.UseModel(&models.NoteToBoost{})
|
||||||
|
|
||||||
|
tableName := _noteToBoost.noteToBoostDo.TableName()
|
||||||
|
_noteToBoost.ALL = field.NewAsterisk(tableName)
|
||||||
|
_noteToBoost.ID = field.NewUint(tableName, "id")
|
||||||
|
_noteToBoost.CreatedAt = field.NewTime(tableName, "created_at")
|
||||||
|
_noteToBoost.UserId = field.NewString(tableName, "user_id")
|
||||||
|
_noteToBoost.NoteId = field.NewString(tableName, "note_id")
|
||||||
|
_noteToBoost.User = noteToBoostBelongsToUser{
|
||||||
|
db: db.Session(&gorm.Session{}),
|
||||||
|
|
||||||
|
RelationField: field.NewRelation("User", "models.User"),
|
||||||
|
Icon: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Icon", "models.MediaMetadata"),
|
||||||
|
},
|
||||||
|
Background: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Background", "models.MediaMetadata"),
|
||||||
|
},
|
||||||
|
Banner: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Banner", "models.MediaMetadata"),
|
||||||
|
},
|
||||||
|
RemoteInfo: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.RemoteInfo", "models.UserRemoteLinks"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.RemoteInfo.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
InfoFields: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.InfoFields", "models.UserInfoField"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.InfoFields.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
BeingTypes: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.BeingTypes", "models.UserToBeing"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.BeingTypes.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Tags: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Tags", "models.UserToTag"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Tags.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Relations: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
TargetUser struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Relations", "models.UserToUserRelation"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Relations.User", "models.User"),
|
||||||
|
},
|
||||||
|
TargetUser: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Relations.TargetUser", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Pronouns: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Pronouns", "models.UserToPronoun"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Pronouns.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Roles: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
Role struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Roles", "models.UserToRole"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Roles.User", "models.User"),
|
||||||
|
},
|
||||||
|
Role: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.Roles.Role", "models.Role"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
AuthMethods: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.AuthMethods", "models.UserAuthMethod"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("User.AuthMethods.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_noteToBoost.Note = noteToBoostBelongsToNote{
|
||||||
|
db: db.Session(&gorm.Session{}),
|
||||||
|
|
||||||
|
RelationField: field.NewRelation("Note", "models.Note"),
|
||||||
|
Creator: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator", "models.User"),
|
||||||
|
},
|
||||||
|
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
|
||||||
|
Icon 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
|
||||||
|
Icon 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
|
||||||
|
Icon struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"),
|
||||||
|
Icon: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server.Icon", "models.MediaMetadata"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_noteToBoost.fillFieldMap()
|
||||||
|
|
||||||
|
return _noteToBoost
|
||||||
|
}
|
||||||
|
|
||||||
|
type noteToBoost struct {
|
||||||
|
noteToBoostDo
|
||||||
|
|
||||||
|
ALL field.Asterisk
|
||||||
|
ID field.Uint
|
||||||
|
CreatedAt field.Time
|
||||||
|
UserId field.String
|
||||||
|
NoteId field.String
|
||||||
|
User noteToBoostBelongsToUser
|
||||||
|
|
||||||
|
Note noteToBoostBelongsToNote
|
||||||
|
|
||||||
|
fieldMap map[string]field.Expr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoost) Table(newTableName string) *noteToBoost {
|
||||||
|
n.noteToBoostDo.UseTable(newTableName)
|
||||||
|
return n.updateTableName(newTableName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoost) As(alias string) *noteToBoost {
|
||||||
|
n.noteToBoostDo.DO = *(n.noteToBoostDo.As(alias).(*gen.DO))
|
||||||
|
return n.updateTableName(alias)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noteToBoost) updateTableName(table string) *noteToBoost {
|
||||||
|
n.ALL = field.NewAsterisk(table)
|
||||||
|
n.ID = field.NewUint(table, "id")
|
||||||
|
n.CreatedAt = field.NewTime(table, "created_at")
|
||||||
|
n.UserId = field.NewString(table, "user_id")
|
||||||
|
n.NoteId = field.NewString(table, "note_id")
|
||||||
|
|
||||||
|
n.fillFieldMap()
|
||||||
|
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noteToBoost) 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 *noteToBoost) fillFieldMap() {
|
||||||
|
n.fieldMap = make(map[string]field.Expr, 6)
|
||||||
|
n.fieldMap["id"] = n.ID
|
||||||
|
n.fieldMap["created_at"] = n.CreatedAt
|
||||||
|
n.fieldMap["user_id"] = n.UserId
|
||||||
|
n.fieldMap["note_id"] = n.NoteId
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoost) clone(db *gorm.DB) noteToBoost {
|
||||||
|
n.noteToBoostDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoost) replaceDB(db *gorm.DB) noteToBoost {
|
||||||
|
n.noteToBoostDo.ReplaceDB(db)
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
type noteToBoostBelongsToUser struct {
|
||||||
|
db *gorm.DB
|
||||||
|
|
||||||
|
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 noteToBoostBelongsToUser) Where(conds ...field.Expr) *noteToBoostBelongsToUser {
|
||||||
|
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 noteToBoostBelongsToUser) WithContext(ctx context.Context) *noteToBoostBelongsToUser {
|
||||||
|
a.db = a.db.WithContext(ctx)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToBoostBelongsToUser) Session(session *gorm.Session) *noteToBoostBelongsToUser {
|
||||||
|
a.db = a.db.Session(session)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToBoostBelongsToUser) Model(m *models.NoteToBoost) *noteToBoostBelongsToUserTx {
|
||||||
|
return ¬eToBoostBelongsToUserTx{a.db.Model(m).Association(a.Name())}
|
||||||
|
}
|
||||||
|
|
||||||
|
type noteToBoostBelongsToUserTx struct{ tx *gorm.Association }
|
||||||
|
|
||||||
|
func (a noteToBoostBelongsToUserTx) Find() (result *models.User, err error) {
|
||||||
|
return result, a.tx.Find(&result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToBoostBelongsToUserTx) 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 noteToBoostBelongsToUserTx) 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 noteToBoostBelongsToUserTx) 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 noteToBoostBelongsToUserTx) Clear() error {
|
||||||
|
return a.tx.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToBoostBelongsToUserTx) Count() int64 {
|
||||||
|
return a.tx.Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
type noteToBoostBelongsToNote struct {
|
||||||
|
db *gorm.DB
|
||||||
|
|
||||||
|
field.RelationField
|
||||||
|
|
||||||
|
Creator 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
|
||||||
|
Icon 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 noteToBoostBelongsToNote) Where(conds ...field.Expr) *noteToBoostBelongsToNote {
|
||||||
|
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 noteToBoostBelongsToNote) WithContext(ctx context.Context) *noteToBoostBelongsToNote {
|
||||||
|
a.db = a.db.WithContext(ctx)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToBoostBelongsToNote) Session(session *gorm.Session) *noteToBoostBelongsToNote {
|
||||||
|
a.db = a.db.Session(session)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToBoostBelongsToNote) Model(m *models.NoteToBoost) *noteToBoostBelongsToNoteTx {
|
||||||
|
return ¬eToBoostBelongsToNoteTx{a.db.Model(m).Association(a.Name())}
|
||||||
|
}
|
||||||
|
|
||||||
|
type noteToBoostBelongsToNoteTx struct{ tx *gorm.Association }
|
||||||
|
|
||||||
|
func (a noteToBoostBelongsToNoteTx) Find() (result *models.Note, err error) {
|
||||||
|
return result, a.tx.Find(&result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToBoostBelongsToNoteTx) 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 noteToBoostBelongsToNoteTx) 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 noteToBoostBelongsToNoteTx) 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 noteToBoostBelongsToNoteTx) Clear() error {
|
||||||
|
return a.tx.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToBoostBelongsToNoteTx) Count() int64 {
|
||||||
|
return a.tx.Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
type noteToBoostDo struct{ gen.DO }
|
||||||
|
|
||||||
|
type INoteToBoostDo interface {
|
||||||
|
gen.SubQuery
|
||||||
|
Debug() INoteToBoostDo
|
||||||
|
WithContext(ctx context.Context) INoteToBoostDo
|
||||||
|
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||||
|
ReplaceDB(db *gorm.DB)
|
||||||
|
ReadDB() INoteToBoostDo
|
||||||
|
WriteDB() INoteToBoostDo
|
||||||
|
As(alias string) gen.Dao
|
||||||
|
Session(config *gorm.Session) INoteToBoostDo
|
||||||
|
Columns(cols ...field.Expr) gen.Columns
|
||||||
|
Clauses(conds ...clause.Expression) INoteToBoostDo
|
||||||
|
Not(conds ...gen.Condition) INoteToBoostDo
|
||||||
|
Or(conds ...gen.Condition) INoteToBoostDo
|
||||||
|
Select(conds ...field.Expr) INoteToBoostDo
|
||||||
|
Where(conds ...gen.Condition) INoteToBoostDo
|
||||||
|
Order(conds ...field.Expr) INoteToBoostDo
|
||||||
|
Distinct(cols ...field.Expr) INoteToBoostDo
|
||||||
|
Omit(cols ...field.Expr) INoteToBoostDo
|
||||||
|
Join(table schema.Tabler, on ...field.Expr) INoteToBoostDo
|
||||||
|
LeftJoin(table schema.Tabler, on ...field.Expr) INoteToBoostDo
|
||||||
|
RightJoin(table schema.Tabler, on ...field.Expr) INoteToBoostDo
|
||||||
|
Group(cols ...field.Expr) INoteToBoostDo
|
||||||
|
Having(conds ...gen.Condition) INoteToBoostDo
|
||||||
|
Limit(limit int) INoteToBoostDo
|
||||||
|
Offset(offset int) INoteToBoostDo
|
||||||
|
Count() (count int64, err error)
|
||||||
|
Scopes(funcs ...func(gen.Dao) gen.Dao) INoteToBoostDo
|
||||||
|
Unscoped() INoteToBoostDo
|
||||||
|
Create(values ...*models.NoteToBoost) error
|
||||||
|
CreateInBatches(values []*models.NoteToBoost, batchSize int) error
|
||||||
|
Save(values ...*models.NoteToBoost) error
|
||||||
|
First() (*models.NoteToBoost, error)
|
||||||
|
Take() (*models.NoteToBoost, error)
|
||||||
|
Last() (*models.NoteToBoost, error)
|
||||||
|
Find() ([]*models.NoteToBoost, error)
|
||||||
|
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.NoteToBoost, err error)
|
||||||
|
FindInBatches(result *[]*models.NoteToBoost, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||||
|
Pluck(column field.Expr, dest interface{}) error
|
||||||
|
Delete(...*models.NoteToBoost) (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) INoteToBoostDo
|
||||||
|
Assign(attrs ...field.AssignExpr) INoteToBoostDo
|
||||||
|
Joins(fields ...field.RelationField) INoteToBoostDo
|
||||||
|
Preload(fields ...field.RelationField) INoteToBoostDo
|
||||||
|
FirstOrInit() (*models.NoteToBoost, error)
|
||||||
|
FirstOrCreate() (*models.NoteToBoost, error)
|
||||||
|
FindByPage(offset int, limit int) (result []*models.NoteToBoost, 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) INoteToBoostDo
|
||||||
|
UnderlyingDB() *gorm.DB
|
||||||
|
schema.Tabler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Debug() INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Debug())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) WithContext(ctx context.Context) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.WithContext(ctx))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) ReadDB() INoteToBoostDo {
|
||||||
|
return n.Clauses(dbresolver.Read)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) WriteDB() INoteToBoostDo {
|
||||||
|
return n.Clauses(dbresolver.Write)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Session(config *gorm.Session) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Session(config))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Clauses(conds ...clause.Expression) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Clauses(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Returning(value interface{}, columns ...string) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Returning(value, columns...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Not(conds ...gen.Condition) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Not(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Or(conds ...gen.Condition) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Or(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Select(conds ...field.Expr) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Select(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Where(conds ...gen.Condition) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Where(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Order(conds ...field.Expr) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Order(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Distinct(cols ...field.Expr) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Distinct(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Omit(cols ...field.Expr) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Omit(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Join(table schema.Tabler, on ...field.Expr) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Join(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) LeftJoin(table schema.Tabler, on ...field.Expr) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.LeftJoin(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) RightJoin(table schema.Tabler, on ...field.Expr) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.RightJoin(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Group(cols ...field.Expr) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Group(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Having(conds ...gen.Condition) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Having(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Limit(limit int) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Limit(limit))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Offset(offset int) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Offset(offset))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Scopes(funcs ...func(gen.Dao) gen.Dao) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Scopes(funcs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Unscoped() INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Unscoped())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Create(values ...*models.NoteToBoost) error {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return n.DO.Create(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) CreateInBatches(values []*models.NoteToBoost, 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 noteToBoostDo) Save(values ...*models.NoteToBoost) error {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return n.DO.Save(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) First() (*models.NoteToBoost, error) {
|
||||||
|
if result, err := n.DO.First(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.NoteToBoost), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Take() (*models.NoteToBoost, error) {
|
||||||
|
if result, err := n.DO.Take(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.NoteToBoost), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Last() (*models.NoteToBoost, error) {
|
||||||
|
if result, err := n.DO.Last(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.NoteToBoost), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Find() ([]*models.NoteToBoost, error) {
|
||||||
|
result, err := n.DO.Find()
|
||||||
|
return result.([]*models.NoteToBoost), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.NoteToBoost, err error) {
|
||||||
|
buf := make([]*models.NoteToBoost, 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 noteToBoostDo) FindInBatches(result *[]*models.NoteToBoost, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||||
|
return n.DO.FindInBatches(result, batchSize, fc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Attrs(attrs ...field.AssignExpr) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Attrs(attrs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Assign(attrs ...field.AssignExpr) INoteToBoostDo {
|
||||||
|
return n.withDO(n.DO.Assign(attrs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Joins(fields ...field.RelationField) INoteToBoostDo {
|
||||||
|
for _, _f := range fields {
|
||||||
|
n = *n.withDO(n.DO.Joins(_f))
|
||||||
|
}
|
||||||
|
return &n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Preload(fields ...field.RelationField) INoteToBoostDo {
|
||||||
|
for _, _f := range fields {
|
||||||
|
n = *n.withDO(n.DO.Preload(_f))
|
||||||
|
}
|
||||||
|
return &n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) FirstOrInit() (*models.NoteToBoost, error) {
|
||||||
|
if result, err := n.DO.FirstOrInit(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.NoteToBoost), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) FirstOrCreate() (*models.NoteToBoost, error) {
|
||||||
|
if result, err := n.DO.FirstOrCreate(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.NoteToBoost), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) FindByPage(offset int, limit int) (result []*models.NoteToBoost, 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 noteToBoostDo) 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 noteToBoostDo) Scan(result interface{}) (err error) {
|
||||||
|
return n.DO.Scan(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToBoostDo) Delete(models ...*models.NoteToBoost) (result gen.ResultInfo, err error) {
|
||||||
|
return n.DO.Delete(models)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noteToBoostDo) withDO(do gen.Dao) *noteToBoostDo {
|
||||||
|
n.DO = *do.(*gen.DO)
|
||||||
|
return n
|
||||||
|
}
|
889
storage-new/dbgen/note_to_feeds.gen.go
Normal file
889
storage-new/dbgen/note_to_feeds.gen.go
Normal file
|
@ -0,0 +1,889 @@
|
||||||
|
// 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 newNoteToFeed(db *gorm.DB, opts ...gen.DOOption) noteToFeed {
|
||||||
|
_noteToFeed := noteToFeed{}
|
||||||
|
|
||||||
|
_noteToFeed.noteToFeedDo.UseDB(db, opts...)
|
||||||
|
_noteToFeed.noteToFeedDo.UseModel(&models.NoteToFeed{})
|
||||||
|
|
||||||
|
tableName := _noteToFeed.noteToFeedDo.TableName()
|
||||||
|
_noteToFeed.ALL = field.NewAsterisk(tableName)
|
||||||
|
_noteToFeed.ID = field.NewUint64(tableName, "id")
|
||||||
|
_noteToFeed.CreatedAt = field.NewTime(tableName, "created_at")
|
||||||
|
_noteToFeed.NoteId = field.NewString(tableName, "note_id")
|
||||||
|
_noteToFeed.Note = noteToFeedBelongsToNote{
|
||||||
|
db: db.Session(&gorm.Session{}),
|
||||||
|
|
||||||
|
RelationField: field.NewRelation("Note", "models.Note"),
|
||||||
|
Creator: 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator", "models.User"),
|
||||||
|
Icon: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Icon", "models.MediaMetadata"),
|
||||||
|
},
|
||||||
|
Background: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Background", "models.MediaMetadata"),
|
||||||
|
},
|
||||||
|
Banner: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Banner", "models.MediaMetadata"),
|
||||||
|
},
|
||||||
|
RemoteInfo: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.RemoteInfo", "models.UserRemoteLinks"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.RemoteInfo.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
InfoFields: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.InfoFields", "models.UserInfoField"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.InfoFields.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
BeingTypes: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.BeingTypes", "models.UserToBeing"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.BeingTypes.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Tags: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Tags", "models.UserToTag"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Tags.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Relations: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
TargetUser struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Relations", "models.UserToUserRelation"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Relations.User", "models.User"),
|
||||||
|
},
|
||||||
|
TargetUser: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Relations.TargetUser", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Pronouns: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Pronouns", "models.UserToPronoun"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Pronouns.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Roles: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
Role struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Roles", "models.UserToRole"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Roles.User", "models.User"),
|
||||||
|
},
|
||||||
|
Role: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.Roles.Role", "models.Role"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
AuthMethods: struct {
|
||||||
|
field.RelationField
|
||||||
|
User struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.AuthMethods", "models.UserAuthMethod"),
|
||||||
|
User: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.Creator.AuthMethods.User", "models.User"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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
|
||||||
|
Icon 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
|
||||||
|
Icon 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
|
||||||
|
Icon struct {
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server", "models.RemoteServer"),
|
||||||
|
Icon: struct {
|
||||||
|
field.RelationField
|
||||||
|
}{
|
||||||
|
RelationField: field.NewRelation("Note.EmoteRelations.Emote.Server.Icon", "models.MediaMetadata"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
_noteToFeed.fillFieldMap()
|
||||||
|
|
||||||
|
return _noteToFeed
|
||||||
|
}
|
||||||
|
|
||||||
|
type noteToFeed struct {
|
||||||
|
noteToFeedDo
|
||||||
|
|
||||||
|
ALL field.Asterisk
|
||||||
|
ID field.Uint64
|
||||||
|
CreatedAt field.Time
|
||||||
|
NoteId field.String
|
||||||
|
Note noteToFeedBelongsToNote
|
||||||
|
|
||||||
|
fieldMap map[string]field.Expr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeed) Table(newTableName string) *noteToFeed {
|
||||||
|
n.noteToFeedDo.UseTable(newTableName)
|
||||||
|
return n.updateTableName(newTableName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeed) As(alias string) *noteToFeed {
|
||||||
|
n.noteToFeedDo.DO = *(n.noteToFeedDo.As(alias).(*gen.DO))
|
||||||
|
return n.updateTableName(alias)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noteToFeed) updateTableName(table string) *noteToFeed {
|
||||||
|
n.ALL = field.NewAsterisk(table)
|
||||||
|
n.ID = field.NewUint64(table, "id")
|
||||||
|
n.CreatedAt = field.NewTime(table, "created_at")
|
||||||
|
n.NoteId = field.NewString(table, "note_id")
|
||||||
|
|
||||||
|
n.fillFieldMap()
|
||||||
|
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noteToFeed) 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 *noteToFeed) fillFieldMap() {
|
||||||
|
n.fieldMap = make(map[string]field.Expr, 4)
|
||||||
|
n.fieldMap["id"] = n.ID
|
||||||
|
n.fieldMap["created_at"] = n.CreatedAt
|
||||||
|
n.fieldMap["note_id"] = n.NoteId
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeed) clone(db *gorm.DB) noteToFeed {
|
||||||
|
n.noteToFeedDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeed) replaceDB(db *gorm.DB) noteToFeed {
|
||||||
|
n.noteToFeedDo.ReplaceDB(db)
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
type noteToFeedBelongsToNote struct {
|
||||||
|
db *gorm.DB
|
||||||
|
|
||||||
|
field.RelationField
|
||||||
|
|
||||||
|
Creator 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
Icon 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 noteToFeedBelongsToNote) Where(conds ...field.Expr) *noteToFeedBelongsToNote {
|
||||||
|
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 noteToFeedBelongsToNote) WithContext(ctx context.Context) *noteToFeedBelongsToNote {
|
||||||
|
a.db = a.db.WithContext(ctx)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToFeedBelongsToNote) Session(session *gorm.Session) *noteToFeedBelongsToNote {
|
||||||
|
a.db = a.db.Session(session)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToFeedBelongsToNote) Model(m *models.NoteToFeed) *noteToFeedBelongsToNoteTx {
|
||||||
|
return ¬eToFeedBelongsToNoteTx{a.db.Model(m).Association(a.Name())}
|
||||||
|
}
|
||||||
|
|
||||||
|
type noteToFeedBelongsToNoteTx struct{ tx *gorm.Association }
|
||||||
|
|
||||||
|
func (a noteToFeedBelongsToNoteTx) Find() (result *models.Note, err error) {
|
||||||
|
return result, a.tx.Find(&result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToFeedBelongsToNoteTx) 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 noteToFeedBelongsToNoteTx) 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 noteToFeedBelongsToNoteTx) 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 noteToFeedBelongsToNoteTx) Clear() error {
|
||||||
|
return a.tx.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a noteToFeedBelongsToNoteTx) Count() int64 {
|
||||||
|
return a.tx.Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
type noteToFeedDo struct{ gen.DO }
|
||||||
|
|
||||||
|
type INoteToFeedDo interface {
|
||||||
|
gen.SubQuery
|
||||||
|
Debug() INoteToFeedDo
|
||||||
|
WithContext(ctx context.Context) INoteToFeedDo
|
||||||
|
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||||
|
ReplaceDB(db *gorm.DB)
|
||||||
|
ReadDB() INoteToFeedDo
|
||||||
|
WriteDB() INoteToFeedDo
|
||||||
|
As(alias string) gen.Dao
|
||||||
|
Session(config *gorm.Session) INoteToFeedDo
|
||||||
|
Columns(cols ...field.Expr) gen.Columns
|
||||||
|
Clauses(conds ...clause.Expression) INoteToFeedDo
|
||||||
|
Not(conds ...gen.Condition) INoteToFeedDo
|
||||||
|
Or(conds ...gen.Condition) INoteToFeedDo
|
||||||
|
Select(conds ...field.Expr) INoteToFeedDo
|
||||||
|
Where(conds ...gen.Condition) INoteToFeedDo
|
||||||
|
Order(conds ...field.Expr) INoteToFeedDo
|
||||||
|
Distinct(cols ...field.Expr) INoteToFeedDo
|
||||||
|
Omit(cols ...field.Expr) INoteToFeedDo
|
||||||
|
Join(table schema.Tabler, on ...field.Expr) INoteToFeedDo
|
||||||
|
LeftJoin(table schema.Tabler, on ...field.Expr) INoteToFeedDo
|
||||||
|
RightJoin(table schema.Tabler, on ...field.Expr) INoteToFeedDo
|
||||||
|
Group(cols ...field.Expr) INoteToFeedDo
|
||||||
|
Having(conds ...gen.Condition) INoteToFeedDo
|
||||||
|
Limit(limit int) INoteToFeedDo
|
||||||
|
Offset(offset int) INoteToFeedDo
|
||||||
|
Count() (count int64, err error)
|
||||||
|
Scopes(funcs ...func(gen.Dao) gen.Dao) INoteToFeedDo
|
||||||
|
Unscoped() INoteToFeedDo
|
||||||
|
Create(values ...*models.NoteToFeed) error
|
||||||
|
CreateInBatches(values []*models.NoteToFeed, batchSize int) error
|
||||||
|
Save(values ...*models.NoteToFeed) error
|
||||||
|
First() (*models.NoteToFeed, error)
|
||||||
|
Take() (*models.NoteToFeed, error)
|
||||||
|
Last() (*models.NoteToFeed, error)
|
||||||
|
Find() ([]*models.NoteToFeed, error)
|
||||||
|
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.NoteToFeed, err error)
|
||||||
|
FindInBatches(result *[]*models.NoteToFeed, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||||
|
Pluck(column field.Expr, dest interface{}) error
|
||||||
|
Delete(...*models.NoteToFeed) (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) INoteToFeedDo
|
||||||
|
Assign(attrs ...field.AssignExpr) INoteToFeedDo
|
||||||
|
Joins(fields ...field.RelationField) INoteToFeedDo
|
||||||
|
Preload(fields ...field.RelationField) INoteToFeedDo
|
||||||
|
FirstOrInit() (*models.NoteToFeed, error)
|
||||||
|
FirstOrCreate() (*models.NoteToFeed, error)
|
||||||
|
FindByPage(offset int, limit int) (result []*models.NoteToFeed, 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) INoteToFeedDo
|
||||||
|
UnderlyingDB() *gorm.DB
|
||||||
|
schema.Tabler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Debug() INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Debug())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) WithContext(ctx context.Context) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.WithContext(ctx))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) ReadDB() INoteToFeedDo {
|
||||||
|
return n.Clauses(dbresolver.Read)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) WriteDB() INoteToFeedDo {
|
||||||
|
return n.Clauses(dbresolver.Write)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Session(config *gorm.Session) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Session(config))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Clauses(conds ...clause.Expression) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Clauses(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Returning(value interface{}, columns ...string) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Returning(value, columns...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Not(conds ...gen.Condition) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Not(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Or(conds ...gen.Condition) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Or(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Select(conds ...field.Expr) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Select(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Where(conds ...gen.Condition) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Where(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Order(conds ...field.Expr) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Order(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Distinct(cols ...field.Expr) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Distinct(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Omit(cols ...field.Expr) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Omit(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Join(table schema.Tabler, on ...field.Expr) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Join(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) LeftJoin(table schema.Tabler, on ...field.Expr) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.LeftJoin(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) RightJoin(table schema.Tabler, on ...field.Expr) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.RightJoin(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Group(cols ...field.Expr) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Group(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Having(conds ...gen.Condition) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Having(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Limit(limit int) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Limit(limit))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Offset(offset int) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Offset(offset))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Scopes(funcs ...func(gen.Dao) gen.Dao) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Scopes(funcs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Unscoped() INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Unscoped())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Create(values ...*models.NoteToFeed) error {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return n.DO.Create(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) CreateInBatches(values []*models.NoteToFeed, 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 noteToFeedDo) Save(values ...*models.NoteToFeed) error {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return n.DO.Save(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) First() (*models.NoteToFeed, error) {
|
||||||
|
if result, err := n.DO.First(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.NoteToFeed), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Take() (*models.NoteToFeed, error) {
|
||||||
|
if result, err := n.DO.Take(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.NoteToFeed), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Last() (*models.NoteToFeed, error) {
|
||||||
|
if result, err := n.DO.Last(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.NoteToFeed), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Find() ([]*models.NoteToFeed, error) {
|
||||||
|
result, err := n.DO.Find()
|
||||||
|
return result.([]*models.NoteToFeed), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.NoteToFeed, err error) {
|
||||||
|
buf := make([]*models.NoteToFeed, 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 noteToFeedDo) FindInBatches(result *[]*models.NoteToFeed, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||||
|
return n.DO.FindInBatches(result, batchSize, fc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Attrs(attrs ...field.AssignExpr) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Attrs(attrs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Assign(attrs ...field.AssignExpr) INoteToFeedDo {
|
||||||
|
return n.withDO(n.DO.Assign(attrs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Joins(fields ...field.RelationField) INoteToFeedDo {
|
||||||
|
for _, _f := range fields {
|
||||||
|
n = *n.withDO(n.DO.Joins(_f))
|
||||||
|
}
|
||||||
|
return &n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Preload(fields ...field.RelationField) INoteToFeedDo {
|
||||||
|
for _, _f := range fields {
|
||||||
|
n = *n.withDO(n.DO.Preload(_f))
|
||||||
|
}
|
||||||
|
return &n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) FirstOrInit() (*models.NoteToFeed, error) {
|
||||||
|
if result, err := n.DO.FirstOrInit(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.NoteToFeed), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) FirstOrCreate() (*models.NoteToFeed, error) {
|
||||||
|
if result, err := n.DO.FirstOrCreate(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*models.NoteToFeed), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) FindByPage(offset int, limit int) (result []*models.NoteToFeed, 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 noteToFeedDo) 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 noteToFeedDo) Scan(result interface{}) (err error) {
|
||||||
|
return n.DO.Scan(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n noteToFeedDo) Delete(models ...*models.NoteToFeed) (result gen.ResultInfo, err error) {
|
||||||
|
return n.DO.Delete(models)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *noteToFeedDo) withDO(do gen.Dao) *noteToFeedDo {
|
||||||
|
n.DO = *do.(*gen.DO)
|
||||||
|
return n
|
||||||
|
}
|
1068
storage-new/dbgen/notifications.gen.go
Normal file
1068
storage-new/dbgen/notifications.gen.go
Normal file
File diff suppressed because it is too large
Load diff
|
@ -33,7 +33,7 @@ func newRemoteServer(db *gorm.DB, opts ...gen.DOOption) remoteServer {
|
||||||
_remoteServer.ServerType = field.NewField(tableName, "server_type")
|
_remoteServer.ServerType = field.NewField(tableName, "server_type")
|
||||||
_remoteServer.Domain = field.NewString(tableName, "domain")
|
_remoteServer.Domain = field.NewString(tableName, "domain")
|
||||||
_remoteServer.Name = field.NewString(tableName, "name")
|
_remoteServer.Name = field.NewString(tableName, "name")
|
||||||
_remoteServer.IconId = field.NewString(tableName, "icon_id")
|
_remoteServer.IconId = field.NewField(tableName, "icon_id")
|
||||||
_remoteServer.IsSelf = field.NewBool(tableName, "is_self")
|
_remoteServer.IsSelf = field.NewBool(tableName, "is_self")
|
||||||
_remoteServer.Icon = remoteServerBelongsToIcon{
|
_remoteServer.Icon = remoteServerBelongsToIcon{
|
||||||
db: db.Session(&gorm.Session{}),
|
db: db.Session(&gorm.Session{}),
|
||||||
|
@ -57,7 +57,7 @@ type remoteServer struct {
|
||||||
ServerType field.Field
|
ServerType field.Field
|
||||||
Domain field.String
|
Domain field.String
|
||||||
Name field.String
|
Name field.String
|
||||||
IconId field.String
|
IconId field.Field
|
||||||
IsSelf field.Bool
|
IsSelf field.Bool
|
||||||
Icon remoteServerBelongsToIcon
|
Icon remoteServerBelongsToIcon
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ func (r *remoteServer) updateTableName(table string) *remoteServer {
|
||||||
r.ServerType = field.NewField(table, "server_type")
|
r.ServerType = field.NewField(table, "server_type")
|
||||||
r.Domain = field.NewString(table, "domain")
|
r.Domain = field.NewString(table, "domain")
|
||||||
r.Name = field.NewString(table, "name")
|
r.Name = field.NewString(table, "name")
|
||||||
r.IconId = field.NewString(table, "icon_id")
|
r.IconId = field.NewField(table, "icon_id")
|
||||||
r.IsSelf = field.NewBool(table, "is_self")
|
r.IsSelf = field.NewBool(table, "is_self")
|
||||||
|
|
||||||
r.fillFieldMap()
|
r.fillFieldMap()
|
||||||
|
|
|
@ -6,6 +6,7 @@ package dbgen
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
@ -1346,6 +1347,25 @@ type IUserDo interface {
|
||||||
Returning(value interface{}, columns ...string) IUserDo
|
Returning(value interface{}, columns ...string) IUserDo
|
||||||
UnderlyingDB() *gorm.DB
|
UnderlyingDB() *gorm.DB
|
||||||
schema.Tabler
|
schema.Tabler
|
||||||
|
|
||||||
|
GetByUsername(username string) (result *models.User, err error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a user by a username
|
||||||
|
//
|
||||||
|
// SELECT * FROM @@table WHERE username = @username LIMIT 1
|
||||||
|
func (u userDo) GetByUsername(username string) (result *models.User, err error) {
|
||||||
|
var params []interface{}
|
||||||
|
|
||||||
|
var generateSQL strings.Builder
|
||||||
|
params = append(params, username)
|
||||||
|
generateSQL.WriteString("SELECT * FROM users WHERE username = ? LIMIT 1 ")
|
||||||
|
|
||||||
|
var executeSQL *gorm.DB
|
||||||
|
executeSQL = u.UnderlyingDB().Raw(generateSQL.String(), params...).Take(&result) // ignore_security_alert
|
||||||
|
err = executeSQL.Error
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u userDo) Debug() IUserDo {
|
func (u userDo) Debug() IUserDo {
|
||||||
|
|
|
@ -7,10 +7,12 @@ var AllTypes = []any{
|
||||||
&MediaMetadata{},
|
&MediaMetadata{},
|
||||||
&Note{},
|
&Note{},
|
||||||
&NoteToAttachment{},
|
&NoteToAttachment{},
|
||||||
|
&NoteToBoost{},
|
||||||
&NoteToEmote{},
|
&NoteToEmote{},
|
||||||
&NoteToFeed{},
|
&NoteToFeed{},
|
||||||
&NoteToPing{},
|
&NoteToPing{},
|
||||||
&NoteTag{},
|
&NoteTag{},
|
||||||
|
&Notification{},
|
||||||
&Reaction{},
|
&Reaction{},
|
||||||
&RemoteServer{},
|
&RemoteServer{},
|
||||||
&Role{},
|
&Role{},
|
||||||
|
|
13
storage-new/models/NoteToBoost.go
Normal file
13
storage-new/models/NoteToBoost.go
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
// Describes a user boosting one note
|
||||||
|
type NoteToBoost struct {
|
||||||
|
ID uint `gorm:"primarykey"`
|
||||||
|
CreatedAt time.Time
|
||||||
|
User User
|
||||||
|
UserId string
|
||||||
|
Note Note
|
||||||
|
NoteId string
|
||||||
|
}
|
42
storage-new/models/Notification.go
Normal file
42
storage-new/models/Notification.go
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
"gorm.io/gen"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Notifications inform users of inbound events
|
||||||
|
// happening to their content
|
||||||
|
type Notification struct {
|
||||||
|
gorm.Model
|
||||||
|
ForUser User // The user the notification is for
|
||||||
|
ForUserId string
|
||||||
|
SourceNote *Note // The note where the notification originates from
|
||||||
|
SourceNoteId sql.NullString
|
||||||
|
SourceUser *User // The user causing the notification
|
||||||
|
SourceUserId sql.NullString
|
||||||
|
Cause NotificationCauseType // What the cause of the notification is
|
||||||
|
ViewedState NotificationViewedState // What the last known state of the notification is
|
||||||
|
}
|
||||||
|
|
||||||
|
type INotification interface {
|
||||||
|
// 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
|
||||||
|
SetState(state uint8, ids ...uint) error
|
||||||
|
|
||||||
|
// 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
|
||||||
|
GetLatestWithOffset(userId string, count uint, offset uint) ([]gen.T, error)
|
||||||
|
}
|
22
storage-new/models/NotificationType.go
Normal file
22
storage-new/models/NotificationType.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import "database/sql/driver"
|
||||||
|
|
||||||
|
// What a notification is caused by
|
||||||
|
type NotificationCauseType uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
NotificationTypeReply NotificationCauseType = iota // A new reply
|
||||||
|
NotificationTypeReaction // A new reaction
|
||||||
|
NotificationTypeBoost // A note got boosted
|
||||||
|
NotificationTypeFollowRequest // Someone requested to follow
|
||||||
|
)
|
||||||
|
|
||||||
|
func (r *NotificationCauseType) Value() (driver.Value, error) {
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *NotificationCauseType) Scan(value any) error {
|
||||||
|
*ct = NotificationCauseType(value.(uint8))
|
||||||
|
return nil
|
||||||
|
}
|
21
storage-new/models/NotificationViewedStateType.go
Normal file
21
storage-new/models/NotificationViewedStateType.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import "database/sql/driver"
|
||||||
|
|
||||||
|
type NotificationViewedState uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
NotViewed NotificationViewedState = iota
|
||||||
|
Viewed
|
||||||
|
Accepted
|
||||||
|
Denied
|
||||||
|
)
|
||||||
|
|
||||||
|
func (r *NotificationViewedState) Value() (driver.Value, error) {
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *NotificationViewedState) Scan(value any) error {
|
||||||
|
*ct = NotificationViewedState(value.(uint8))
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -2,6 +2,8 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gen"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AccessToken maps a unique token to one account.
|
// AccessToken maps a unique token to one account.
|
||||||
|
@ -18,3 +20,10 @@ type AccessToken struct {
|
||||||
// at a point in the future this server should never reach
|
// at a point in the future this server should never reach
|
||||||
ExpiresAt time.Time `gorm:"default:TIMESTAMP WITH TIME ZONE '9999-12-30 23:59:59+00'"`
|
ExpiresAt time.Time `gorm:"default:TIMESTAMP WITH TIME ZONE '9999-12-30 23:59:59+00'"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IAccessToken interface {
|
||||||
|
// Get the data for a token
|
||||||
|
//
|
||||||
|
// SELECT * FROM @@table WHERE token = @token
|
||||||
|
GetTokenIfValid(token string) (*gen.T, error)
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gen"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"git.mstar.dev/mstar/linstrom/config"
|
"git.mstar.dev/mstar/linstrom/config"
|
||||||
|
@ -97,3 +98,10 @@ func BuildLinstromUser() *User {
|
||||||
BannerId: sql.NullString{Valid: false},
|
BannerId: sql.NullString{Valid: false},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IUser interface {
|
||||||
|
// Get a user by a username
|
||||||
|
//
|
||||||
|
// SELECT * FROM @@table WHERE username = @username LIMIT 1
|
||||||
|
GetByUsername(username string) (*gen.T, error)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue