diff --git a/go.mod b/go.mod index 7cfc3dfe..b460a46c 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/samber/lo v1.49.1 github.com/sony/sonyflake v1.2.0 github.com/spf13/afero v1.14.0 - github.com/tuihub/protos v0.5.2 + github.com/tuihub/protos v0.5.4 go.opentelemetry.io/otel v1.35.0 go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.11.0 go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.11.0 @@ -55,7 +55,7 @@ require ( go.uber.org/zap v1.27.0 golang.org/x/crypto v0.36.0 golang.org/x/text v0.23.0 - google.golang.org/grpc v1.71.0 + google.golang.org/grpc v1.71.1 google.golang.org/protobuf v1.36.6 gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) diff --git a/go.sum b/go.sum index 9d785437..95c6aa1c 100644 --- a/go.sum +++ b/go.sum @@ -712,8 +712,8 @@ github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tuihub/protos v0.5.2 h1:9FrBH3iz1OCMgHD7rVbcLaylU3Z7Ml9+Tqx0a/cWQJw= -github.com/tuihub/protos v0.5.2/go.mod h1:NzgjndKsJmA1tPevx2MTFbBLeIVC+ykrW87YpTp/ibA= +github.com/tuihub/protos v0.5.4 h1:u14CtxUdzehckcGcGzY3LwA19yUysrb2ZpSnJlhqemA= +github.com/tuihub/protos v0.5.4/go.mod h1:bky4vaFgW6oSHndf0E5KBrzsKDZevB6Tn5SWfo3aZio= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= @@ -1043,8 +1043,8 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8 google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= google.golang.org/grpc v1.32.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg= -google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec= +google.golang.org/grpc v1.71.1 h1:ffsFWr7ygTUscGPI0KKK6TLrGz0476KUvvsbqWK0rPI= +google.golang.org/grpc v1.71.1/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/internal/biz/bizgebura/sentinel.go b/internal/biz/bizgebura/sentinel.go new file mode 100644 index 00000000..4702b57a --- /dev/null +++ b/internal/biz/bizgebura/sentinel.go @@ -0,0 +1,41 @@ +package bizgebura + +import ( + "context" + + "github.com/tuihub/librarian/internal/biz/bizutils" + "github.com/tuihub/librarian/internal/lib/libauth" + "github.com/tuihub/librarian/internal/model" + "github.com/tuihub/librarian/internal/model/modelgebura" + pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1" +) + +func (g *Gebura) UpsertSentinelInfo( + ctx context.Context, info *modelgebura.SentinelInfo, +) error { + claims := libauth.FromContextAssertUserType(ctx, model.UserTypeSentinel) + if claims == nil { + return bizutils.NoPermissionError() + } + info.ID = claims.UserID + err := g.repo.UpdateSentinelInfo(ctx, info) + if err != nil { + return pb.ErrorErrorReasonUnspecified("%s", err.Error()) + } + return nil +} + +func (g *Gebura) UpsertAppBinaries( + ctx context.Context, abs []*modelgebura.SentinelAppBinary, +) error { + claims := libauth.FromContextAssertUserType(ctx, model.UserTypeSentinel) + if claims == nil { + return bizutils.NoPermissionError() + } + sentinelID := claims.UserID + err := g.repo.UpsertAppBinaries(ctx, sentinelID, abs) + if err != nil { + return pb.ErrorErrorReasonUnspecified("%s", err.Error()) + } + return nil +} diff --git a/internal/biz/biztiphereth/token.go b/internal/biz/biztiphereth/token.go index afcce8cc..e1ec371c 100644 --- a/internal/biz/biztiphereth/token.go +++ b/internal/biz/biztiphereth/token.go @@ -17,6 +17,9 @@ import ( const accessTokenExpire = time.Hour const refreshTokenExpire = libtime.SevenDays const refreshTokenNeedRefresh = libtime.FiveDays +const sentinelAccessTokenExpire = libtime.ThreeDays +const sentinelRefreshTokenExpire = libtime.ThirtyDays +const sentinelRefreshTokenNeedRefresh = libtime.TwentyTwoDays func (t *Tiphereth) GetToken( ctx context.Context, @@ -168,6 +171,50 @@ func (t *Tiphereth) RefreshToken( //nolint:gocognit // TODO return model.AccessToken(accessToken), model.RefreshToken(refreshToken), nil } +func (t *Tiphereth) SentinelRefreshToken( + ctx context.Context, +) (model.AccessToken, model.RefreshToken, *errors.Error) { + claims := libauth.FromContextAssertUserType(ctx, model.UserTypeSentinel) + if claims == nil { + return "", "", bizutils.NoPermissionError() + } + oldRefreshToken := libauth.RawFromContext(ctx) + if oldRefreshToken == "" { + return "", "", bizutils.NoPermissionError() + } + var err error + var accessToken, refreshToken string + accessToken, err = t.auth.GenerateToken( + claims.UserID, + claims.PorterID, + libauth.ClaimsTypeAccessToken, + claims.UserType, + nil, + sentinelAccessTokenExpire, + ) + if err != nil { + logger.Infof("generate access token failed: %s", err.Error()) + return "", "", pb.ErrorErrorReasonUnspecified("%s", err.Error()) + } + if claims.ExpiresAt.After(time.Now().Add(sentinelRefreshTokenNeedRefresh)) { + refreshToken = oldRefreshToken + } else { + refreshToken, err = t.auth.GenerateToken( + claims.UserID, + claims.PorterID, + libauth.ClaimsTypeRefreshToken, + claims.UserType, + nil, + sentinelRefreshTokenExpire, + ) + if err != nil { + logger.Infof("generate refresh token failed: %s", err.Error()) + return "", "", pb.ErrorErrorReasonUnspecified("%s", err.Error()) + } + } + return model.AccessToken(accessToken), model.RefreshToken(refreshToken), nil +} + func (t *Tiphereth) AcquireUserToken( ctx context.Context, userID model.InternalID, diff --git a/internal/data/gebura.go b/internal/data/gebura.go index 0b03f49f..1a507b28 100644 --- a/internal/data/gebura.go +++ b/internal/data/gebura.go @@ -11,9 +11,16 @@ import ( "github.com/tuihub/librarian/internal/data/internal/ent/appcategory" "github.com/tuihub/librarian/internal/data/internal/ent/appinfo" "github.com/tuihub/librarian/internal/data/internal/ent/appruntime" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" "github.com/tuihub/librarian/internal/data/internal/ent/user" "github.com/tuihub/librarian/internal/model" "github.com/tuihub/librarian/internal/model/modelgebura" + + "entgo.io/ent/dialect/sql" + "github.com/samber/lo" ) type GeburaRepo struct { @@ -534,15 +541,7 @@ func (g *GeburaRepo) CreateAppCategory(ctx context.Context, userID model.Interna AddAppIDs(ac.AppIDs...) return q.Exec(ctx) } -func (g *GeburaRepo) GetAppCategory(ctx context.Context, id model.InternalID) (*modelgebura.AppCategory, error) { - res, err := g.data.db.AppCategory.Query(). - Where(appcategory.IDEQ(id)). - Only(ctx) - if err != nil { - return nil, err - } - return converter.ToBizAppCategory(res), nil -} + func (g *GeburaRepo) ListAppCategories(ctx context.Context, userID model.InternalID) ([]*modelgebura.AppCategory, error) { acs, err := g.data.db.AppCategory.Query(). WithAppAppCategory(). @@ -557,6 +556,7 @@ func (g *GeburaRepo) ListAppCategories(ctx context.Context, userID model.Interna } return res, nil } + func (g *GeburaRepo) UpdateAppCategory( ctx context.Context, userID model.InternalID, @@ -594,6 +594,7 @@ func (g *GeburaRepo) UpdateAppCategory( return q.Exec(ctx) }) } + func (g *GeburaRepo) DeleteAppCategory( ctx context.Context, userID model.InternalID, @@ -616,3 +617,138 @@ func (g *GeburaRepo) DeleteAppCategory( return err }) } + +func (g *GeburaRepo) UpdateSentinelInfo( + ctx context.Context, + info *modelgebura.SentinelInfo, +) error { + return g.data.WithTx(ctx, func(tx *ent.Tx) error { + // update sentinel info + err := tx.SentinelInfo.UpdateOneID(info.ID). + SetURL(info.Url). + SetAlternativeUrls(info.AlternativeUrls). + SetGetTokenPath(info.GetTokenPath). + SetDownloadFileBasePath(info.DownloadFileBasePath). + AddLibraryReportSequence(1). + Exec(ctx) + if err != nil { + return err + } + // upsert libraries + sInfo, err := tx.SentinelInfo.Query(). + Where(sentinelinfo.IDEQ(info.ID)). + Only(ctx) + if err != nil { + return err + } + newLibs := make([]*ent.SentinelLibraryCreate, 0, len(info.Libraries)) + for _, lib := range info.Libraries { + newLibs = append(newLibs, tx.SentinelLibrary.Create(). + SetSentinelInfoID(sInfo.ID). + SetReportedID(lib.ReportedID). + SetDownloadBasePath(lib.DownloadBasePath). + SetLibraryReportSequence(sInfo.LibraryReportSequence), + ) + } + return tx.SentinelLibrary.CreateBulk(newLibs...). + OnConflict( + sql.ConflictColumns( + sentinellibrary.FieldSentinelInfoID, + sentinellibrary.FieldReportedID, + ), + ). + UpdateNewValues(). + Exec(ctx) + }) +} + +func (g *GeburaRepo) UpsertAppBinaries( + ctx context.Context, + sentinelID model.InternalID, + abs []*modelgebura.SentinelAppBinary, +) error { + return g.data.WithTx(ctx, func(tx *ent.Tx) error { + // update AppBinaryReportSequence + err := tx.SentinelInfo.UpdateOneID(sentinelID). + AddAppBinaryReportSequence(1). + Exec(ctx) + if err != nil { + return err + } + sInfo, err := tx.SentinelInfo.Query(). + Where(sentinelinfo.IDEQ(sentinelID)). + WithSentinelLibrary(). + Only(ctx) + if err != nil { + return err + } + // upsert binaries + newAbs := make([]*ent.SentinelAppBinaryCreate, 0, len(abs)) + for _, ab := range abs { + newAbs = append(newAbs, tx.SentinelAppBinary.Create(). + SetSentinelInfoID(sentinelID). + SetSentinelLibraryReportedID(ab.SentinelLibraryID). + SetGeneratedID(ab.GeneratedID). + SetSizeBytes(ab.SizeBytes). + SetNeedToken(ab.NeedToken). + SetName(ab.Name). + SetVersion(ab.Version). + SetDeveloper(ab.Developer). + SetPublisher(ab.Publisher). + SetAppBinaryReportSequence(sInfo.AppBinaryReportSequence)) + } + err = tx.SentinelAppBinary.CreateBulk(newAbs...). + OnConflict( + sql.ConflictColumns( + sentinelappbinary.FieldSentinelInfoID, + sentinelappbinary.FieldSentinelLibraryReportedID, + sentinelappbinary.FieldGeneratedID, + ), + resolveWithIgnores([]string{ + sentinelappbinary.FieldID, + }), + ). + UpdateNewValues(). + Exec(ctx) + if err != nil { + return err + } + // upsert binary files + abfCount := lo.Sum(lo.Map(abs, func(ab *modelgebura.SentinelAppBinary, _ int) int { + return len(ab.Files) + })) + newAbfs := make([]*ent.SentinelAppBinaryFileCreate, 0, abfCount) + for _, ab := range abs { + for _, f := range ab.Files { + newAbfs = append(newAbfs, tx.SentinelAppBinaryFile.Create(). + SetSentinelInfoID(sentinelID). + SetSentinelLibraryReportedID(ab.SentinelLibraryID). + SetSentinelAppBinaryGeneratedID(ab.GeneratedID). + SetName(f.Name). + SetSizeBytes(f.SizeBytes). + SetSha256(f.Sha256). + SetServerFilePath(f.ServerFilePath). + SetChunksInfo(f.ChunksInfo). + SetAppBinaryReportSequence(sInfo.AppBinaryReportSequence)) + } + } + err = tx.SentinelAppBinaryFile.CreateBulk(newAbfs...). + OnConflict( + sql.ConflictColumns( + sentinelappbinaryfile.FieldSentinelInfoID, + sentinelappbinaryfile.FieldSentinelLibraryReportedID, + sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID, + sentinelappbinaryfile.FieldServerFilePath, + ), + resolveWithIgnores([]string{ + sentinelappbinaryfile.FieldID, + }), + ). + UpdateNewValues(). + Exec(ctx) + if err != nil { + return err + } + return nil + }) +} diff --git a/internal/data/internal/ent/client.go b/internal/data/internal/ent/client.go index d2657bca..f6e85bd4 100644 --- a/internal/data/internal/ent/client.go +++ b/internal/data/internal/ent/client.go @@ -38,6 +38,10 @@ import ( "github.com/tuihub/librarian/internal/data/internal/ent/notifytarget" "github.com/tuihub/librarian/internal/data/internal/ent/portercontext" "github.com/tuihub/librarian/internal/data/internal/ent/porterinstance" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" "github.com/tuihub/librarian/internal/data/internal/ent/session" "github.com/tuihub/librarian/internal/data/internal/ent/storeapp" "github.com/tuihub/librarian/internal/data/internal/ent/storeappbinary" @@ -95,6 +99,14 @@ type Client struct { PorterContext *PorterContextClient // PorterInstance is the client for interacting with the PorterInstance builders. PorterInstance *PorterInstanceClient + // SentinelAppBinary is the client for interacting with the SentinelAppBinary builders. + SentinelAppBinary *SentinelAppBinaryClient + // SentinelAppBinaryFile is the client for interacting with the SentinelAppBinaryFile builders. + SentinelAppBinaryFile *SentinelAppBinaryFileClient + // SentinelInfo is the client for interacting with the SentinelInfo builders. + SentinelInfo *SentinelInfoClient + // SentinelLibrary is the client for interacting with the SentinelLibrary builders. + SentinelLibrary *SentinelLibraryClient // Session is the client for interacting with the Session builders. Session *SessionClient // StoreApp is the client for interacting with the StoreApp builders. @@ -140,6 +152,10 @@ func (c *Client) init() { c.NotifyTarget = NewNotifyTargetClient(c.config) c.PorterContext = NewPorterContextClient(c.config) c.PorterInstance = NewPorterInstanceClient(c.config) + c.SentinelAppBinary = NewSentinelAppBinaryClient(c.config) + c.SentinelAppBinaryFile = NewSentinelAppBinaryFileClient(c.config) + c.SentinelInfo = NewSentinelInfoClient(c.config) + c.SentinelLibrary = NewSentinelLibraryClient(c.config) c.Session = NewSessionClient(c.config) c.StoreApp = NewStoreAppClient(c.config) c.StoreAppBinary = NewStoreAppBinaryClient(c.config) @@ -236,36 +252,40 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { cfg := c.config cfg.driver = tx return &Tx{ - ctx: ctx, - config: cfg, - Account: NewAccountClient(cfg), - App: NewAppClient(cfg), - AppAppCategory: NewAppAppCategoryClient(cfg), - AppCategory: NewAppCategoryClient(cfg), - AppInfo: NewAppInfoClient(cfg), - AppRunTime: NewAppRunTimeClient(cfg), - Device: NewDeviceClient(cfg), - Feed: NewFeedClient(cfg), - FeedActionSet: NewFeedActionSetClient(cfg), - FeedConfig: NewFeedConfigClient(cfg), - FeedConfigAction: NewFeedConfigActionClient(cfg), - FeedItem: NewFeedItemClient(cfg), - FeedItemCollection: NewFeedItemCollectionClient(cfg), - File: NewFileClient(cfg), - Image: NewImageClient(cfg), - NotifyFlow: NewNotifyFlowClient(cfg), - NotifyFlowSource: NewNotifyFlowSourceClient(cfg), - NotifyFlowTarget: NewNotifyFlowTargetClient(cfg), - NotifySource: NewNotifySourceClient(cfg), - NotifyTarget: NewNotifyTargetClient(cfg), - PorterContext: NewPorterContextClient(cfg), - PorterInstance: NewPorterInstanceClient(cfg), - Session: NewSessionClient(cfg), - StoreApp: NewStoreAppClient(cfg), - StoreAppBinary: NewStoreAppBinaryClient(cfg), - SystemNotification: NewSystemNotificationClient(cfg), - Tag: NewTagClient(cfg), - User: NewUserClient(cfg), + ctx: ctx, + config: cfg, + Account: NewAccountClient(cfg), + App: NewAppClient(cfg), + AppAppCategory: NewAppAppCategoryClient(cfg), + AppCategory: NewAppCategoryClient(cfg), + AppInfo: NewAppInfoClient(cfg), + AppRunTime: NewAppRunTimeClient(cfg), + Device: NewDeviceClient(cfg), + Feed: NewFeedClient(cfg), + FeedActionSet: NewFeedActionSetClient(cfg), + FeedConfig: NewFeedConfigClient(cfg), + FeedConfigAction: NewFeedConfigActionClient(cfg), + FeedItem: NewFeedItemClient(cfg), + FeedItemCollection: NewFeedItemCollectionClient(cfg), + File: NewFileClient(cfg), + Image: NewImageClient(cfg), + NotifyFlow: NewNotifyFlowClient(cfg), + NotifyFlowSource: NewNotifyFlowSourceClient(cfg), + NotifyFlowTarget: NewNotifyFlowTargetClient(cfg), + NotifySource: NewNotifySourceClient(cfg), + NotifyTarget: NewNotifyTargetClient(cfg), + PorterContext: NewPorterContextClient(cfg), + PorterInstance: NewPorterInstanceClient(cfg), + SentinelAppBinary: NewSentinelAppBinaryClient(cfg), + SentinelAppBinaryFile: NewSentinelAppBinaryFileClient(cfg), + SentinelInfo: NewSentinelInfoClient(cfg), + SentinelLibrary: NewSentinelLibraryClient(cfg), + Session: NewSessionClient(cfg), + StoreApp: NewStoreAppClient(cfg), + StoreAppBinary: NewStoreAppBinaryClient(cfg), + SystemNotification: NewSystemNotificationClient(cfg), + Tag: NewTagClient(cfg), + User: NewUserClient(cfg), }, nil } @@ -283,36 +303,40 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) cfg := c.config cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ - ctx: ctx, - config: cfg, - Account: NewAccountClient(cfg), - App: NewAppClient(cfg), - AppAppCategory: NewAppAppCategoryClient(cfg), - AppCategory: NewAppCategoryClient(cfg), - AppInfo: NewAppInfoClient(cfg), - AppRunTime: NewAppRunTimeClient(cfg), - Device: NewDeviceClient(cfg), - Feed: NewFeedClient(cfg), - FeedActionSet: NewFeedActionSetClient(cfg), - FeedConfig: NewFeedConfigClient(cfg), - FeedConfigAction: NewFeedConfigActionClient(cfg), - FeedItem: NewFeedItemClient(cfg), - FeedItemCollection: NewFeedItemCollectionClient(cfg), - File: NewFileClient(cfg), - Image: NewImageClient(cfg), - NotifyFlow: NewNotifyFlowClient(cfg), - NotifyFlowSource: NewNotifyFlowSourceClient(cfg), - NotifyFlowTarget: NewNotifyFlowTargetClient(cfg), - NotifySource: NewNotifySourceClient(cfg), - NotifyTarget: NewNotifyTargetClient(cfg), - PorterContext: NewPorterContextClient(cfg), - PorterInstance: NewPorterInstanceClient(cfg), - Session: NewSessionClient(cfg), - StoreApp: NewStoreAppClient(cfg), - StoreAppBinary: NewStoreAppBinaryClient(cfg), - SystemNotification: NewSystemNotificationClient(cfg), - Tag: NewTagClient(cfg), - User: NewUserClient(cfg), + ctx: ctx, + config: cfg, + Account: NewAccountClient(cfg), + App: NewAppClient(cfg), + AppAppCategory: NewAppAppCategoryClient(cfg), + AppCategory: NewAppCategoryClient(cfg), + AppInfo: NewAppInfoClient(cfg), + AppRunTime: NewAppRunTimeClient(cfg), + Device: NewDeviceClient(cfg), + Feed: NewFeedClient(cfg), + FeedActionSet: NewFeedActionSetClient(cfg), + FeedConfig: NewFeedConfigClient(cfg), + FeedConfigAction: NewFeedConfigActionClient(cfg), + FeedItem: NewFeedItemClient(cfg), + FeedItemCollection: NewFeedItemCollectionClient(cfg), + File: NewFileClient(cfg), + Image: NewImageClient(cfg), + NotifyFlow: NewNotifyFlowClient(cfg), + NotifyFlowSource: NewNotifyFlowSourceClient(cfg), + NotifyFlowTarget: NewNotifyFlowTargetClient(cfg), + NotifySource: NewNotifySourceClient(cfg), + NotifyTarget: NewNotifyTargetClient(cfg), + PorterContext: NewPorterContextClient(cfg), + PorterInstance: NewPorterInstanceClient(cfg), + SentinelAppBinary: NewSentinelAppBinaryClient(cfg), + SentinelAppBinaryFile: NewSentinelAppBinaryFileClient(cfg), + SentinelInfo: NewSentinelInfoClient(cfg), + SentinelLibrary: NewSentinelLibraryClient(cfg), + Session: NewSessionClient(cfg), + StoreApp: NewStoreAppClient(cfg), + StoreAppBinary: NewStoreAppBinaryClient(cfg), + SystemNotification: NewSystemNotificationClient(cfg), + Tag: NewTagClient(cfg), + User: NewUserClient(cfg), }, nil } @@ -346,8 +370,9 @@ func (c *Client) Use(hooks ...Hook) { c.Device, c.Feed, c.FeedActionSet, c.FeedConfig, c.FeedConfigAction, c.FeedItem, c.FeedItemCollection, c.File, c.Image, c.NotifyFlow, c.NotifyFlowSource, c.NotifyFlowTarget, c.NotifySource, c.NotifyTarget, - c.PorterContext, c.PorterInstance, c.Session, c.StoreApp, c.StoreAppBinary, - c.SystemNotification, c.Tag, c.User, + c.PorterContext, c.PorterInstance, c.SentinelAppBinary, + c.SentinelAppBinaryFile, c.SentinelInfo, c.SentinelLibrary, c.Session, + c.StoreApp, c.StoreAppBinary, c.SystemNotification, c.Tag, c.User, } { n.Use(hooks...) } @@ -361,8 +386,9 @@ func (c *Client) Intercept(interceptors ...Interceptor) { c.Device, c.Feed, c.FeedActionSet, c.FeedConfig, c.FeedConfigAction, c.FeedItem, c.FeedItemCollection, c.File, c.Image, c.NotifyFlow, c.NotifyFlowSource, c.NotifyFlowTarget, c.NotifySource, c.NotifyTarget, - c.PorterContext, c.PorterInstance, c.Session, c.StoreApp, c.StoreAppBinary, - c.SystemNotification, c.Tag, c.User, + c.PorterContext, c.PorterInstance, c.SentinelAppBinary, + c.SentinelAppBinaryFile, c.SentinelInfo, c.SentinelLibrary, c.Session, + c.StoreApp, c.StoreAppBinary, c.SystemNotification, c.Tag, c.User, } { n.Intercept(interceptors...) } @@ -415,6 +441,14 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.PorterContext.mutate(ctx, m) case *PorterInstanceMutation: return c.PorterInstance.mutate(ctx, m) + case *SentinelAppBinaryMutation: + return c.SentinelAppBinary.mutate(ctx, m) + case *SentinelAppBinaryFileMutation: + return c.SentinelAppBinaryFile.mutate(ctx, m) + case *SentinelInfoMutation: + return c.SentinelInfo.mutate(ctx, m) + case *SentinelLibraryMutation: + return c.SentinelLibrary.mutate(ctx, m) case *SessionMutation: return c.Session.mutate(ctx, m) case *StoreAppMutation: @@ -4174,6 +4208,570 @@ func (c *PorterInstanceClient) mutate(ctx context.Context, m *PorterInstanceMuta } } +// SentinelAppBinaryClient is a client for the SentinelAppBinary schema. +type SentinelAppBinaryClient struct { + config +} + +// NewSentinelAppBinaryClient returns a client for the SentinelAppBinary from the given config. +func NewSentinelAppBinaryClient(c config) *SentinelAppBinaryClient { + return &SentinelAppBinaryClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `sentinelappbinary.Hooks(f(g(h())))`. +func (c *SentinelAppBinaryClient) Use(hooks ...Hook) { + c.hooks.SentinelAppBinary = append(c.hooks.SentinelAppBinary, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `sentinelappbinary.Intercept(f(g(h())))`. +func (c *SentinelAppBinaryClient) Intercept(interceptors ...Interceptor) { + c.inters.SentinelAppBinary = append(c.inters.SentinelAppBinary, interceptors...) +} + +// Create returns a builder for creating a SentinelAppBinary entity. +func (c *SentinelAppBinaryClient) Create() *SentinelAppBinaryCreate { + mutation := newSentinelAppBinaryMutation(c.config, OpCreate) + return &SentinelAppBinaryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of SentinelAppBinary entities. +func (c *SentinelAppBinaryClient) CreateBulk(builders ...*SentinelAppBinaryCreate) *SentinelAppBinaryCreateBulk { + return &SentinelAppBinaryCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *SentinelAppBinaryClient) MapCreateBulk(slice any, setFunc func(*SentinelAppBinaryCreate, int)) *SentinelAppBinaryCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &SentinelAppBinaryCreateBulk{err: fmt.Errorf("calling to SentinelAppBinaryClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*SentinelAppBinaryCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &SentinelAppBinaryCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for SentinelAppBinary. +func (c *SentinelAppBinaryClient) Update() *SentinelAppBinaryUpdate { + mutation := newSentinelAppBinaryMutation(c.config, OpUpdate) + return &SentinelAppBinaryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *SentinelAppBinaryClient) UpdateOne(sab *SentinelAppBinary) *SentinelAppBinaryUpdateOne { + mutation := newSentinelAppBinaryMutation(c.config, OpUpdateOne, withSentinelAppBinary(sab)) + return &SentinelAppBinaryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *SentinelAppBinaryClient) UpdateOneID(id int) *SentinelAppBinaryUpdateOne { + mutation := newSentinelAppBinaryMutation(c.config, OpUpdateOne, withSentinelAppBinaryID(id)) + return &SentinelAppBinaryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for SentinelAppBinary. +func (c *SentinelAppBinaryClient) Delete() *SentinelAppBinaryDelete { + mutation := newSentinelAppBinaryMutation(c.config, OpDelete) + return &SentinelAppBinaryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *SentinelAppBinaryClient) DeleteOne(sab *SentinelAppBinary) *SentinelAppBinaryDeleteOne { + return c.DeleteOneID(sab.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *SentinelAppBinaryClient) DeleteOneID(id int) *SentinelAppBinaryDeleteOne { + builder := c.Delete().Where(sentinelappbinary.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &SentinelAppBinaryDeleteOne{builder} +} + +// Query returns a query builder for SentinelAppBinary. +func (c *SentinelAppBinaryClient) Query() *SentinelAppBinaryQuery { + return &SentinelAppBinaryQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeSentinelAppBinary}, + inters: c.Interceptors(), + } +} + +// Get returns a SentinelAppBinary entity by its id. +func (c *SentinelAppBinaryClient) Get(ctx context.Context, id int) (*SentinelAppBinary, error) { + return c.Query().Where(sentinelappbinary.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *SentinelAppBinaryClient) GetX(ctx context.Context, id int) *SentinelAppBinary { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *SentinelAppBinaryClient) Hooks() []Hook { + return c.hooks.SentinelAppBinary +} + +// Interceptors returns the client interceptors. +func (c *SentinelAppBinaryClient) Interceptors() []Interceptor { + return c.inters.SentinelAppBinary +} + +func (c *SentinelAppBinaryClient) mutate(ctx context.Context, m *SentinelAppBinaryMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&SentinelAppBinaryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&SentinelAppBinaryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&SentinelAppBinaryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&SentinelAppBinaryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown SentinelAppBinary mutation op: %q", m.Op()) + } +} + +// SentinelAppBinaryFileClient is a client for the SentinelAppBinaryFile schema. +type SentinelAppBinaryFileClient struct { + config +} + +// NewSentinelAppBinaryFileClient returns a client for the SentinelAppBinaryFile from the given config. +func NewSentinelAppBinaryFileClient(c config) *SentinelAppBinaryFileClient { + return &SentinelAppBinaryFileClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `sentinelappbinaryfile.Hooks(f(g(h())))`. +func (c *SentinelAppBinaryFileClient) Use(hooks ...Hook) { + c.hooks.SentinelAppBinaryFile = append(c.hooks.SentinelAppBinaryFile, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `sentinelappbinaryfile.Intercept(f(g(h())))`. +func (c *SentinelAppBinaryFileClient) Intercept(interceptors ...Interceptor) { + c.inters.SentinelAppBinaryFile = append(c.inters.SentinelAppBinaryFile, interceptors...) +} + +// Create returns a builder for creating a SentinelAppBinaryFile entity. +func (c *SentinelAppBinaryFileClient) Create() *SentinelAppBinaryFileCreate { + mutation := newSentinelAppBinaryFileMutation(c.config, OpCreate) + return &SentinelAppBinaryFileCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of SentinelAppBinaryFile entities. +func (c *SentinelAppBinaryFileClient) CreateBulk(builders ...*SentinelAppBinaryFileCreate) *SentinelAppBinaryFileCreateBulk { + return &SentinelAppBinaryFileCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *SentinelAppBinaryFileClient) MapCreateBulk(slice any, setFunc func(*SentinelAppBinaryFileCreate, int)) *SentinelAppBinaryFileCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &SentinelAppBinaryFileCreateBulk{err: fmt.Errorf("calling to SentinelAppBinaryFileClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*SentinelAppBinaryFileCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &SentinelAppBinaryFileCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for SentinelAppBinaryFile. +func (c *SentinelAppBinaryFileClient) Update() *SentinelAppBinaryFileUpdate { + mutation := newSentinelAppBinaryFileMutation(c.config, OpUpdate) + return &SentinelAppBinaryFileUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *SentinelAppBinaryFileClient) UpdateOne(sabf *SentinelAppBinaryFile) *SentinelAppBinaryFileUpdateOne { + mutation := newSentinelAppBinaryFileMutation(c.config, OpUpdateOne, withSentinelAppBinaryFile(sabf)) + return &SentinelAppBinaryFileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *SentinelAppBinaryFileClient) UpdateOneID(id int) *SentinelAppBinaryFileUpdateOne { + mutation := newSentinelAppBinaryFileMutation(c.config, OpUpdateOne, withSentinelAppBinaryFileID(id)) + return &SentinelAppBinaryFileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for SentinelAppBinaryFile. +func (c *SentinelAppBinaryFileClient) Delete() *SentinelAppBinaryFileDelete { + mutation := newSentinelAppBinaryFileMutation(c.config, OpDelete) + return &SentinelAppBinaryFileDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *SentinelAppBinaryFileClient) DeleteOne(sabf *SentinelAppBinaryFile) *SentinelAppBinaryFileDeleteOne { + return c.DeleteOneID(sabf.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *SentinelAppBinaryFileClient) DeleteOneID(id int) *SentinelAppBinaryFileDeleteOne { + builder := c.Delete().Where(sentinelappbinaryfile.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &SentinelAppBinaryFileDeleteOne{builder} +} + +// Query returns a query builder for SentinelAppBinaryFile. +func (c *SentinelAppBinaryFileClient) Query() *SentinelAppBinaryFileQuery { + return &SentinelAppBinaryFileQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeSentinelAppBinaryFile}, + inters: c.Interceptors(), + } +} + +// Get returns a SentinelAppBinaryFile entity by its id. +func (c *SentinelAppBinaryFileClient) Get(ctx context.Context, id int) (*SentinelAppBinaryFile, error) { + return c.Query().Where(sentinelappbinaryfile.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *SentinelAppBinaryFileClient) GetX(ctx context.Context, id int) *SentinelAppBinaryFile { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *SentinelAppBinaryFileClient) Hooks() []Hook { + return c.hooks.SentinelAppBinaryFile +} + +// Interceptors returns the client interceptors. +func (c *SentinelAppBinaryFileClient) Interceptors() []Interceptor { + return c.inters.SentinelAppBinaryFile +} + +func (c *SentinelAppBinaryFileClient) mutate(ctx context.Context, m *SentinelAppBinaryFileMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&SentinelAppBinaryFileCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&SentinelAppBinaryFileUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&SentinelAppBinaryFileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&SentinelAppBinaryFileDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown SentinelAppBinaryFile mutation op: %q", m.Op()) + } +} + +// SentinelInfoClient is a client for the SentinelInfo schema. +type SentinelInfoClient struct { + config +} + +// NewSentinelInfoClient returns a client for the SentinelInfo from the given config. +func NewSentinelInfoClient(c config) *SentinelInfoClient { + return &SentinelInfoClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `sentinelinfo.Hooks(f(g(h())))`. +func (c *SentinelInfoClient) Use(hooks ...Hook) { + c.hooks.SentinelInfo = append(c.hooks.SentinelInfo, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `sentinelinfo.Intercept(f(g(h())))`. +func (c *SentinelInfoClient) Intercept(interceptors ...Interceptor) { + c.inters.SentinelInfo = append(c.inters.SentinelInfo, interceptors...) +} + +// Create returns a builder for creating a SentinelInfo entity. +func (c *SentinelInfoClient) Create() *SentinelInfoCreate { + mutation := newSentinelInfoMutation(c.config, OpCreate) + return &SentinelInfoCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of SentinelInfo entities. +func (c *SentinelInfoClient) CreateBulk(builders ...*SentinelInfoCreate) *SentinelInfoCreateBulk { + return &SentinelInfoCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *SentinelInfoClient) MapCreateBulk(slice any, setFunc func(*SentinelInfoCreate, int)) *SentinelInfoCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &SentinelInfoCreateBulk{err: fmt.Errorf("calling to SentinelInfoClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*SentinelInfoCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &SentinelInfoCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for SentinelInfo. +func (c *SentinelInfoClient) Update() *SentinelInfoUpdate { + mutation := newSentinelInfoMutation(c.config, OpUpdate) + return &SentinelInfoUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *SentinelInfoClient) UpdateOne(si *SentinelInfo) *SentinelInfoUpdateOne { + mutation := newSentinelInfoMutation(c.config, OpUpdateOne, withSentinelInfo(si)) + return &SentinelInfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *SentinelInfoClient) UpdateOneID(id model.InternalID) *SentinelInfoUpdateOne { + mutation := newSentinelInfoMutation(c.config, OpUpdateOne, withSentinelInfoID(id)) + return &SentinelInfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for SentinelInfo. +func (c *SentinelInfoClient) Delete() *SentinelInfoDelete { + mutation := newSentinelInfoMutation(c.config, OpDelete) + return &SentinelInfoDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *SentinelInfoClient) DeleteOne(si *SentinelInfo) *SentinelInfoDeleteOne { + return c.DeleteOneID(si.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *SentinelInfoClient) DeleteOneID(id model.InternalID) *SentinelInfoDeleteOne { + builder := c.Delete().Where(sentinelinfo.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &SentinelInfoDeleteOne{builder} +} + +// Query returns a query builder for SentinelInfo. +func (c *SentinelInfoClient) Query() *SentinelInfoQuery { + return &SentinelInfoQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeSentinelInfo}, + inters: c.Interceptors(), + } +} + +// Get returns a SentinelInfo entity by its id. +func (c *SentinelInfoClient) Get(ctx context.Context, id model.InternalID) (*SentinelInfo, error) { + return c.Query().Where(sentinelinfo.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *SentinelInfoClient) GetX(ctx context.Context, id model.InternalID) *SentinelInfo { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QuerySentinelLibrary queries the sentinel_library edge of a SentinelInfo. +func (c *SentinelInfoClient) QuerySentinelLibrary(si *SentinelInfo) *SentinelLibraryQuery { + query := (&SentinelLibraryClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := si.ID + step := sqlgraph.NewStep( + sqlgraph.From(sentinelinfo.Table, sentinelinfo.FieldID, id), + sqlgraph.To(sentinellibrary.Table, sentinellibrary.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, sentinelinfo.SentinelLibraryTable, sentinelinfo.SentinelLibraryColumn), + ) + fromV = sqlgraph.Neighbors(si.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *SentinelInfoClient) Hooks() []Hook { + return c.hooks.SentinelInfo +} + +// Interceptors returns the client interceptors. +func (c *SentinelInfoClient) Interceptors() []Interceptor { + return c.inters.SentinelInfo +} + +func (c *SentinelInfoClient) mutate(ctx context.Context, m *SentinelInfoMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&SentinelInfoCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&SentinelInfoUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&SentinelInfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&SentinelInfoDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown SentinelInfo mutation op: %q", m.Op()) + } +} + +// SentinelLibraryClient is a client for the SentinelLibrary schema. +type SentinelLibraryClient struct { + config +} + +// NewSentinelLibraryClient returns a client for the SentinelLibrary from the given config. +func NewSentinelLibraryClient(c config) *SentinelLibraryClient { + return &SentinelLibraryClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `sentinellibrary.Hooks(f(g(h())))`. +func (c *SentinelLibraryClient) Use(hooks ...Hook) { + c.hooks.SentinelLibrary = append(c.hooks.SentinelLibrary, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `sentinellibrary.Intercept(f(g(h())))`. +func (c *SentinelLibraryClient) Intercept(interceptors ...Interceptor) { + c.inters.SentinelLibrary = append(c.inters.SentinelLibrary, interceptors...) +} + +// Create returns a builder for creating a SentinelLibrary entity. +func (c *SentinelLibraryClient) Create() *SentinelLibraryCreate { + mutation := newSentinelLibraryMutation(c.config, OpCreate) + return &SentinelLibraryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of SentinelLibrary entities. +func (c *SentinelLibraryClient) CreateBulk(builders ...*SentinelLibraryCreate) *SentinelLibraryCreateBulk { + return &SentinelLibraryCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *SentinelLibraryClient) MapCreateBulk(slice any, setFunc func(*SentinelLibraryCreate, int)) *SentinelLibraryCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &SentinelLibraryCreateBulk{err: fmt.Errorf("calling to SentinelLibraryClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*SentinelLibraryCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &SentinelLibraryCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for SentinelLibrary. +func (c *SentinelLibraryClient) Update() *SentinelLibraryUpdate { + mutation := newSentinelLibraryMutation(c.config, OpUpdate) + return &SentinelLibraryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *SentinelLibraryClient) UpdateOne(sl *SentinelLibrary) *SentinelLibraryUpdateOne { + mutation := newSentinelLibraryMutation(c.config, OpUpdateOne, withSentinelLibrary(sl)) + return &SentinelLibraryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *SentinelLibraryClient) UpdateOneID(id int) *SentinelLibraryUpdateOne { + mutation := newSentinelLibraryMutation(c.config, OpUpdateOne, withSentinelLibraryID(id)) + return &SentinelLibraryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for SentinelLibrary. +func (c *SentinelLibraryClient) Delete() *SentinelLibraryDelete { + mutation := newSentinelLibraryMutation(c.config, OpDelete) + return &SentinelLibraryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *SentinelLibraryClient) DeleteOne(sl *SentinelLibrary) *SentinelLibraryDeleteOne { + return c.DeleteOneID(sl.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *SentinelLibraryClient) DeleteOneID(id int) *SentinelLibraryDeleteOne { + builder := c.Delete().Where(sentinellibrary.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &SentinelLibraryDeleteOne{builder} +} + +// Query returns a query builder for SentinelLibrary. +func (c *SentinelLibraryClient) Query() *SentinelLibraryQuery { + return &SentinelLibraryQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeSentinelLibrary}, + inters: c.Interceptors(), + } +} + +// Get returns a SentinelLibrary entity by its id. +func (c *SentinelLibraryClient) Get(ctx context.Context, id int) (*SentinelLibrary, error) { + return c.Query().Where(sentinellibrary.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *SentinelLibraryClient) GetX(ctx context.Context, id int) *SentinelLibrary { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QuerySentinelInfo queries the sentinel_info edge of a SentinelLibrary. +func (c *SentinelLibraryClient) QuerySentinelInfo(sl *SentinelLibrary) *SentinelInfoQuery { + query := (&SentinelInfoClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := sl.ID + step := sqlgraph.NewStep( + sqlgraph.From(sentinellibrary.Table, sentinellibrary.FieldID, id), + sqlgraph.To(sentinelinfo.Table, sentinelinfo.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, sentinellibrary.SentinelInfoTable, sentinellibrary.SentinelInfoColumn), + ) + fromV = sqlgraph.Neighbors(sl.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *SentinelLibraryClient) Hooks() []Hook { + return c.hooks.SentinelLibrary +} + +// Interceptors returns the client interceptors. +func (c *SentinelLibraryClient) Interceptors() []Interceptor { + return c.inters.SentinelLibrary +} + +func (c *SentinelLibraryClient) mutate(ctx context.Context, m *SentinelLibraryMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&SentinelLibraryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&SentinelLibraryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&SentinelLibraryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&SentinelLibraryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown SentinelLibrary mutation op: %q", m.Op()) + } +} + // SessionClient is a client for the Session schema. type SessionClient struct { config @@ -5266,14 +5864,16 @@ type ( Account, App, AppAppCategory, AppCategory, AppInfo, AppRunTime, Device, Feed, FeedActionSet, FeedConfig, FeedConfigAction, FeedItem, FeedItemCollection, File, Image, NotifyFlow, NotifyFlowSource, NotifyFlowTarget, NotifySource, - NotifyTarget, PorterContext, PorterInstance, Session, StoreApp, StoreAppBinary, - SystemNotification, Tag, User []ent.Hook + NotifyTarget, PorterContext, PorterInstance, SentinelAppBinary, + SentinelAppBinaryFile, SentinelInfo, SentinelLibrary, Session, StoreApp, + StoreAppBinary, SystemNotification, Tag, User []ent.Hook } inters struct { Account, App, AppAppCategory, AppCategory, AppInfo, AppRunTime, Device, Feed, FeedActionSet, FeedConfig, FeedConfigAction, FeedItem, FeedItemCollection, File, Image, NotifyFlow, NotifyFlowSource, NotifyFlowTarget, NotifySource, - NotifyTarget, PorterContext, PorterInstance, Session, StoreApp, StoreAppBinary, - SystemNotification, Tag, User []ent.Interceptor + NotifyTarget, PorterContext, PorterInstance, SentinelAppBinary, + SentinelAppBinaryFile, SentinelInfo, SentinelLibrary, Session, StoreApp, + StoreAppBinary, SystemNotification, Tag, User []ent.Interceptor } ) diff --git a/internal/data/internal/ent/ent.go b/internal/data/internal/ent/ent.go index e6fd38df..a4c8a683 100644 --- a/internal/data/internal/ent/ent.go +++ b/internal/data/internal/ent/ent.go @@ -34,6 +34,10 @@ import ( "github.com/tuihub/librarian/internal/data/internal/ent/notifytarget" "github.com/tuihub/librarian/internal/data/internal/ent/portercontext" "github.com/tuihub/librarian/internal/data/internal/ent/porterinstance" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" "github.com/tuihub/librarian/internal/data/internal/ent/session" "github.com/tuihub/librarian/internal/data/internal/ent/storeapp" "github.com/tuihub/librarian/internal/data/internal/ent/storeappbinary" @@ -100,34 +104,38 @@ var ( func checkColumn(table, column string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ - account.Table: account.ValidColumn, - app.Table: app.ValidColumn, - appappcategory.Table: appappcategory.ValidColumn, - appcategory.Table: appcategory.ValidColumn, - appinfo.Table: appinfo.ValidColumn, - appruntime.Table: appruntime.ValidColumn, - device.Table: device.ValidColumn, - feed.Table: feed.ValidColumn, - feedactionset.Table: feedactionset.ValidColumn, - feedconfig.Table: feedconfig.ValidColumn, - feedconfigaction.Table: feedconfigaction.ValidColumn, - feeditem.Table: feeditem.ValidColumn, - feeditemcollection.Table: feeditemcollection.ValidColumn, - file.Table: file.ValidColumn, - image.Table: image.ValidColumn, - notifyflow.Table: notifyflow.ValidColumn, - notifyflowsource.Table: notifyflowsource.ValidColumn, - notifyflowtarget.Table: notifyflowtarget.ValidColumn, - notifysource.Table: notifysource.ValidColumn, - notifytarget.Table: notifytarget.ValidColumn, - portercontext.Table: portercontext.ValidColumn, - porterinstance.Table: porterinstance.ValidColumn, - session.Table: session.ValidColumn, - storeapp.Table: storeapp.ValidColumn, - storeappbinary.Table: storeappbinary.ValidColumn, - systemnotification.Table: systemnotification.ValidColumn, - tag.Table: tag.ValidColumn, - user.Table: user.ValidColumn, + account.Table: account.ValidColumn, + app.Table: app.ValidColumn, + appappcategory.Table: appappcategory.ValidColumn, + appcategory.Table: appcategory.ValidColumn, + appinfo.Table: appinfo.ValidColumn, + appruntime.Table: appruntime.ValidColumn, + device.Table: device.ValidColumn, + feed.Table: feed.ValidColumn, + feedactionset.Table: feedactionset.ValidColumn, + feedconfig.Table: feedconfig.ValidColumn, + feedconfigaction.Table: feedconfigaction.ValidColumn, + feeditem.Table: feeditem.ValidColumn, + feeditemcollection.Table: feeditemcollection.ValidColumn, + file.Table: file.ValidColumn, + image.Table: image.ValidColumn, + notifyflow.Table: notifyflow.ValidColumn, + notifyflowsource.Table: notifyflowsource.ValidColumn, + notifyflowtarget.Table: notifyflowtarget.ValidColumn, + notifysource.Table: notifysource.ValidColumn, + notifytarget.Table: notifytarget.ValidColumn, + portercontext.Table: portercontext.ValidColumn, + porterinstance.Table: porterinstance.ValidColumn, + sentinelappbinary.Table: sentinelappbinary.ValidColumn, + sentinelappbinaryfile.Table: sentinelappbinaryfile.ValidColumn, + sentinelinfo.Table: sentinelinfo.ValidColumn, + sentinellibrary.Table: sentinellibrary.ValidColumn, + session.Table: session.ValidColumn, + storeapp.Table: storeapp.ValidColumn, + storeappbinary.Table: storeappbinary.ValidColumn, + systemnotification.Table: systemnotification.ValidColumn, + tag.Table: tag.ValidColumn, + user.Table: user.ValidColumn, }) }) return columnCheck(table, column) diff --git a/internal/data/internal/ent/hook/hook.go b/internal/data/internal/ent/hook/hook.go index 4f933b73..9140e995 100644 --- a/internal/data/internal/ent/hook/hook.go +++ b/internal/data/internal/ent/hook/hook.go @@ -273,6 +273,54 @@ func (f PorterInstanceFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Val return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PorterInstanceMutation", m) } +// The SentinelAppBinaryFunc type is an adapter to allow the use of ordinary +// function as SentinelAppBinary mutator. +type SentinelAppBinaryFunc func(context.Context, *ent.SentinelAppBinaryMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f SentinelAppBinaryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.SentinelAppBinaryMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SentinelAppBinaryMutation", m) +} + +// The SentinelAppBinaryFileFunc type is an adapter to allow the use of ordinary +// function as SentinelAppBinaryFile mutator. +type SentinelAppBinaryFileFunc func(context.Context, *ent.SentinelAppBinaryFileMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f SentinelAppBinaryFileFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.SentinelAppBinaryFileMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SentinelAppBinaryFileMutation", m) +} + +// The SentinelInfoFunc type is an adapter to allow the use of ordinary +// function as SentinelInfo mutator. +type SentinelInfoFunc func(context.Context, *ent.SentinelInfoMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f SentinelInfoFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.SentinelInfoMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SentinelInfoMutation", m) +} + +// The SentinelLibraryFunc type is an adapter to allow the use of ordinary +// function as SentinelLibrary mutator. +type SentinelLibraryFunc func(context.Context, *ent.SentinelLibraryMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f SentinelLibraryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.SentinelLibraryMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SentinelLibraryMutation", m) +} + // The SessionFunc type is an adapter to allow the use of ordinary // function as Session mutator. type SessionFunc func(context.Context, *ent.SessionMutation) (ent.Value, error) diff --git a/internal/data/internal/ent/migrate/schema.go b/internal/data/internal/ent/migrate/schema.go index e04c9756..c1cd958b 100644 --- a/internal/data/internal/ent/migrate/schema.go +++ b/internal/data/internal/ent/migrate/schema.go @@ -737,6 +737,132 @@ var ( }, }, } + // SentinelAppBinariesColumns holds the columns for the "sentinel_app_binaries" table. + SentinelAppBinariesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "sentinel_info_id", Type: field.TypeInt64}, + {Name: "sentinel_library_reported_id", Type: field.TypeInt64}, + {Name: "generated_id", Type: field.TypeString}, + {Name: "size_bytes", Type: field.TypeInt64}, + {Name: "need_token", Type: field.TypeBool}, + {Name: "name", Type: field.TypeString, Nullable: true}, + {Name: "version", Type: field.TypeString, Nullable: true}, + {Name: "developer", Type: field.TypeString, Nullable: true}, + {Name: "publisher", Type: field.TypeString, Nullable: true}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "app_binary_report_sequence", Type: field.TypeInt64}, + } + // SentinelAppBinariesTable holds the schema information for the "sentinel_app_binaries" table. + SentinelAppBinariesTable = &schema.Table{ + Name: "sentinel_app_binaries", + Columns: SentinelAppBinariesColumns, + PrimaryKey: []*schema.Column{SentinelAppBinariesColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "sentinelappbinary_sentinel_info_id_sentinel_library_reported_id_generated_id", + Unique: true, + Columns: []*schema.Column{SentinelAppBinariesColumns[1], SentinelAppBinariesColumns[2], SentinelAppBinariesColumns[3]}, + }, + { + Name: "sentinelappbinary_generated_id", + Unique: false, + Columns: []*schema.Column{SentinelAppBinariesColumns[3]}, + }, + { + Name: "sentinelappbinary_app_binary_report_sequence", + Unique: false, + Columns: []*schema.Column{SentinelAppBinariesColumns[12]}, + }, + }, + } + // SentinelAppBinaryFilesColumns holds the columns for the "sentinel_app_binary_files" table. + SentinelAppBinaryFilesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "sentinel_info_id", Type: field.TypeInt64}, + {Name: "sentinel_library_reported_id", Type: field.TypeInt64}, + {Name: "sentinel_app_binary_generated_id", Type: field.TypeString}, + {Name: "name", Type: field.TypeString}, + {Name: "size_bytes", Type: field.TypeInt64}, + {Name: "sha256", Type: field.TypeBytes}, + {Name: "server_file_path", Type: field.TypeString}, + {Name: "chunks_info", Type: field.TypeString, Nullable: true}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "app_binary_report_sequence", Type: field.TypeInt64}, + } + // SentinelAppBinaryFilesTable holds the schema information for the "sentinel_app_binary_files" table. + SentinelAppBinaryFilesTable = &schema.Table{ + Name: "sentinel_app_binary_files", + Columns: SentinelAppBinaryFilesColumns, + PrimaryKey: []*schema.Column{SentinelAppBinaryFilesColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "sentinelappbinaryfile_sentinel_info_id_sentinel_library_reported_id_sentinel_app_binary_generated_id_server_file_path", + Unique: true, + Columns: []*schema.Column{SentinelAppBinaryFilesColumns[1], SentinelAppBinaryFilesColumns[2], SentinelAppBinaryFilesColumns[3], SentinelAppBinaryFilesColumns[7]}, + }, + { + Name: "sentinelappbinaryfile_app_binary_report_sequence", + Unique: false, + Columns: []*schema.Column{SentinelAppBinaryFilesColumns[11]}, + }, + }, + } + // SentinelInfosColumns holds the columns for the "sentinel_infos" table. + SentinelInfosColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt64}, + {Name: "url", Type: field.TypeString}, + {Name: "alternative_urls", Type: field.TypeJSON, Nullable: true}, + {Name: "get_token_path", Type: field.TypeString, Nullable: true}, + {Name: "download_file_base_path", Type: field.TypeString}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "library_report_sequence", Type: field.TypeInt64}, + {Name: "app_binary_report_sequence", Type: field.TypeInt64}, + } + // SentinelInfosTable holds the schema information for the "sentinel_infos" table. + SentinelInfosTable = &schema.Table{ + Name: "sentinel_infos", + Columns: SentinelInfosColumns, + PrimaryKey: []*schema.Column{SentinelInfosColumns[0]}, + } + // SentinelLibrariesColumns holds the columns for the "sentinel_libraries" table. + SentinelLibrariesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "reported_id", Type: field.TypeInt64}, + {Name: "download_base_path", Type: field.TypeString}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "library_report_sequence", Type: field.TypeInt64}, + {Name: "sentinel_info_id", Type: field.TypeInt64}, + } + // SentinelLibrariesTable holds the schema information for the "sentinel_libraries" table. + SentinelLibrariesTable = &schema.Table{ + Name: "sentinel_libraries", + Columns: SentinelLibrariesColumns, + PrimaryKey: []*schema.Column{SentinelLibrariesColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "sentinel_libraries_sentinel_infos_sentinel_info", + Columns: []*schema.Column{SentinelLibrariesColumns[6]}, + RefColumns: []*schema.Column{SentinelInfosColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + Indexes: []*schema.Index{ + { + Name: "sentinellibrary_sentinel_info_id_reported_id", + Unique: true, + Columns: []*schema.Column{SentinelLibrariesColumns[6], SentinelLibrariesColumns[1]}, + }, + { + Name: "sentinellibrary_library_report_sequence", + Unique: false, + Columns: []*schema.Column{SentinelLibrariesColumns[5]}, + }, + }, + } // SessionsColumns holds the columns for the "sessions" table. SessionsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64}, @@ -931,6 +1057,10 @@ var ( NotifyTargetsTable, PorterContextsTable, PorterInstancesTable, + SentinelAppBinariesTable, + SentinelAppBinaryFilesTable, + SentinelInfosTable, + SentinelLibrariesTable, SessionsTable, StoreAppsTable, StoreAppBinariesTable, @@ -968,6 +1098,7 @@ func init() { NotifySourcesTable.ForeignKeys[2].RefTable = UsersTable NotifyTargetsTable.ForeignKeys[0].RefTable = UsersTable PorterContextsTable.ForeignKeys[0].RefTable = UsersTable + SentinelLibrariesTable.ForeignKeys[0].RefTable = SentinelInfosTable SessionsTable.ForeignKeys[0].RefTable = DevicesTable SessionsTable.ForeignKeys[1].RefTable = UsersTable TagsTable.ForeignKeys[0].RefTable = UsersTable diff --git a/internal/data/internal/ent/mutation.go b/internal/data/internal/ent/mutation.go index 8cf5a1e0..501d98e1 100644 --- a/internal/data/internal/ent/mutation.go +++ b/internal/data/internal/ent/mutation.go @@ -34,6 +34,10 @@ import ( "github.com/tuihub/librarian/internal/data/internal/ent/portercontext" "github.com/tuihub/librarian/internal/data/internal/ent/porterinstance" "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" "github.com/tuihub/librarian/internal/data/internal/ent/session" "github.com/tuihub/librarian/internal/data/internal/ent/storeapp" "github.com/tuihub/librarian/internal/data/internal/ent/storeappbinary" @@ -54,34 +58,38 @@ const ( OpUpdateOne = ent.OpUpdateOne // Node types. - TypeAccount = "Account" - TypeApp = "App" - TypeAppAppCategory = "AppAppCategory" - TypeAppCategory = "AppCategory" - TypeAppInfo = "AppInfo" - TypeAppRunTime = "AppRunTime" - TypeDevice = "Device" - TypeFeed = "Feed" - TypeFeedActionSet = "FeedActionSet" - TypeFeedConfig = "FeedConfig" - TypeFeedConfigAction = "FeedConfigAction" - TypeFeedItem = "FeedItem" - TypeFeedItemCollection = "FeedItemCollection" - TypeFile = "File" - TypeImage = "Image" - TypeNotifyFlow = "NotifyFlow" - TypeNotifyFlowSource = "NotifyFlowSource" - TypeNotifyFlowTarget = "NotifyFlowTarget" - TypeNotifySource = "NotifySource" - TypeNotifyTarget = "NotifyTarget" - TypePorterContext = "PorterContext" - TypePorterInstance = "PorterInstance" - TypeSession = "Session" - TypeStoreApp = "StoreApp" - TypeStoreAppBinary = "StoreAppBinary" - TypeSystemNotification = "SystemNotification" - TypeTag = "Tag" - TypeUser = "User" + TypeAccount = "Account" + TypeApp = "App" + TypeAppAppCategory = "AppAppCategory" + TypeAppCategory = "AppCategory" + TypeAppInfo = "AppInfo" + TypeAppRunTime = "AppRunTime" + TypeDevice = "Device" + TypeFeed = "Feed" + TypeFeedActionSet = "FeedActionSet" + TypeFeedConfig = "FeedConfig" + TypeFeedConfigAction = "FeedConfigAction" + TypeFeedItem = "FeedItem" + TypeFeedItemCollection = "FeedItemCollection" + TypeFile = "File" + TypeImage = "Image" + TypeNotifyFlow = "NotifyFlow" + TypeNotifyFlowSource = "NotifyFlowSource" + TypeNotifyFlowTarget = "NotifyFlowTarget" + TypeNotifySource = "NotifySource" + TypeNotifyTarget = "NotifyTarget" + TypePorterContext = "PorterContext" + TypePorterInstance = "PorterInstance" + TypeSentinelAppBinary = "SentinelAppBinary" + TypeSentinelAppBinaryFile = "SentinelAppBinaryFile" + TypeSentinelInfo = "SentinelInfo" + TypeSentinelLibrary = "SentinelLibrary" + TypeSession = "Session" + TypeStoreApp = "StoreApp" + TypeStoreAppBinary = "StoreAppBinary" + TypeSystemNotification = "SystemNotification" + TypeTag = "Tag" + TypeUser = "User" ) // AccountMutation represents an operation that mutates the Account nodes in the graph. @@ -21845,6 +21853,3812 @@ func (m *PorterInstanceMutation) ResetEdge(name string) error { return fmt.Errorf("unknown PorterInstance edge %s", name) } +// SentinelAppBinaryMutation represents an operation that mutates the SentinelAppBinary nodes in the graph. +type SentinelAppBinaryMutation struct { + config + op Op + typ string + id *int + sentinel_info_id *model.InternalID + addsentinel_info_id *model.InternalID + sentinel_library_reported_id *int64 + addsentinel_library_reported_id *int64 + generated_id *string + size_bytes *int64 + addsize_bytes *int64 + need_token *bool + name *string + version *string + developer *string + publisher *string + updated_at *time.Time + created_at *time.Time + app_binary_report_sequence *int64 + addapp_binary_report_sequence *int64 + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*SentinelAppBinary, error) + predicates []predicate.SentinelAppBinary +} + +var _ ent.Mutation = (*SentinelAppBinaryMutation)(nil) + +// sentinelappbinaryOption allows management of the mutation configuration using functional options. +type sentinelappbinaryOption func(*SentinelAppBinaryMutation) + +// newSentinelAppBinaryMutation creates new mutation for the SentinelAppBinary entity. +func newSentinelAppBinaryMutation(c config, op Op, opts ...sentinelappbinaryOption) *SentinelAppBinaryMutation { + m := &SentinelAppBinaryMutation{ + config: c, + op: op, + typ: TypeSentinelAppBinary, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withSentinelAppBinaryID sets the ID field of the mutation. +func withSentinelAppBinaryID(id int) sentinelappbinaryOption { + return func(m *SentinelAppBinaryMutation) { + var ( + err error + once sync.Once + value *SentinelAppBinary + ) + m.oldValue = func(ctx context.Context) (*SentinelAppBinary, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().SentinelAppBinary.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withSentinelAppBinary sets the old SentinelAppBinary of the mutation. +func withSentinelAppBinary(node *SentinelAppBinary) sentinelappbinaryOption { + return func(m *SentinelAppBinaryMutation) { + m.oldValue = func(context.Context) (*SentinelAppBinary, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m SentinelAppBinaryMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m SentinelAppBinaryMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *SentinelAppBinaryMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *SentinelAppBinaryMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().SentinelAppBinary.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (m *SentinelAppBinaryMutation) SetSentinelInfoID(mi model.InternalID) { + m.sentinel_info_id = &mi + m.addsentinel_info_id = nil +} + +// SentinelInfoID returns the value of the "sentinel_info_id" field in the mutation. +func (m *SentinelAppBinaryMutation) SentinelInfoID() (r model.InternalID, exists bool) { + v := m.sentinel_info_id + if v == nil { + return + } + return *v, true +} + +// OldSentinelInfoID returns the old "sentinel_info_id" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldSentinelInfoID(ctx context.Context) (v model.InternalID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSentinelInfoID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSentinelInfoID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSentinelInfoID: %w", err) + } + return oldValue.SentinelInfoID, nil +} + +// AddSentinelInfoID adds mi to the "sentinel_info_id" field. +func (m *SentinelAppBinaryMutation) AddSentinelInfoID(mi model.InternalID) { + if m.addsentinel_info_id != nil { + *m.addsentinel_info_id += mi + } else { + m.addsentinel_info_id = &mi + } +} + +// AddedSentinelInfoID returns the value that was added to the "sentinel_info_id" field in this mutation. +func (m *SentinelAppBinaryMutation) AddedSentinelInfoID() (r model.InternalID, exists bool) { + v := m.addsentinel_info_id + if v == nil { + return + } + return *v, true +} + +// ResetSentinelInfoID resets all changes to the "sentinel_info_id" field. +func (m *SentinelAppBinaryMutation) ResetSentinelInfoID() { + m.sentinel_info_id = nil + m.addsentinel_info_id = nil +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (m *SentinelAppBinaryMutation) SetSentinelLibraryReportedID(i int64) { + m.sentinel_library_reported_id = &i + m.addsentinel_library_reported_id = nil +} + +// SentinelLibraryReportedID returns the value of the "sentinel_library_reported_id" field in the mutation. +func (m *SentinelAppBinaryMutation) SentinelLibraryReportedID() (r int64, exists bool) { + v := m.sentinel_library_reported_id + if v == nil { + return + } + return *v, true +} + +// OldSentinelLibraryReportedID returns the old "sentinel_library_reported_id" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldSentinelLibraryReportedID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSentinelLibraryReportedID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSentinelLibraryReportedID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSentinelLibraryReportedID: %w", err) + } + return oldValue.SentinelLibraryReportedID, nil +} + +// AddSentinelLibraryReportedID adds i to the "sentinel_library_reported_id" field. +func (m *SentinelAppBinaryMutation) AddSentinelLibraryReportedID(i int64) { + if m.addsentinel_library_reported_id != nil { + *m.addsentinel_library_reported_id += i + } else { + m.addsentinel_library_reported_id = &i + } +} + +// AddedSentinelLibraryReportedID returns the value that was added to the "sentinel_library_reported_id" field in this mutation. +func (m *SentinelAppBinaryMutation) AddedSentinelLibraryReportedID() (r int64, exists bool) { + v := m.addsentinel_library_reported_id + if v == nil { + return + } + return *v, true +} + +// ResetSentinelLibraryReportedID resets all changes to the "sentinel_library_reported_id" field. +func (m *SentinelAppBinaryMutation) ResetSentinelLibraryReportedID() { + m.sentinel_library_reported_id = nil + m.addsentinel_library_reported_id = nil +} + +// SetGeneratedID sets the "generated_id" field. +func (m *SentinelAppBinaryMutation) SetGeneratedID(s string) { + m.generated_id = &s +} + +// GeneratedID returns the value of the "generated_id" field in the mutation. +func (m *SentinelAppBinaryMutation) GeneratedID() (r string, exists bool) { + v := m.generated_id + if v == nil { + return + } + return *v, true +} + +// OldGeneratedID returns the old "generated_id" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldGeneratedID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldGeneratedID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldGeneratedID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldGeneratedID: %w", err) + } + return oldValue.GeneratedID, nil +} + +// ResetGeneratedID resets all changes to the "generated_id" field. +func (m *SentinelAppBinaryMutation) ResetGeneratedID() { + m.generated_id = nil +} + +// SetSizeBytes sets the "size_bytes" field. +func (m *SentinelAppBinaryMutation) SetSizeBytes(i int64) { + m.size_bytes = &i + m.addsize_bytes = nil +} + +// SizeBytes returns the value of the "size_bytes" field in the mutation. +func (m *SentinelAppBinaryMutation) SizeBytes() (r int64, exists bool) { + v := m.size_bytes + if v == nil { + return + } + return *v, true +} + +// OldSizeBytes returns the old "size_bytes" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldSizeBytes(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSizeBytes is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSizeBytes requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSizeBytes: %w", err) + } + return oldValue.SizeBytes, nil +} + +// AddSizeBytes adds i to the "size_bytes" field. +func (m *SentinelAppBinaryMutation) AddSizeBytes(i int64) { + if m.addsize_bytes != nil { + *m.addsize_bytes += i + } else { + m.addsize_bytes = &i + } +} + +// AddedSizeBytes returns the value that was added to the "size_bytes" field in this mutation. +func (m *SentinelAppBinaryMutation) AddedSizeBytes() (r int64, exists bool) { + v := m.addsize_bytes + if v == nil { + return + } + return *v, true +} + +// ResetSizeBytes resets all changes to the "size_bytes" field. +func (m *SentinelAppBinaryMutation) ResetSizeBytes() { + m.size_bytes = nil + m.addsize_bytes = nil +} + +// SetNeedToken sets the "need_token" field. +func (m *SentinelAppBinaryMutation) SetNeedToken(b bool) { + m.need_token = &b +} + +// NeedToken returns the value of the "need_token" field in the mutation. +func (m *SentinelAppBinaryMutation) NeedToken() (r bool, exists bool) { + v := m.need_token + if v == nil { + return + } + return *v, true +} + +// OldNeedToken returns the old "need_token" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldNeedToken(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNeedToken is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNeedToken requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNeedToken: %w", err) + } + return oldValue.NeedToken, nil +} + +// ResetNeedToken resets all changes to the "need_token" field. +func (m *SentinelAppBinaryMutation) ResetNeedToken() { + m.need_token = nil +} + +// SetName sets the "name" field. +func (m *SentinelAppBinaryMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *SentinelAppBinaryMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ClearName clears the value of the "name" field. +func (m *SentinelAppBinaryMutation) ClearName() { + m.name = nil + m.clearedFields[sentinelappbinary.FieldName] = struct{}{} +} + +// NameCleared returns if the "name" field was cleared in this mutation. +func (m *SentinelAppBinaryMutation) NameCleared() bool { + _, ok := m.clearedFields[sentinelappbinary.FieldName] + return ok +} + +// ResetName resets all changes to the "name" field. +func (m *SentinelAppBinaryMutation) ResetName() { + m.name = nil + delete(m.clearedFields, sentinelappbinary.FieldName) +} + +// SetVersion sets the "version" field. +func (m *SentinelAppBinaryMutation) SetVersion(s string) { + m.version = &s +} + +// Version returns the value of the "version" field in the mutation. +func (m *SentinelAppBinaryMutation) Version() (r string, exists bool) { + v := m.version + if v == nil { + return + } + return *v, true +} + +// OldVersion returns the old "version" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldVersion(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldVersion is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldVersion requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldVersion: %w", err) + } + return oldValue.Version, nil +} + +// ClearVersion clears the value of the "version" field. +func (m *SentinelAppBinaryMutation) ClearVersion() { + m.version = nil + m.clearedFields[sentinelappbinary.FieldVersion] = struct{}{} +} + +// VersionCleared returns if the "version" field was cleared in this mutation. +func (m *SentinelAppBinaryMutation) VersionCleared() bool { + _, ok := m.clearedFields[sentinelappbinary.FieldVersion] + return ok +} + +// ResetVersion resets all changes to the "version" field. +func (m *SentinelAppBinaryMutation) ResetVersion() { + m.version = nil + delete(m.clearedFields, sentinelappbinary.FieldVersion) +} + +// SetDeveloper sets the "developer" field. +func (m *SentinelAppBinaryMutation) SetDeveloper(s string) { + m.developer = &s +} + +// Developer returns the value of the "developer" field in the mutation. +func (m *SentinelAppBinaryMutation) Developer() (r string, exists bool) { + v := m.developer + if v == nil { + return + } + return *v, true +} + +// OldDeveloper returns the old "developer" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldDeveloper(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDeveloper is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDeveloper requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDeveloper: %w", err) + } + return oldValue.Developer, nil +} + +// ClearDeveloper clears the value of the "developer" field. +func (m *SentinelAppBinaryMutation) ClearDeveloper() { + m.developer = nil + m.clearedFields[sentinelappbinary.FieldDeveloper] = struct{}{} +} + +// DeveloperCleared returns if the "developer" field was cleared in this mutation. +func (m *SentinelAppBinaryMutation) DeveloperCleared() bool { + _, ok := m.clearedFields[sentinelappbinary.FieldDeveloper] + return ok +} + +// ResetDeveloper resets all changes to the "developer" field. +func (m *SentinelAppBinaryMutation) ResetDeveloper() { + m.developer = nil + delete(m.clearedFields, sentinelappbinary.FieldDeveloper) +} + +// SetPublisher sets the "publisher" field. +func (m *SentinelAppBinaryMutation) SetPublisher(s string) { + m.publisher = &s +} + +// Publisher returns the value of the "publisher" field in the mutation. +func (m *SentinelAppBinaryMutation) Publisher() (r string, exists bool) { + v := m.publisher + if v == nil { + return + } + return *v, true +} + +// OldPublisher returns the old "publisher" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldPublisher(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPublisher is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPublisher requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPublisher: %w", err) + } + return oldValue.Publisher, nil +} + +// ClearPublisher clears the value of the "publisher" field. +func (m *SentinelAppBinaryMutation) ClearPublisher() { + m.publisher = nil + m.clearedFields[sentinelappbinary.FieldPublisher] = struct{}{} +} + +// PublisherCleared returns if the "publisher" field was cleared in this mutation. +func (m *SentinelAppBinaryMutation) PublisherCleared() bool { + _, ok := m.clearedFields[sentinelappbinary.FieldPublisher] + return ok +} + +// ResetPublisher resets all changes to the "publisher" field. +func (m *SentinelAppBinaryMutation) ResetPublisher() { + m.publisher = nil + delete(m.clearedFields, sentinelappbinary.FieldPublisher) +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *SentinelAppBinaryMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *SentinelAppBinaryMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *SentinelAppBinaryMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *SentinelAppBinaryMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *SentinelAppBinaryMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *SentinelAppBinaryMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (m *SentinelAppBinaryMutation) SetAppBinaryReportSequence(i int64) { + m.app_binary_report_sequence = &i + m.addapp_binary_report_sequence = nil +} + +// AppBinaryReportSequence returns the value of the "app_binary_report_sequence" field in the mutation. +func (m *SentinelAppBinaryMutation) AppBinaryReportSequence() (r int64, exists bool) { + v := m.app_binary_report_sequence + if v == nil { + return + } + return *v, true +} + +// OldAppBinaryReportSequence returns the old "app_binary_report_sequence" field's value of the SentinelAppBinary entity. +// If the SentinelAppBinary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryMutation) OldAppBinaryReportSequence(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAppBinaryReportSequence is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAppBinaryReportSequence requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAppBinaryReportSequence: %w", err) + } + return oldValue.AppBinaryReportSequence, nil +} + +// AddAppBinaryReportSequence adds i to the "app_binary_report_sequence" field. +func (m *SentinelAppBinaryMutation) AddAppBinaryReportSequence(i int64) { + if m.addapp_binary_report_sequence != nil { + *m.addapp_binary_report_sequence += i + } else { + m.addapp_binary_report_sequence = &i + } +} + +// AddedAppBinaryReportSequence returns the value that was added to the "app_binary_report_sequence" field in this mutation. +func (m *SentinelAppBinaryMutation) AddedAppBinaryReportSequence() (r int64, exists bool) { + v := m.addapp_binary_report_sequence + if v == nil { + return + } + return *v, true +} + +// ResetAppBinaryReportSequence resets all changes to the "app_binary_report_sequence" field. +func (m *SentinelAppBinaryMutation) ResetAppBinaryReportSequence() { + m.app_binary_report_sequence = nil + m.addapp_binary_report_sequence = nil +} + +// Where appends a list predicates to the SentinelAppBinaryMutation builder. +func (m *SentinelAppBinaryMutation) Where(ps ...predicate.SentinelAppBinary) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the SentinelAppBinaryMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *SentinelAppBinaryMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.SentinelAppBinary, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *SentinelAppBinaryMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *SentinelAppBinaryMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (SentinelAppBinary). +func (m *SentinelAppBinaryMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *SentinelAppBinaryMutation) Fields() []string { + fields := make([]string, 0, 12) + if m.sentinel_info_id != nil { + fields = append(fields, sentinelappbinary.FieldSentinelInfoID) + } + if m.sentinel_library_reported_id != nil { + fields = append(fields, sentinelappbinary.FieldSentinelLibraryReportedID) + } + if m.generated_id != nil { + fields = append(fields, sentinelappbinary.FieldGeneratedID) + } + if m.size_bytes != nil { + fields = append(fields, sentinelappbinary.FieldSizeBytes) + } + if m.need_token != nil { + fields = append(fields, sentinelappbinary.FieldNeedToken) + } + if m.name != nil { + fields = append(fields, sentinelappbinary.FieldName) + } + if m.version != nil { + fields = append(fields, sentinelappbinary.FieldVersion) + } + if m.developer != nil { + fields = append(fields, sentinelappbinary.FieldDeveloper) + } + if m.publisher != nil { + fields = append(fields, sentinelappbinary.FieldPublisher) + } + if m.updated_at != nil { + fields = append(fields, sentinelappbinary.FieldUpdatedAt) + } + if m.created_at != nil { + fields = append(fields, sentinelappbinary.FieldCreatedAt) + } + if m.app_binary_report_sequence != nil { + fields = append(fields, sentinelappbinary.FieldAppBinaryReportSequence) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *SentinelAppBinaryMutation) Field(name string) (ent.Value, bool) { + switch name { + case sentinelappbinary.FieldSentinelInfoID: + return m.SentinelInfoID() + case sentinelappbinary.FieldSentinelLibraryReportedID: + return m.SentinelLibraryReportedID() + case sentinelappbinary.FieldGeneratedID: + return m.GeneratedID() + case sentinelappbinary.FieldSizeBytes: + return m.SizeBytes() + case sentinelappbinary.FieldNeedToken: + return m.NeedToken() + case sentinelappbinary.FieldName: + return m.Name() + case sentinelappbinary.FieldVersion: + return m.Version() + case sentinelappbinary.FieldDeveloper: + return m.Developer() + case sentinelappbinary.FieldPublisher: + return m.Publisher() + case sentinelappbinary.FieldUpdatedAt: + return m.UpdatedAt() + case sentinelappbinary.FieldCreatedAt: + return m.CreatedAt() + case sentinelappbinary.FieldAppBinaryReportSequence: + return m.AppBinaryReportSequence() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *SentinelAppBinaryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case sentinelappbinary.FieldSentinelInfoID: + return m.OldSentinelInfoID(ctx) + case sentinelappbinary.FieldSentinelLibraryReportedID: + return m.OldSentinelLibraryReportedID(ctx) + case sentinelappbinary.FieldGeneratedID: + return m.OldGeneratedID(ctx) + case sentinelappbinary.FieldSizeBytes: + return m.OldSizeBytes(ctx) + case sentinelappbinary.FieldNeedToken: + return m.OldNeedToken(ctx) + case sentinelappbinary.FieldName: + return m.OldName(ctx) + case sentinelappbinary.FieldVersion: + return m.OldVersion(ctx) + case sentinelappbinary.FieldDeveloper: + return m.OldDeveloper(ctx) + case sentinelappbinary.FieldPublisher: + return m.OldPublisher(ctx) + case sentinelappbinary.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case sentinelappbinary.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case sentinelappbinary.FieldAppBinaryReportSequence: + return m.OldAppBinaryReportSequence(ctx) + } + return nil, fmt.Errorf("unknown SentinelAppBinary field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SentinelAppBinaryMutation) SetField(name string, value ent.Value) error { + switch name { + case sentinelappbinary.FieldSentinelInfoID: + v, ok := value.(model.InternalID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSentinelInfoID(v) + return nil + case sentinelappbinary.FieldSentinelLibraryReportedID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSentinelLibraryReportedID(v) + return nil + case sentinelappbinary.FieldGeneratedID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetGeneratedID(v) + return nil + case sentinelappbinary.FieldSizeBytes: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSizeBytes(v) + return nil + case sentinelappbinary.FieldNeedToken: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNeedToken(v) + return nil + case sentinelappbinary.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case sentinelappbinary.FieldVersion: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetVersion(v) + return nil + case sentinelappbinary.FieldDeveloper: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDeveloper(v) + return nil + case sentinelappbinary.FieldPublisher: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPublisher(v) + return nil + case sentinelappbinary.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case sentinelappbinary.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case sentinelappbinary.FieldAppBinaryReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAppBinaryReportSequence(v) + return nil + } + return fmt.Errorf("unknown SentinelAppBinary field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *SentinelAppBinaryMutation) AddedFields() []string { + var fields []string + if m.addsentinel_info_id != nil { + fields = append(fields, sentinelappbinary.FieldSentinelInfoID) + } + if m.addsentinel_library_reported_id != nil { + fields = append(fields, sentinelappbinary.FieldSentinelLibraryReportedID) + } + if m.addsize_bytes != nil { + fields = append(fields, sentinelappbinary.FieldSizeBytes) + } + if m.addapp_binary_report_sequence != nil { + fields = append(fields, sentinelappbinary.FieldAppBinaryReportSequence) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *SentinelAppBinaryMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case sentinelappbinary.FieldSentinelInfoID: + return m.AddedSentinelInfoID() + case sentinelappbinary.FieldSentinelLibraryReportedID: + return m.AddedSentinelLibraryReportedID() + case sentinelappbinary.FieldSizeBytes: + return m.AddedSizeBytes() + case sentinelappbinary.FieldAppBinaryReportSequence: + return m.AddedAppBinaryReportSequence() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SentinelAppBinaryMutation) AddField(name string, value ent.Value) error { + switch name { + case sentinelappbinary.FieldSentinelInfoID: + v, ok := value.(model.InternalID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddSentinelInfoID(v) + return nil + case sentinelappbinary.FieldSentinelLibraryReportedID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddSentinelLibraryReportedID(v) + return nil + case sentinelappbinary.FieldSizeBytes: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddSizeBytes(v) + return nil + case sentinelappbinary.FieldAppBinaryReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddAppBinaryReportSequence(v) + return nil + } + return fmt.Errorf("unknown SentinelAppBinary numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *SentinelAppBinaryMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(sentinelappbinary.FieldName) { + fields = append(fields, sentinelappbinary.FieldName) + } + if m.FieldCleared(sentinelappbinary.FieldVersion) { + fields = append(fields, sentinelappbinary.FieldVersion) + } + if m.FieldCleared(sentinelappbinary.FieldDeveloper) { + fields = append(fields, sentinelappbinary.FieldDeveloper) + } + if m.FieldCleared(sentinelappbinary.FieldPublisher) { + fields = append(fields, sentinelappbinary.FieldPublisher) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *SentinelAppBinaryMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *SentinelAppBinaryMutation) ClearField(name string) error { + switch name { + case sentinelappbinary.FieldName: + m.ClearName() + return nil + case sentinelappbinary.FieldVersion: + m.ClearVersion() + return nil + case sentinelappbinary.FieldDeveloper: + m.ClearDeveloper() + return nil + case sentinelappbinary.FieldPublisher: + m.ClearPublisher() + return nil + } + return fmt.Errorf("unknown SentinelAppBinary nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *SentinelAppBinaryMutation) ResetField(name string) error { + switch name { + case sentinelappbinary.FieldSentinelInfoID: + m.ResetSentinelInfoID() + return nil + case sentinelappbinary.FieldSentinelLibraryReportedID: + m.ResetSentinelLibraryReportedID() + return nil + case sentinelappbinary.FieldGeneratedID: + m.ResetGeneratedID() + return nil + case sentinelappbinary.FieldSizeBytes: + m.ResetSizeBytes() + return nil + case sentinelappbinary.FieldNeedToken: + m.ResetNeedToken() + return nil + case sentinelappbinary.FieldName: + m.ResetName() + return nil + case sentinelappbinary.FieldVersion: + m.ResetVersion() + return nil + case sentinelappbinary.FieldDeveloper: + m.ResetDeveloper() + return nil + case sentinelappbinary.FieldPublisher: + m.ResetPublisher() + return nil + case sentinelappbinary.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case sentinelappbinary.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case sentinelappbinary.FieldAppBinaryReportSequence: + m.ResetAppBinaryReportSequence() + return nil + } + return fmt.Errorf("unknown SentinelAppBinary field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *SentinelAppBinaryMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *SentinelAppBinaryMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *SentinelAppBinaryMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *SentinelAppBinaryMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *SentinelAppBinaryMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *SentinelAppBinaryMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *SentinelAppBinaryMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown SentinelAppBinary unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *SentinelAppBinaryMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown SentinelAppBinary edge %s", name) +} + +// SentinelAppBinaryFileMutation represents an operation that mutates the SentinelAppBinaryFile nodes in the graph. +type SentinelAppBinaryFileMutation struct { + config + op Op + typ string + id *int + sentinel_info_id *model.InternalID + addsentinel_info_id *model.InternalID + sentinel_library_reported_id *int64 + addsentinel_library_reported_id *int64 + sentinel_app_binary_generated_id *string + name *string + size_bytes *int64 + addsize_bytes *int64 + sha256 *[]byte + server_file_path *string + chunks_info *string + updated_at *time.Time + created_at *time.Time + app_binary_report_sequence *int64 + addapp_binary_report_sequence *int64 + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*SentinelAppBinaryFile, error) + predicates []predicate.SentinelAppBinaryFile +} + +var _ ent.Mutation = (*SentinelAppBinaryFileMutation)(nil) + +// sentinelappbinaryfileOption allows management of the mutation configuration using functional options. +type sentinelappbinaryfileOption func(*SentinelAppBinaryFileMutation) + +// newSentinelAppBinaryFileMutation creates new mutation for the SentinelAppBinaryFile entity. +func newSentinelAppBinaryFileMutation(c config, op Op, opts ...sentinelappbinaryfileOption) *SentinelAppBinaryFileMutation { + m := &SentinelAppBinaryFileMutation{ + config: c, + op: op, + typ: TypeSentinelAppBinaryFile, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withSentinelAppBinaryFileID sets the ID field of the mutation. +func withSentinelAppBinaryFileID(id int) sentinelappbinaryfileOption { + return func(m *SentinelAppBinaryFileMutation) { + var ( + err error + once sync.Once + value *SentinelAppBinaryFile + ) + m.oldValue = func(ctx context.Context) (*SentinelAppBinaryFile, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().SentinelAppBinaryFile.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withSentinelAppBinaryFile sets the old SentinelAppBinaryFile of the mutation. +func withSentinelAppBinaryFile(node *SentinelAppBinaryFile) sentinelappbinaryfileOption { + return func(m *SentinelAppBinaryFileMutation) { + m.oldValue = func(context.Context) (*SentinelAppBinaryFile, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m SentinelAppBinaryFileMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m SentinelAppBinaryFileMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *SentinelAppBinaryFileMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *SentinelAppBinaryFileMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().SentinelAppBinaryFile.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (m *SentinelAppBinaryFileMutation) SetSentinelInfoID(mi model.InternalID) { + m.sentinel_info_id = &mi + m.addsentinel_info_id = nil +} + +// SentinelInfoID returns the value of the "sentinel_info_id" field in the mutation. +func (m *SentinelAppBinaryFileMutation) SentinelInfoID() (r model.InternalID, exists bool) { + v := m.sentinel_info_id + if v == nil { + return + } + return *v, true +} + +// OldSentinelInfoID returns the old "sentinel_info_id" field's value of the SentinelAppBinaryFile entity. +// If the SentinelAppBinaryFile object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryFileMutation) OldSentinelInfoID(ctx context.Context) (v model.InternalID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSentinelInfoID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSentinelInfoID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSentinelInfoID: %w", err) + } + return oldValue.SentinelInfoID, nil +} + +// AddSentinelInfoID adds mi to the "sentinel_info_id" field. +func (m *SentinelAppBinaryFileMutation) AddSentinelInfoID(mi model.InternalID) { + if m.addsentinel_info_id != nil { + *m.addsentinel_info_id += mi + } else { + m.addsentinel_info_id = &mi + } +} + +// AddedSentinelInfoID returns the value that was added to the "sentinel_info_id" field in this mutation. +func (m *SentinelAppBinaryFileMutation) AddedSentinelInfoID() (r model.InternalID, exists bool) { + v := m.addsentinel_info_id + if v == nil { + return + } + return *v, true +} + +// ResetSentinelInfoID resets all changes to the "sentinel_info_id" field. +func (m *SentinelAppBinaryFileMutation) ResetSentinelInfoID() { + m.sentinel_info_id = nil + m.addsentinel_info_id = nil +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (m *SentinelAppBinaryFileMutation) SetSentinelLibraryReportedID(i int64) { + m.sentinel_library_reported_id = &i + m.addsentinel_library_reported_id = nil +} + +// SentinelLibraryReportedID returns the value of the "sentinel_library_reported_id" field in the mutation. +func (m *SentinelAppBinaryFileMutation) SentinelLibraryReportedID() (r int64, exists bool) { + v := m.sentinel_library_reported_id + if v == nil { + return + } + return *v, true +} + +// OldSentinelLibraryReportedID returns the old "sentinel_library_reported_id" field's value of the SentinelAppBinaryFile entity. +// If the SentinelAppBinaryFile object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryFileMutation) OldSentinelLibraryReportedID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSentinelLibraryReportedID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSentinelLibraryReportedID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSentinelLibraryReportedID: %w", err) + } + return oldValue.SentinelLibraryReportedID, nil +} + +// AddSentinelLibraryReportedID adds i to the "sentinel_library_reported_id" field. +func (m *SentinelAppBinaryFileMutation) AddSentinelLibraryReportedID(i int64) { + if m.addsentinel_library_reported_id != nil { + *m.addsentinel_library_reported_id += i + } else { + m.addsentinel_library_reported_id = &i + } +} + +// AddedSentinelLibraryReportedID returns the value that was added to the "sentinel_library_reported_id" field in this mutation. +func (m *SentinelAppBinaryFileMutation) AddedSentinelLibraryReportedID() (r int64, exists bool) { + v := m.addsentinel_library_reported_id + if v == nil { + return + } + return *v, true +} + +// ResetSentinelLibraryReportedID resets all changes to the "sentinel_library_reported_id" field. +func (m *SentinelAppBinaryFileMutation) ResetSentinelLibraryReportedID() { + m.sentinel_library_reported_id = nil + m.addsentinel_library_reported_id = nil +} + +// SetSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field. +func (m *SentinelAppBinaryFileMutation) SetSentinelAppBinaryGeneratedID(s string) { + m.sentinel_app_binary_generated_id = &s +} + +// SentinelAppBinaryGeneratedID returns the value of the "sentinel_app_binary_generated_id" field in the mutation. +func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryGeneratedID() (r string, exists bool) { + v := m.sentinel_app_binary_generated_id + if v == nil { + return + } + return *v, true +} + +// OldSentinelAppBinaryGeneratedID returns the old "sentinel_app_binary_generated_id" field's value of the SentinelAppBinaryFile entity. +// If the SentinelAppBinaryFile object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryFileMutation) OldSentinelAppBinaryGeneratedID(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSentinelAppBinaryGeneratedID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSentinelAppBinaryGeneratedID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSentinelAppBinaryGeneratedID: %w", err) + } + return oldValue.SentinelAppBinaryGeneratedID, nil +} + +// ResetSentinelAppBinaryGeneratedID resets all changes to the "sentinel_app_binary_generated_id" field. +func (m *SentinelAppBinaryFileMutation) ResetSentinelAppBinaryGeneratedID() { + m.sentinel_app_binary_generated_id = nil +} + +// SetName sets the "name" field. +func (m *SentinelAppBinaryFileMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *SentinelAppBinaryFileMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the SentinelAppBinaryFile entity. +// If the SentinelAppBinaryFile object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryFileMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *SentinelAppBinaryFileMutation) ResetName() { + m.name = nil +} + +// SetSizeBytes sets the "size_bytes" field. +func (m *SentinelAppBinaryFileMutation) SetSizeBytes(i int64) { + m.size_bytes = &i + m.addsize_bytes = nil +} + +// SizeBytes returns the value of the "size_bytes" field in the mutation. +func (m *SentinelAppBinaryFileMutation) SizeBytes() (r int64, exists bool) { + v := m.size_bytes + if v == nil { + return + } + return *v, true +} + +// OldSizeBytes returns the old "size_bytes" field's value of the SentinelAppBinaryFile entity. +// If the SentinelAppBinaryFile object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryFileMutation) OldSizeBytes(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSizeBytes is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSizeBytes requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSizeBytes: %w", err) + } + return oldValue.SizeBytes, nil +} + +// AddSizeBytes adds i to the "size_bytes" field. +func (m *SentinelAppBinaryFileMutation) AddSizeBytes(i int64) { + if m.addsize_bytes != nil { + *m.addsize_bytes += i + } else { + m.addsize_bytes = &i + } +} + +// AddedSizeBytes returns the value that was added to the "size_bytes" field in this mutation. +func (m *SentinelAppBinaryFileMutation) AddedSizeBytes() (r int64, exists bool) { + v := m.addsize_bytes + if v == nil { + return + } + return *v, true +} + +// ResetSizeBytes resets all changes to the "size_bytes" field. +func (m *SentinelAppBinaryFileMutation) ResetSizeBytes() { + m.size_bytes = nil + m.addsize_bytes = nil +} + +// SetSha256 sets the "sha256" field. +func (m *SentinelAppBinaryFileMutation) SetSha256(b []byte) { + m.sha256 = &b +} + +// Sha256 returns the value of the "sha256" field in the mutation. +func (m *SentinelAppBinaryFileMutation) Sha256() (r []byte, exists bool) { + v := m.sha256 + if v == nil { + return + } + return *v, true +} + +// OldSha256 returns the old "sha256" field's value of the SentinelAppBinaryFile entity. +// If the SentinelAppBinaryFile object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryFileMutation) OldSha256(ctx context.Context) (v []byte, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSha256 is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSha256 requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSha256: %w", err) + } + return oldValue.Sha256, nil +} + +// ResetSha256 resets all changes to the "sha256" field. +func (m *SentinelAppBinaryFileMutation) ResetSha256() { + m.sha256 = nil +} + +// SetServerFilePath sets the "server_file_path" field. +func (m *SentinelAppBinaryFileMutation) SetServerFilePath(s string) { + m.server_file_path = &s +} + +// ServerFilePath returns the value of the "server_file_path" field in the mutation. +func (m *SentinelAppBinaryFileMutation) ServerFilePath() (r string, exists bool) { + v := m.server_file_path + if v == nil { + return + } + return *v, true +} + +// OldServerFilePath returns the old "server_file_path" field's value of the SentinelAppBinaryFile entity. +// If the SentinelAppBinaryFile object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryFileMutation) OldServerFilePath(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldServerFilePath is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldServerFilePath requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldServerFilePath: %w", err) + } + return oldValue.ServerFilePath, nil +} + +// ResetServerFilePath resets all changes to the "server_file_path" field. +func (m *SentinelAppBinaryFileMutation) ResetServerFilePath() { + m.server_file_path = nil +} + +// SetChunksInfo sets the "chunks_info" field. +func (m *SentinelAppBinaryFileMutation) SetChunksInfo(s string) { + m.chunks_info = &s +} + +// ChunksInfo returns the value of the "chunks_info" field in the mutation. +func (m *SentinelAppBinaryFileMutation) ChunksInfo() (r string, exists bool) { + v := m.chunks_info + if v == nil { + return + } + return *v, true +} + +// OldChunksInfo returns the old "chunks_info" field's value of the SentinelAppBinaryFile entity. +// If the SentinelAppBinaryFile object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryFileMutation) OldChunksInfo(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldChunksInfo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldChunksInfo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldChunksInfo: %w", err) + } + return oldValue.ChunksInfo, nil +} + +// ClearChunksInfo clears the value of the "chunks_info" field. +func (m *SentinelAppBinaryFileMutation) ClearChunksInfo() { + m.chunks_info = nil + m.clearedFields[sentinelappbinaryfile.FieldChunksInfo] = struct{}{} +} + +// ChunksInfoCleared returns if the "chunks_info" field was cleared in this mutation. +func (m *SentinelAppBinaryFileMutation) ChunksInfoCleared() bool { + _, ok := m.clearedFields[sentinelappbinaryfile.FieldChunksInfo] + return ok +} + +// ResetChunksInfo resets all changes to the "chunks_info" field. +func (m *SentinelAppBinaryFileMutation) ResetChunksInfo() { + m.chunks_info = nil + delete(m.clearedFields, sentinelappbinaryfile.FieldChunksInfo) +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *SentinelAppBinaryFileMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *SentinelAppBinaryFileMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the SentinelAppBinaryFile entity. +// If the SentinelAppBinaryFile object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryFileMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *SentinelAppBinaryFileMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *SentinelAppBinaryFileMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *SentinelAppBinaryFileMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the SentinelAppBinaryFile entity. +// If the SentinelAppBinaryFile object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryFileMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *SentinelAppBinaryFileMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (m *SentinelAppBinaryFileMutation) SetAppBinaryReportSequence(i int64) { + m.app_binary_report_sequence = &i + m.addapp_binary_report_sequence = nil +} + +// AppBinaryReportSequence returns the value of the "app_binary_report_sequence" field in the mutation. +func (m *SentinelAppBinaryFileMutation) AppBinaryReportSequence() (r int64, exists bool) { + v := m.app_binary_report_sequence + if v == nil { + return + } + return *v, true +} + +// OldAppBinaryReportSequence returns the old "app_binary_report_sequence" field's value of the SentinelAppBinaryFile entity. +// If the SentinelAppBinaryFile object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelAppBinaryFileMutation) OldAppBinaryReportSequence(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAppBinaryReportSequence is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAppBinaryReportSequence requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAppBinaryReportSequence: %w", err) + } + return oldValue.AppBinaryReportSequence, nil +} + +// AddAppBinaryReportSequence adds i to the "app_binary_report_sequence" field. +func (m *SentinelAppBinaryFileMutation) AddAppBinaryReportSequence(i int64) { + if m.addapp_binary_report_sequence != nil { + *m.addapp_binary_report_sequence += i + } else { + m.addapp_binary_report_sequence = &i + } +} + +// AddedAppBinaryReportSequence returns the value that was added to the "app_binary_report_sequence" field in this mutation. +func (m *SentinelAppBinaryFileMutation) AddedAppBinaryReportSequence() (r int64, exists bool) { + v := m.addapp_binary_report_sequence + if v == nil { + return + } + return *v, true +} + +// ResetAppBinaryReportSequence resets all changes to the "app_binary_report_sequence" field. +func (m *SentinelAppBinaryFileMutation) ResetAppBinaryReportSequence() { + m.app_binary_report_sequence = nil + m.addapp_binary_report_sequence = nil +} + +// Where appends a list predicates to the SentinelAppBinaryFileMutation builder. +func (m *SentinelAppBinaryFileMutation) Where(ps ...predicate.SentinelAppBinaryFile) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the SentinelAppBinaryFileMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *SentinelAppBinaryFileMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.SentinelAppBinaryFile, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *SentinelAppBinaryFileMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *SentinelAppBinaryFileMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (SentinelAppBinaryFile). +func (m *SentinelAppBinaryFileMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *SentinelAppBinaryFileMutation) Fields() []string { + fields := make([]string, 0, 11) + if m.sentinel_info_id != nil { + fields = append(fields, sentinelappbinaryfile.FieldSentinelInfoID) + } + if m.sentinel_library_reported_id != nil { + fields = append(fields, sentinelappbinaryfile.FieldSentinelLibraryReportedID) + } + if m.sentinel_app_binary_generated_id != nil { + fields = append(fields, sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID) + } + if m.name != nil { + fields = append(fields, sentinelappbinaryfile.FieldName) + } + if m.size_bytes != nil { + fields = append(fields, sentinelappbinaryfile.FieldSizeBytes) + } + if m.sha256 != nil { + fields = append(fields, sentinelappbinaryfile.FieldSha256) + } + if m.server_file_path != nil { + fields = append(fields, sentinelappbinaryfile.FieldServerFilePath) + } + if m.chunks_info != nil { + fields = append(fields, sentinelappbinaryfile.FieldChunksInfo) + } + if m.updated_at != nil { + fields = append(fields, sentinelappbinaryfile.FieldUpdatedAt) + } + if m.created_at != nil { + fields = append(fields, sentinelappbinaryfile.FieldCreatedAt) + } + if m.app_binary_report_sequence != nil { + fields = append(fields, sentinelappbinaryfile.FieldAppBinaryReportSequence) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *SentinelAppBinaryFileMutation) Field(name string) (ent.Value, bool) { + switch name { + case sentinelappbinaryfile.FieldSentinelInfoID: + return m.SentinelInfoID() + case sentinelappbinaryfile.FieldSentinelLibraryReportedID: + return m.SentinelLibraryReportedID() + case sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID: + return m.SentinelAppBinaryGeneratedID() + case sentinelappbinaryfile.FieldName: + return m.Name() + case sentinelappbinaryfile.FieldSizeBytes: + return m.SizeBytes() + case sentinelappbinaryfile.FieldSha256: + return m.Sha256() + case sentinelappbinaryfile.FieldServerFilePath: + return m.ServerFilePath() + case sentinelappbinaryfile.FieldChunksInfo: + return m.ChunksInfo() + case sentinelappbinaryfile.FieldUpdatedAt: + return m.UpdatedAt() + case sentinelappbinaryfile.FieldCreatedAt: + return m.CreatedAt() + case sentinelappbinaryfile.FieldAppBinaryReportSequence: + return m.AppBinaryReportSequence() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *SentinelAppBinaryFileMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case sentinelappbinaryfile.FieldSentinelInfoID: + return m.OldSentinelInfoID(ctx) + case sentinelappbinaryfile.FieldSentinelLibraryReportedID: + return m.OldSentinelLibraryReportedID(ctx) + case sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID: + return m.OldSentinelAppBinaryGeneratedID(ctx) + case sentinelappbinaryfile.FieldName: + return m.OldName(ctx) + case sentinelappbinaryfile.FieldSizeBytes: + return m.OldSizeBytes(ctx) + case sentinelappbinaryfile.FieldSha256: + return m.OldSha256(ctx) + case sentinelappbinaryfile.FieldServerFilePath: + return m.OldServerFilePath(ctx) + case sentinelappbinaryfile.FieldChunksInfo: + return m.OldChunksInfo(ctx) + case sentinelappbinaryfile.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case sentinelappbinaryfile.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case sentinelappbinaryfile.FieldAppBinaryReportSequence: + return m.OldAppBinaryReportSequence(ctx) + } + return nil, fmt.Errorf("unknown SentinelAppBinaryFile field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SentinelAppBinaryFileMutation) SetField(name string, value ent.Value) error { + switch name { + case sentinelappbinaryfile.FieldSentinelInfoID: + v, ok := value.(model.InternalID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSentinelInfoID(v) + return nil + case sentinelappbinaryfile.FieldSentinelLibraryReportedID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSentinelLibraryReportedID(v) + return nil + case sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSentinelAppBinaryGeneratedID(v) + return nil + case sentinelappbinaryfile.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case sentinelappbinaryfile.FieldSizeBytes: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSizeBytes(v) + return nil + case sentinelappbinaryfile.FieldSha256: + v, ok := value.([]byte) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSha256(v) + return nil + case sentinelappbinaryfile.FieldServerFilePath: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetServerFilePath(v) + return nil + case sentinelappbinaryfile.FieldChunksInfo: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetChunksInfo(v) + return nil + case sentinelappbinaryfile.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case sentinelappbinaryfile.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case sentinelappbinaryfile.FieldAppBinaryReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAppBinaryReportSequence(v) + return nil + } + return fmt.Errorf("unknown SentinelAppBinaryFile field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *SentinelAppBinaryFileMutation) AddedFields() []string { + var fields []string + if m.addsentinel_info_id != nil { + fields = append(fields, sentinelappbinaryfile.FieldSentinelInfoID) + } + if m.addsentinel_library_reported_id != nil { + fields = append(fields, sentinelappbinaryfile.FieldSentinelLibraryReportedID) + } + if m.addsize_bytes != nil { + fields = append(fields, sentinelappbinaryfile.FieldSizeBytes) + } + if m.addapp_binary_report_sequence != nil { + fields = append(fields, sentinelappbinaryfile.FieldAppBinaryReportSequence) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *SentinelAppBinaryFileMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case sentinelappbinaryfile.FieldSentinelInfoID: + return m.AddedSentinelInfoID() + case sentinelappbinaryfile.FieldSentinelLibraryReportedID: + return m.AddedSentinelLibraryReportedID() + case sentinelappbinaryfile.FieldSizeBytes: + return m.AddedSizeBytes() + case sentinelappbinaryfile.FieldAppBinaryReportSequence: + return m.AddedAppBinaryReportSequence() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SentinelAppBinaryFileMutation) AddField(name string, value ent.Value) error { + switch name { + case sentinelappbinaryfile.FieldSentinelInfoID: + v, ok := value.(model.InternalID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddSentinelInfoID(v) + return nil + case sentinelappbinaryfile.FieldSentinelLibraryReportedID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddSentinelLibraryReportedID(v) + return nil + case sentinelappbinaryfile.FieldSizeBytes: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddSizeBytes(v) + return nil + case sentinelappbinaryfile.FieldAppBinaryReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddAppBinaryReportSequence(v) + return nil + } + return fmt.Errorf("unknown SentinelAppBinaryFile numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *SentinelAppBinaryFileMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(sentinelappbinaryfile.FieldChunksInfo) { + fields = append(fields, sentinelappbinaryfile.FieldChunksInfo) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *SentinelAppBinaryFileMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *SentinelAppBinaryFileMutation) ClearField(name string) error { + switch name { + case sentinelappbinaryfile.FieldChunksInfo: + m.ClearChunksInfo() + return nil + } + return fmt.Errorf("unknown SentinelAppBinaryFile nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *SentinelAppBinaryFileMutation) ResetField(name string) error { + switch name { + case sentinelappbinaryfile.FieldSentinelInfoID: + m.ResetSentinelInfoID() + return nil + case sentinelappbinaryfile.FieldSentinelLibraryReportedID: + m.ResetSentinelLibraryReportedID() + return nil + case sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID: + m.ResetSentinelAppBinaryGeneratedID() + return nil + case sentinelappbinaryfile.FieldName: + m.ResetName() + return nil + case sentinelappbinaryfile.FieldSizeBytes: + m.ResetSizeBytes() + return nil + case sentinelappbinaryfile.FieldSha256: + m.ResetSha256() + return nil + case sentinelappbinaryfile.FieldServerFilePath: + m.ResetServerFilePath() + return nil + case sentinelappbinaryfile.FieldChunksInfo: + m.ResetChunksInfo() + return nil + case sentinelappbinaryfile.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case sentinelappbinaryfile.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case sentinelappbinaryfile.FieldAppBinaryReportSequence: + m.ResetAppBinaryReportSequence() + return nil + } + return fmt.Errorf("unknown SentinelAppBinaryFile field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *SentinelAppBinaryFileMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *SentinelAppBinaryFileMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *SentinelAppBinaryFileMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *SentinelAppBinaryFileMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *SentinelAppBinaryFileMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *SentinelAppBinaryFileMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *SentinelAppBinaryFileMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown SentinelAppBinaryFile unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *SentinelAppBinaryFileMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown SentinelAppBinaryFile edge %s", name) +} + +// SentinelInfoMutation represents an operation that mutates the SentinelInfo nodes in the graph. +type SentinelInfoMutation struct { + config + op Op + typ string + id *model.InternalID + url *string + alternative_urls *[]string + appendalternative_urls []string + get_token_path *string + download_file_base_path *string + updated_at *time.Time + created_at *time.Time + library_report_sequence *int64 + addlibrary_report_sequence *int64 + app_binary_report_sequence *int64 + addapp_binary_report_sequence *int64 + clearedFields map[string]struct{} + sentinel_library map[int]struct{} + removedsentinel_library map[int]struct{} + clearedsentinel_library bool + done bool + oldValue func(context.Context) (*SentinelInfo, error) + predicates []predicate.SentinelInfo +} + +var _ ent.Mutation = (*SentinelInfoMutation)(nil) + +// sentinelinfoOption allows management of the mutation configuration using functional options. +type sentinelinfoOption func(*SentinelInfoMutation) + +// newSentinelInfoMutation creates new mutation for the SentinelInfo entity. +func newSentinelInfoMutation(c config, op Op, opts ...sentinelinfoOption) *SentinelInfoMutation { + m := &SentinelInfoMutation{ + config: c, + op: op, + typ: TypeSentinelInfo, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withSentinelInfoID sets the ID field of the mutation. +func withSentinelInfoID(id model.InternalID) sentinelinfoOption { + return func(m *SentinelInfoMutation) { + var ( + err error + once sync.Once + value *SentinelInfo + ) + m.oldValue = func(ctx context.Context) (*SentinelInfo, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().SentinelInfo.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withSentinelInfo sets the old SentinelInfo of the mutation. +func withSentinelInfo(node *SentinelInfo) sentinelinfoOption { + return func(m *SentinelInfoMutation) { + m.oldValue = func(context.Context) (*SentinelInfo, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m SentinelInfoMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m SentinelInfoMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of SentinelInfo entities. +func (m *SentinelInfoMutation) SetID(id model.InternalID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *SentinelInfoMutation) ID() (id model.InternalID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *SentinelInfoMutation) IDs(ctx context.Context) ([]model.InternalID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []model.InternalID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().SentinelInfo.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetURL sets the "url" field. +func (m *SentinelInfoMutation) SetURL(s string) { + m.url = &s +} + +// URL returns the value of the "url" field in the mutation. +func (m *SentinelInfoMutation) URL() (r string, exists bool) { + v := m.url + if v == nil { + return + } + return *v, true +} + +// OldURL returns the old "url" field's value of the SentinelInfo entity. +// If the SentinelInfo object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelInfoMutation) OldURL(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldURL is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldURL requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldURL: %w", err) + } + return oldValue.URL, nil +} + +// ResetURL resets all changes to the "url" field. +func (m *SentinelInfoMutation) ResetURL() { + m.url = nil +} + +// SetAlternativeUrls sets the "alternative_urls" field. +func (m *SentinelInfoMutation) SetAlternativeUrls(s []string) { + m.alternative_urls = &s + m.appendalternative_urls = nil +} + +// AlternativeUrls returns the value of the "alternative_urls" field in the mutation. +func (m *SentinelInfoMutation) AlternativeUrls() (r []string, exists bool) { + v := m.alternative_urls + if v == nil { + return + } + return *v, true +} + +// OldAlternativeUrls returns the old "alternative_urls" field's value of the SentinelInfo entity. +// If the SentinelInfo object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelInfoMutation) OldAlternativeUrls(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAlternativeUrls is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAlternativeUrls requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAlternativeUrls: %w", err) + } + return oldValue.AlternativeUrls, nil +} + +// AppendAlternativeUrls adds s to the "alternative_urls" field. +func (m *SentinelInfoMutation) AppendAlternativeUrls(s []string) { + m.appendalternative_urls = append(m.appendalternative_urls, s...) +} + +// AppendedAlternativeUrls returns the list of values that were appended to the "alternative_urls" field in this mutation. +func (m *SentinelInfoMutation) AppendedAlternativeUrls() ([]string, bool) { + if len(m.appendalternative_urls) == 0 { + return nil, false + } + return m.appendalternative_urls, true +} + +// ClearAlternativeUrls clears the value of the "alternative_urls" field. +func (m *SentinelInfoMutation) ClearAlternativeUrls() { + m.alternative_urls = nil + m.appendalternative_urls = nil + m.clearedFields[sentinelinfo.FieldAlternativeUrls] = struct{}{} +} + +// AlternativeUrlsCleared returns if the "alternative_urls" field was cleared in this mutation. +func (m *SentinelInfoMutation) AlternativeUrlsCleared() bool { + _, ok := m.clearedFields[sentinelinfo.FieldAlternativeUrls] + return ok +} + +// ResetAlternativeUrls resets all changes to the "alternative_urls" field. +func (m *SentinelInfoMutation) ResetAlternativeUrls() { + m.alternative_urls = nil + m.appendalternative_urls = nil + delete(m.clearedFields, sentinelinfo.FieldAlternativeUrls) +} + +// SetGetTokenPath sets the "get_token_path" field. +func (m *SentinelInfoMutation) SetGetTokenPath(s string) { + m.get_token_path = &s +} + +// GetTokenPath returns the value of the "get_token_path" field in the mutation. +func (m *SentinelInfoMutation) GetTokenPath() (r string, exists bool) { + v := m.get_token_path + if v == nil { + return + } + return *v, true +} + +// OldGetTokenPath returns the old "get_token_path" field's value of the SentinelInfo entity. +// If the SentinelInfo object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelInfoMutation) OldGetTokenPath(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldGetTokenPath is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldGetTokenPath requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldGetTokenPath: %w", err) + } + return oldValue.GetTokenPath, nil +} + +// ClearGetTokenPath clears the value of the "get_token_path" field. +func (m *SentinelInfoMutation) ClearGetTokenPath() { + m.get_token_path = nil + m.clearedFields[sentinelinfo.FieldGetTokenPath] = struct{}{} +} + +// GetTokenPathCleared returns if the "get_token_path" field was cleared in this mutation. +func (m *SentinelInfoMutation) GetTokenPathCleared() bool { + _, ok := m.clearedFields[sentinelinfo.FieldGetTokenPath] + return ok +} + +// ResetGetTokenPath resets all changes to the "get_token_path" field. +func (m *SentinelInfoMutation) ResetGetTokenPath() { + m.get_token_path = nil + delete(m.clearedFields, sentinelinfo.FieldGetTokenPath) +} + +// SetDownloadFileBasePath sets the "download_file_base_path" field. +func (m *SentinelInfoMutation) SetDownloadFileBasePath(s string) { + m.download_file_base_path = &s +} + +// DownloadFileBasePath returns the value of the "download_file_base_path" field in the mutation. +func (m *SentinelInfoMutation) DownloadFileBasePath() (r string, exists bool) { + v := m.download_file_base_path + if v == nil { + return + } + return *v, true +} + +// OldDownloadFileBasePath returns the old "download_file_base_path" field's value of the SentinelInfo entity. +// If the SentinelInfo object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelInfoMutation) OldDownloadFileBasePath(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDownloadFileBasePath is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDownloadFileBasePath requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDownloadFileBasePath: %w", err) + } + return oldValue.DownloadFileBasePath, nil +} + +// ResetDownloadFileBasePath resets all changes to the "download_file_base_path" field. +func (m *SentinelInfoMutation) ResetDownloadFileBasePath() { + m.download_file_base_path = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *SentinelInfoMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *SentinelInfoMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the SentinelInfo entity. +// If the SentinelInfo object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelInfoMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *SentinelInfoMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *SentinelInfoMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *SentinelInfoMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the SentinelInfo entity. +// If the SentinelInfo object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelInfoMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *SentinelInfoMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (m *SentinelInfoMutation) SetLibraryReportSequence(i int64) { + m.library_report_sequence = &i + m.addlibrary_report_sequence = nil +} + +// LibraryReportSequence returns the value of the "library_report_sequence" field in the mutation. +func (m *SentinelInfoMutation) LibraryReportSequence() (r int64, exists bool) { + v := m.library_report_sequence + if v == nil { + return + } + return *v, true +} + +// OldLibraryReportSequence returns the old "library_report_sequence" field's value of the SentinelInfo entity. +// If the SentinelInfo object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelInfoMutation) OldLibraryReportSequence(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLibraryReportSequence is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLibraryReportSequence requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLibraryReportSequence: %w", err) + } + return oldValue.LibraryReportSequence, nil +} + +// AddLibraryReportSequence adds i to the "library_report_sequence" field. +func (m *SentinelInfoMutation) AddLibraryReportSequence(i int64) { + if m.addlibrary_report_sequence != nil { + *m.addlibrary_report_sequence += i + } else { + m.addlibrary_report_sequence = &i + } +} + +// AddedLibraryReportSequence returns the value that was added to the "library_report_sequence" field in this mutation. +func (m *SentinelInfoMutation) AddedLibraryReportSequence() (r int64, exists bool) { + v := m.addlibrary_report_sequence + if v == nil { + return + } + return *v, true +} + +// ResetLibraryReportSequence resets all changes to the "library_report_sequence" field. +func (m *SentinelInfoMutation) ResetLibraryReportSequence() { + m.library_report_sequence = nil + m.addlibrary_report_sequence = nil +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (m *SentinelInfoMutation) SetAppBinaryReportSequence(i int64) { + m.app_binary_report_sequence = &i + m.addapp_binary_report_sequence = nil +} + +// AppBinaryReportSequence returns the value of the "app_binary_report_sequence" field in the mutation. +func (m *SentinelInfoMutation) AppBinaryReportSequence() (r int64, exists bool) { + v := m.app_binary_report_sequence + if v == nil { + return + } + return *v, true +} + +// OldAppBinaryReportSequence returns the old "app_binary_report_sequence" field's value of the SentinelInfo entity. +// If the SentinelInfo object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelInfoMutation) OldAppBinaryReportSequence(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAppBinaryReportSequence is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAppBinaryReportSequence requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAppBinaryReportSequence: %w", err) + } + return oldValue.AppBinaryReportSequence, nil +} + +// AddAppBinaryReportSequence adds i to the "app_binary_report_sequence" field. +func (m *SentinelInfoMutation) AddAppBinaryReportSequence(i int64) { + if m.addapp_binary_report_sequence != nil { + *m.addapp_binary_report_sequence += i + } else { + m.addapp_binary_report_sequence = &i + } +} + +// AddedAppBinaryReportSequence returns the value that was added to the "app_binary_report_sequence" field in this mutation. +func (m *SentinelInfoMutation) AddedAppBinaryReportSequence() (r int64, exists bool) { + v := m.addapp_binary_report_sequence + if v == nil { + return + } + return *v, true +} + +// ResetAppBinaryReportSequence resets all changes to the "app_binary_report_sequence" field. +func (m *SentinelInfoMutation) ResetAppBinaryReportSequence() { + m.app_binary_report_sequence = nil + m.addapp_binary_report_sequence = nil +} + +// AddSentinelLibraryIDs adds the "sentinel_library" edge to the SentinelLibrary entity by ids. +func (m *SentinelInfoMutation) AddSentinelLibraryIDs(ids ...int) { + if m.sentinel_library == nil { + m.sentinel_library = make(map[int]struct{}) + } + for i := range ids { + m.sentinel_library[ids[i]] = struct{}{} + } +} + +// ClearSentinelLibrary clears the "sentinel_library" edge to the SentinelLibrary entity. +func (m *SentinelInfoMutation) ClearSentinelLibrary() { + m.clearedsentinel_library = true +} + +// SentinelLibraryCleared reports if the "sentinel_library" edge to the SentinelLibrary entity was cleared. +func (m *SentinelInfoMutation) SentinelLibraryCleared() bool { + return m.clearedsentinel_library +} + +// RemoveSentinelLibraryIDs removes the "sentinel_library" edge to the SentinelLibrary entity by IDs. +func (m *SentinelInfoMutation) RemoveSentinelLibraryIDs(ids ...int) { + if m.removedsentinel_library == nil { + m.removedsentinel_library = make(map[int]struct{}) + } + for i := range ids { + delete(m.sentinel_library, ids[i]) + m.removedsentinel_library[ids[i]] = struct{}{} + } +} + +// RemovedSentinelLibrary returns the removed IDs of the "sentinel_library" edge to the SentinelLibrary entity. +func (m *SentinelInfoMutation) RemovedSentinelLibraryIDs() (ids []int) { + for id := range m.removedsentinel_library { + ids = append(ids, id) + } + return +} + +// SentinelLibraryIDs returns the "sentinel_library" edge IDs in the mutation. +func (m *SentinelInfoMutation) SentinelLibraryIDs() (ids []int) { + for id := range m.sentinel_library { + ids = append(ids, id) + } + return +} + +// ResetSentinelLibrary resets all changes to the "sentinel_library" edge. +func (m *SentinelInfoMutation) ResetSentinelLibrary() { + m.sentinel_library = nil + m.clearedsentinel_library = false + m.removedsentinel_library = nil +} + +// Where appends a list predicates to the SentinelInfoMutation builder. +func (m *SentinelInfoMutation) Where(ps ...predicate.SentinelInfo) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the SentinelInfoMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *SentinelInfoMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.SentinelInfo, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *SentinelInfoMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *SentinelInfoMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (SentinelInfo). +func (m *SentinelInfoMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *SentinelInfoMutation) Fields() []string { + fields := make([]string, 0, 8) + if m.url != nil { + fields = append(fields, sentinelinfo.FieldURL) + } + if m.alternative_urls != nil { + fields = append(fields, sentinelinfo.FieldAlternativeUrls) + } + if m.get_token_path != nil { + fields = append(fields, sentinelinfo.FieldGetTokenPath) + } + if m.download_file_base_path != nil { + fields = append(fields, sentinelinfo.FieldDownloadFileBasePath) + } + if m.updated_at != nil { + fields = append(fields, sentinelinfo.FieldUpdatedAt) + } + if m.created_at != nil { + fields = append(fields, sentinelinfo.FieldCreatedAt) + } + if m.library_report_sequence != nil { + fields = append(fields, sentinelinfo.FieldLibraryReportSequence) + } + if m.app_binary_report_sequence != nil { + fields = append(fields, sentinelinfo.FieldAppBinaryReportSequence) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *SentinelInfoMutation) Field(name string) (ent.Value, bool) { + switch name { + case sentinelinfo.FieldURL: + return m.URL() + case sentinelinfo.FieldAlternativeUrls: + return m.AlternativeUrls() + case sentinelinfo.FieldGetTokenPath: + return m.GetTokenPath() + case sentinelinfo.FieldDownloadFileBasePath: + return m.DownloadFileBasePath() + case sentinelinfo.FieldUpdatedAt: + return m.UpdatedAt() + case sentinelinfo.FieldCreatedAt: + return m.CreatedAt() + case sentinelinfo.FieldLibraryReportSequence: + return m.LibraryReportSequence() + case sentinelinfo.FieldAppBinaryReportSequence: + return m.AppBinaryReportSequence() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *SentinelInfoMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case sentinelinfo.FieldURL: + return m.OldURL(ctx) + case sentinelinfo.FieldAlternativeUrls: + return m.OldAlternativeUrls(ctx) + case sentinelinfo.FieldGetTokenPath: + return m.OldGetTokenPath(ctx) + case sentinelinfo.FieldDownloadFileBasePath: + return m.OldDownloadFileBasePath(ctx) + case sentinelinfo.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case sentinelinfo.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case sentinelinfo.FieldLibraryReportSequence: + return m.OldLibraryReportSequence(ctx) + case sentinelinfo.FieldAppBinaryReportSequence: + return m.OldAppBinaryReportSequence(ctx) + } + return nil, fmt.Errorf("unknown SentinelInfo field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SentinelInfoMutation) SetField(name string, value ent.Value) error { + switch name { + case sentinelinfo.FieldURL: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetURL(v) + return nil + case sentinelinfo.FieldAlternativeUrls: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAlternativeUrls(v) + return nil + case sentinelinfo.FieldGetTokenPath: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetGetTokenPath(v) + return nil + case sentinelinfo.FieldDownloadFileBasePath: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDownloadFileBasePath(v) + return nil + case sentinelinfo.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case sentinelinfo.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case sentinelinfo.FieldLibraryReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLibraryReportSequence(v) + return nil + case sentinelinfo.FieldAppBinaryReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAppBinaryReportSequence(v) + return nil + } + return fmt.Errorf("unknown SentinelInfo field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *SentinelInfoMutation) AddedFields() []string { + var fields []string + if m.addlibrary_report_sequence != nil { + fields = append(fields, sentinelinfo.FieldLibraryReportSequence) + } + if m.addapp_binary_report_sequence != nil { + fields = append(fields, sentinelinfo.FieldAppBinaryReportSequence) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *SentinelInfoMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case sentinelinfo.FieldLibraryReportSequence: + return m.AddedLibraryReportSequence() + case sentinelinfo.FieldAppBinaryReportSequence: + return m.AddedAppBinaryReportSequence() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SentinelInfoMutation) AddField(name string, value ent.Value) error { + switch name { + case sentinelinfo.FieldLibraryReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddLibraryReportSequence(v) + return nil + case sentinelinfo.FieldAppBinaryReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddAppBinaryReportSequence(v) + return nil + } + return fmt.Errorf("unknown SentinelInfo numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *SentinelInfoMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(sentinelinfo.FieldAlternativeUrls) { + fields = append(fields, sentinelinfo.FieldAlternativeUrls) + } + if m.FieldCleared(sentinelinfo.FieldGetTokenPath) { + fields = append(fields, sentinelinfo.FieldGetTokenPath) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *SentinelInfoMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *SentinelInfoMutation) ClearField(name string) error { + switch name { + case sentinelinfo.FieldAlternativeUrls: + m.ClearAlternativeUrls() + return nil + case sentinelinfo.FieldGetTokenPath: + m.ClearGetTokenPath() + return nil + } + return fmt.Errorf("unknown SentinelInfo nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *SentinelInfoMutation) ResetField(name string) error { + switch name { + case sentinelinfo.FieldURL: + m.ResetURL() + return nil + case sentinelinfo.FieldAlternativeUrls: + m.ResetAlternativeUrls() + return nil + case sentinelinfo.FieldGetTokenPath: + m.ResetGetTokenPath() + return nil + case sentinelinfo.FieldDownloadFileBasePath: + m.ResetDownloadFileBasePath() + return nil + case sentinelinfo.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case sentinelinfo.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case sentinelinfo.FieldLibraryReportSequence: + m.ResetLibraryReportSequence() + return nil + case sentinelinfo.FieldAppBinaryReportSequence: + m.ResetAppBinaryReportSequence() + return nil + } + return fmt.Errorf("unknown SentinelInfo field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *SentinelInfoMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.sentinel_library != nil { + edges = append(edges, sentinelinfo.EdgeSentinelLibrary) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *SentinelInfoMutation) AddedIDs(name string) []ent.Value { + switch name { + case sentinelinfo.EdgeSentinelLibrary: + ids := make([]ent.Value, 0, len(m.sentinel_library)) + for id := range m.sentinel_library { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *SentinelInfoMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + if m.removedsentinel_library != nil { + edges = append(edges, sentinelinfo.EdgeSentinelLibrary) + } + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *SentinelInfoMutation) RemovedIDs(name string) []ent.Value { + switch name { + case sentinelinfo.EdgeSentinelLibrary: + ids := make([]ent.Value, 0, len(m.removedsentinel_library)) + for id := range m.removedsentinel_library { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *SentinelInfoMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedsentinel_library { + edges = append(edges, sentinelinfo.EdgeSentinelLibrary) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *SentinelInfoMutation) EdgeCleared(name string) bool { + switch name { + case sentinelinfo.EdgeSentinelLibrary: + return m.clearedsentinel_library + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *SentinelInfoMutation) ClearEdge(name string) error { + switch name { + } + return fmt.Errorf("unknown SentinelInfo unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *SentinelInfoMutation) ResetEdge(name string) error { + switch name { + case sentinelinfo.EdgeSentinelLibrary: + m.ResetSentinelLibrary() + return nil + } + return fmt.Errorf("unknown SentinelInfo edge %s", name) +} + +// SentinelLibraryMutation represents an operation that mutates the SentinelLibrary nodes in the graph. +type SentinelLibraryMutation struct { + config + op Op + typ string + id *int + reported_id *int64 + addreported_id *int64 + download_base_path *string + updated_at *time.Time + created_at *time.Time + library_report_sequence *int64 + addlibrary_report_sequence *int64 + clearedFields map[string]struct{} + sentinel_info *model.InternalID + clearedsentinel_info bool + done bool + oldValue func(context.Context) (*SentinelLibrary, error) + predicates []predicate.SentinelLibrary +} + +var _ ent.Mutation = (*SentinelLibraryMutation)(nil) + +// sentinellibraryOption allows management of the mutation configuration using functional options. +type sentinellibraryOption func(*SentinelLibraryMutation) + +// newSentinelLibraryMutation creates new mutation for the SentinelLibrary entity. +func newSentinelLibraryMutation(c config, op Op, opts ...sentinellibraryOption) *SentinelLibraryMutation { + m := &SentinelLibraryMutation{ + config: c, + op: op, + typ: TypeSentinelLibrary, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withSentinelLibraryID sets the ID field of the mutation. +func withSentinelLibraryID(id int) sentinellibraryOption { + return func(m *SentinelLibraryMutation) { + var ( + err error + once sync.Once + value *SentinelLibrary + ) + m.oldValue = func(ctx context.Context) (*SentinelLibrary, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().SentinelLibrary.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withSentinelLibrary sets the old SentinelLibrary of the mutation. +func withSentinelLibrary(node *SentinelLibrary) sentinellibraryOption { + return func(m *SentinelLibraryMutation) { + m.oldValue = func(context.Context) (*SentinelLibrary, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m SentinelLibraryMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m SentinelLibraryMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *SentinelLibraryMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *SentinelLibraryMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().SentinelLibrary.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (m *SentinelLibraryMutation) SetSentinelInfoID(mi model.InternalID) { + m.sentinel_info = &mi +} + +// SentinelInfoID returns the value of the "sentinel_info_id" field in the mutation. +func (m *SentinelLibraryMutation) SentinelInfoID() (r model.InternalID, exists bool) { + v := m.sentinel_info + if v == nil { + return + } + return *v, true +} + +// OldSentinelInfoID returns the old "sentinel_info_id" field's value of the SentinelLibrary entity. +// If the SentinelLibrary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelLibraryMutation) OldSentinelInfoID(ctx context.Context) (v model.InternalID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSentinelInfoID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSentinelInfoID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSentinelInfoID: %w", err) + } + return oldValue.SentinelInfoID, nil +} + +// ResetSentinelInfoID resets all changes to the "sentinel_info_id" field. +func (m *SentinelLibraryMutation) ResetSentinelInfoID() { + m.sentinel_info = nil +} + +// SetReportedID sets the "reported_id" field. +func (m *SentinelLibraryMutation) SetReportedID(i int64) { + m.reported_id = &i + m.addreported_id = nil +} + +// ReportedID returns the value of the "reported_id" field in the mutation. +func (m *SentinelLibraryMutation) ReportedID() (r int64, exists bool) { + v := m.reported_id + if v == nil { + return + } + return *v, true +} + +// OldReportedID returns the old "reported_id" field's value of the SentinelLibrary entity. +// If the SentinelLibrary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelLibraryMutation) OldReportedID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldReportedID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldReportedID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldReportedID: %w", err) + } + return oldValue.ReportedID, nil +} + +// AddReportedID adds i to the "reported_id" field. +func (m *SentinelLibraryMutation) AddReportedID(i int64) { + if m.addreported_id != nil { + *m.addreported_id += i + } else { + m.addreported_id = &i + } +} + +// AddedReportedID returns the value that was added to the "reported_id" field in this mutation. +func (m *SentinelLibraryMutation) AddedReportedID() (r int64, exists bool) { + v := m.addreported_id + if v == nil { + return + } + return *v, true +} + +// ResetReportedID resets all changes to the "reported_id" field. +func (m *SentinelLibraryMutation) ResetReportedID() { + m.reported_id = nil + m.addreported_id = nil +} + +// SetDownloadBasePath sets the "download_base_path" field. +func (m *SentinelLibraryMutation) SetDownloadBasePath(s string) { + m.download_base_path = &s +} + +// DownloadBasePath returns the value of the "download_base_path" field in the mutation. +func (m *SentinelLibraryMutation) DownloadBasePath() (r string, exists bool) { + v := m.download_base_path + if v == nil { + return + } + return *v, true +} + +// OldDownloadBasePath returns the old "download_base_path" field's value of the SentinelLibrary entity. +// If the SentinelLibrary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelLibraryMutation) OldDownloadBasePath(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDownloadBasePath is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDownloadBasePath requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDownloadBasePath: %w", err) + } + return oldValue.DownloadBasePath, nil +} + +// ResetDownloadBasePath resets all changes to the "download_base_path" field. +func (m *SentinelLibraryMutation) ResetDownloadBasePath() { + m.download_base_path = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *SentinelLibraryMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *SentinelLibraryMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the SentinelLibrary entity. +// If the SentinelLibrary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelLibraryMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *SentinelLibraryMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *SentinelLibraryMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *SentinelLibraryMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the SentinelLibrary entity. +// If the SentinelLibrary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelLibraryMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *SentinelLibraryMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (m *SentinelLibraryMutation) SetLibraryReportSequence(i int64) { + m.library_report_sequence = &i + m.addlibrary_report_sequence = nil +} + +// LibraryReportSequence returns the value of the "library_report_sequence" field in the mutation. +func (m *SentinelLibraryMutation) LibraryReportSequence() (r int64, exists bool) { + v := m.library_report_sequence + if v == nil { + return + } + return *v, true +} + +// OldLibraryReportSequence returns the old "library_report_sequence" field's value of the SentinelLibrary entity. +// If the SentinelLibrary object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *SentinelLibraryMutation) OldLibraryReportSequence(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLibraryReportSequence is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLibraryReportSequence requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLibraryReportSequence: %w", err) + } + return oldValue.LibraryReportSequence, nil +} + +// AddLibraryReportSequence adds i to the "library_report_sequence" field. +func (m *SentinelLibraryMutation) AddLibraryReportSequence(i int64) { + if m.addlibrary_report_sequence != nil { + *m.addlibrary_report_sequence += i + } else { + m.addlibrary_report_sequence = &i + } +} + +// AddedLibraryReportSequence returns the value that was added to the "library_report_sequence" field in this mutation. +func (m *SentinelLibraryMutation) AddedLibraryReportSequence() (r int64, exists bool) { + v := m.addlibrary_report_sequence + if v == nil { + return + } + return *v, true +} + +// ResetLibraryReportSequence resets all changes to the "library_report_sequence" field. +func (m *SentinelLibraryMutation) ResetLibraryReportSequence() { + m.library_report_sequence = nil + m.addlibrary_report_sequence = nil +} + +// ClearSentinelInfo clears the "sentinel_info" edge to the SentinelInfo entity. +func (m *SentinelLibraryMutation) ClearSentinelInfo() { + m.clearedsentinel_info = true + m.clearedFields[sentinellibrary.FieldSentinelInfoID] = struct{}{} +} + +// SentinelInfoCleared reports if the "sentinel_info" edge to the SentinelInfo entity was cleared. +func (m *SentinelLibraryMutation) SentinelInfoCleared() bool { + return m.clearedsentinel_info +} + +// SentinelInfoIDs returns the "sentinel_info" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// SentinelInfoID instead. It exists only for internal usage by the builders. +func (m *SentinelLibraryMutation) SentinelInfoIDs() (ids []model.InternalID) { + if id := m.sentinel_info; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetSentinelInfo resets all changes to the "sentinel_info" edge. +func (m *SentinelLibraryMutation) ResetSentinelInfo() { + m.sentinel_info = nil + m.clearedsentinel_info = false +} + +// Where appends a list predicates to the SentinelLibraryMutation builder. +func (m *SentinelLibraryMutation) Where(ps ...predicate.SentinelLibrary) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the SentinelLibraryMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *SentinelLibraryMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.SentinelLibrary, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *SentinelLibraryMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *SentinelLibraryMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (SentinelLibrary). +func (m *SentinelLibraryMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *SentinelLibraryMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.sentinel_info != nil { + fields = append(fields, sentinellibrary.FieldSentinelInfoID) + } + if m.reported_id != nil { + fields = append(fields, sentinellibrary.FieldReportedID) + } + if m.download_base_path != nil { + fields = append(fields, sentinellibrary.FieldDownloadBasePath) + } + if m.updated_at != nil { + fields = append(fields, sentinellibrary.FieldUpdatedAt) + } + if m.created_at != nil { + fields = append(fields, sentinellibrary.FieldCreatedAt) + } + if m.library_report_sequence != nil { + fields = append(fields, sentinellibrary.FieldLibraryReportSequence) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *SentinelLibraryMutation) Field(name string) (ent.Value, bool) { + switch name { + case sentinellibrary.FieldSentinelInfoID: + return m.SentinelInfoID() + case sentinellibrary.FieldReportedID: + return m.ReportedID() + case sentinellibrary.FieldDownloadBasePath: + return m.DownloadBasePath() + case sentinellibrary.FieldUpdatedAt: + return m.UpdatedAt() + case sentinellibrary.FieldCreatedAt: + return m.CreatedAt() + case sentinellibrary.FieldLibraryReportSequence: + return m.LibraryReportSequence() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *SentinelLibraryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case sentinellibrary.FieldSentinelInfoID: + return m.OldSentinelInfoID(ctx) + case sentinellibrary.FieldReportedID: + return m.OldReportedID(ctx) + case sentinellibrary.FieldDownloadBasePath: + return m.OldDownloadBasePath(ctx) + case sentinellibrary.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case sentinellibrary.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case sentinellibrary.FieldLibraryReportSequence: + return m.OldLibraryReportSequence(ctx) + } + return nil, fmt.Errorf("unknown SentinelLibrary field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SentinelLibraryMutation) SetField(name string, value ent.Value) error { + switch name { + case sentinellibrary.FieldSentinelInfoID: + v, ok := value.(model.InternalID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSentinelInfoID(v) + return nil + case sentinellibrary.FieldReportedID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetReportedID(v) + return nil + case sentinellibrary.FieldDownloadBasePath: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDownloadBasePath(v) + return nil + case sentinellibrary.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case sentinellibrary.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case sentinellibrary.FieldLibraryReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLibraryReportSequence(v) + return nil + } + return fmt.Errorf("unknown SentinelLibrary field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *SentinelLibraryMutation) AddedFields() []string { + var fields []string + if m.addreported_id != nil { + fields = append(fields, sentinellibrary.FieldReportedID) + } + if m.addlibrary_report_sequence != nil { + fields = append(fields, sentinellibrary.FieldLibraryReportSequence) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *SentinelLibraryMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case sentinellibrary.FieldReportedID: + return m.AddedReportedID() + case sentinellibrary.FieldLibraryReportSequence: + return m.AddedLibraryReportSequence() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *SentinelLibraryMutation) AddField(name string, value ent.Value) error { + switch name { + case sentinellibrary.FieldReportedID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddReportedID(v) + return nil + case sentinellibrary.FieldLibraryReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddLibraryReportSequence(v) + return nil + } + return fmt.Errorf("unknown SentinelLibrary numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *SentinelLibraryMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *SentinelLibraryMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *SentinelLibraryMutation) ClearField(name string) error { + return fmt.Errorf("unknown SentinelLibrary nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *SentinelLibraryMutation) ResetField(name string) error { + switch name { + case sentinellibrary.FieldSentinelInfoID: + m.ResetSentinelInfoID() + return nil + case sentinellibrary.FieldReportedID: + m.ResetReportedID() + return nil + case sentinellibrary.FieldDownloadBasePath: + m.ResetDownloadBasePath() + return nil + case sentinellibrary.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case sentinellibrary.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case sentinellibrary.FieldLibraryReportSequence: + m.ResetLibraryReportSequence() + return nil + } + return fmt.Errorf("unknown SentinelLibrary field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *SentinelLibraryMutation) AddedEdges() []string { + edges := make([]string, 0, 1) + if m.sentinel_info != nil { + edges = append(edges, sentinellibrary.EdgeSentinelInfo) + } + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *SentinelLibraryMutation) AddedIDs(name string) []ent.Value { + switch name { + case sentinellibrary.EdgeSentinelInfo: + if id := m.sentinel_info; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *SentinelLibraryMutation) RemovedEdges() []string { + edges := make([]string, 0, 1) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *SentinelLibraryMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *SentinelLibraryMutation) ClearedEdges() []string { + edges := make([]string, 0, 1) + if m.clearedsentinel_info { + edges = append(edges, sentinellibrary.EdgeSentinelInfo) + } + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *SentinelLibraryMutation) EdgeCleared(name string) bool { + switch name { + case sentinellibrary.EdgeSentinelInfo: + return m.clearedsentinel_info + } + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *SentinelLibraryMutation) ClearEdge(name string) error { + switch name { + case sentinellibrary.EdgeSentinelInfo: + m.ClearSentinelInfo() + return nil + } + return fmt.Errorf("unknown SentinelLibrary unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *SentinelLibraryMutation) ResetEdge(name string) error { + switch name { + case sentinellibrary.EdgeSentinelInfo: + m.ResetSentinelInfo() + return nil + } + return fmt.Errorf("unknown SentinelLibrary edge %s", name) +} + // SessionMutation represents an operation that mutates the Session nodes in the graph. type SessionMutation struct { config diff --git a/internal/data/internal/ent/predicate/predicate.go b/internal/data/internal/ent/predicate/predicate.go index b03fedb6..eab6ab1b 100644 --- a/internal/data/internal/ent/predicate/predicate.go +++ b/internal/data/internal/ent/predicate/predicate.go @@ -72,6 +72,18 @@ type PorterContext func(*sql.Selector) // PorterInstance is the predicate function for porterinstance builders. type PorterInstance func(*sql.Selector) +// SentinelAppBinary is the predicate function for sentinelappbinary builders. +type SentinelAppBinary func(*sql.Selector) + +// SentinelAppBinaryFile is the predicate function for sentinelappbinaryfile builders. +type SentinelAppBinaryFile func(*sql.Selector) + +// SentinelInfo is the predicate function for sentinelinfo builders. +type SentinelInfo func(*sql.Selector) + +// SentinelLibrary is the predicate function for sentinellibrary builders. +type SentinelLibrary func(*sql.Selector) + // Session is the predicate function for session builders. type Session func(*sql.Selector) diff --git a/internal/data/internal/ent/runtime.go b/internal/data/internal/ent/runtime.go index b26d0d81..faaa2d61 100644 --- a/internal/data/internal/ent/runtime.go +++ b/internal/data/internal/ent/runtime.go @@ -27,6 +27,10 @@ import ( "github.com/tuihub/librarian/internal/data/internal/ent/portercontext" "github.com/tuihub/librarian/internal/data/internal/ent/porterinstance" "github.com/tuihub/librarian/internal/data/internal/ent/schema" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" "github.com/tuihub/librarian/internal/data/internal/ent/session" "github.com/tuihub/librarian/internal/data/internal/ent/storeapp" "github.com/tuihub/librarian/internal/data/internal/ent/storeappbinary" @@ -307,6 +311,54 @@ func init() { porterinstanceDescCreatedAt := porterinstanceFields[14].Descriptor() // porterinstance.DefaultCreatedAt holds the default value on creation for the created_at field. porterinstance.DefaultCreatedAt = porterinstanceDescCreatedAt.Default.(func() time.Time) + sentinelappbinaryFields := schema.SentinelAppBinary{}.Fields() + _ = sentinelappbinaryFields + // sentinelappbinaryDescUpdatedAt is the schema descriptor for updated_at field. + sentinelappbinaryDescUpdatedAt := sentinelappbinaryFields[9].Descriptor() + // sentinelappbinary.DefaultUpdatedAt holds the default value on creation for the updated_at field. + sentinelappbinary.DefaultUpdatedAt = sentinelappbinaryDescUpdatedAt.Default.(func() time.Time) + // sentinelappbinary.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + sentinelappbinary.UpdateDefaultUpdatedAt = sentinelappbinaryDescUpdatedAt.UpdateDefault.(func() time.Time) + // sentinelappbinaryDescCreatedAt is the schema descriptor for created_at field. + sentinelappbinaryDescCreatedAt := sentinelappbinaryFields[10].Descriptor() + // sentinelappbinary.DefaultCreatedAt holds the default value on creation for the created_at field. + sentinelappbinary.DefaultCreatedAt = sentinelappbinaryDescCreatedAt.Default.(func() time.Time) + sentinelappbinaryfileFields := schema.SentinelAppBinaryFile{}.Fields() + _ = sentinelappbinaryfileFields + // sentinelappbinaryfileDescUpdatedAt is the schema descriptor for updated_at field. + sentinelappbinaryfileDescUpdatedAt := sentinelappbinaryfileFields[8].Descriptor() + // sentinelappbinaryfile.DefaultUpdatedAt holds the default value on creation for the updated_at field. + sentinelappbinaryfile.DefaultUpdatedAt = sentinelappbinaryfileDescUpdatedAt.Default.(func() time.Time) + // sentinelappbinaryfile.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + sentinelappbinaryfile.UpdateDefaultUpdatedAt = sentinelappbinaryfileDescUpdatedAt.UpdateDefault.(func() time.Time) + // sentinelappbinaryfileDescCreatedAt is the schema descriptor for created_at field. + sentinelappbinaryfileDescCreatedAt := sentinelappbinaryfileFields[9].Descriptor() + // sentinelappbinaryfile.DefaultCreatedAt holds the default value on creation for the created_at field. + sentinelappbinaryfile.DefaultCreatedAt = sentinelappbinaryfileDescCreatedAt.Default.(func() time.Time) + sentinelinfoFields := schema.SentinelInfo{}.Fields() + _ = sentinelinfoFields + // sentinelinfoDescUpdatedAt is the schema descriptor for updated_at field. + sentinelinfoDescUpdatedAt := sentinelinfoFields[5].Descriptor() + // sentinelinfo.DefaultUpdatedAt holds the default value on creation for the updated_at field. + sentinelinfo.DefaultUpdatedAt = sentinelinfoDescUpdatedAt.Default.(func() time.Time) + // sentinelinfo.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + sentinelinfo.UpdateDefaultUpdatedAt = sentinelinfoDescUpdatedAt.UpdateDefault.(func() time.Time) + // sentinelinfoDescCreatedAt is the schema descriptor for created_at field. + sentinelinfoDescCreatedAt := sentinelinfoFields[6].Descriptor() + // sentinelinfo.DefaultCreatedAt holds the default value on creation for the created_at field. + sentinelinfo.DefaultCreatedAt = sentinelinfoDescCreatedAt.Default.(func() time.Time) + sentinellibraryFields := schema.SentinelLibrary{}.Fields() + _ = sentinellibraryFields + // sentinellibraryDescUpdatedAt is the schema descriptor for updated_at field. + sentinellibraryDescUpdatedAt := sentinellibraryFields[3].Descriptor() + // sentinellibrary.DefaultUpdatedAt holds the default value on creation for the updated_at field. + sentinellibrary.DefaultUpdatedAt = sentinellibraryDescUpdatedAt.Default.(func() time.Time) + // sentinellibrary.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. + sentinellibrary.UpdateDefaultUpdatedAt = sentinellibraryDescUpdatedAt.UpdateDefault.(func() time.Time) + // sentinellibraryDescCreatedAt is the schema descriptor for created_at field. + sentinellibraryDescCreatedAt := sentinellibraryFields[4].Descriptor() + // sentinellibrary.DefaultCreatedAt holds the default value on creation for the created_at field. + sentinellibrary.DefaultCreatedAt = sentinellibraryDescCreatedAt.Default.(func() time.Time) sessionFields := schema.Session{}.Fields() _ = sessionFields // sessionDescUpdatedAt is the schema descriptor for updated_at field. diff --git a/internal/data/internal/ent/schema/sentinel_app_binary.go b/internal/data/internal/ent/schema/sentinel_app_binary.go new file mode 100644 index 00000000..9b76e87a --- /dev/null +++ b/internal/data/internal/ent/schema/sentinel_app_binary.go @@ -0,0 +1,57 @@ +package schema + +import ( + "time" + + "github.com/tuihub/librarian/internal/model" + + "entgo.io/ent" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" +) + +type SentinelAppBinary struct { + ent.Schema +} + +func (SentinelAppBinary) Fields() []ent.Field { + return []ent.Field{ + // field.Int("sentinel_library_id"), + field.Int64("sentinel_info_id").GoType(model.InternalID(0)), + field.Int64("sentinel_library_reported_id"), + field.String("generated_id"), + field.Int64("size_bytes"), + field.Bool("need_token"), + field.String("name").Optional(), + field.String("version").Optional(), + field.String("developer").Optional(), + field.String("publisher").Optional(), + field.Time("updated_at"). + Default(time.Now).UpdateDefault(time.Now), + field.Time("created_at"). + Default(time.Now), + field.Int64("app_binary_report_sequence"), + } +} + +func (SentinelAppBinary) Indexes() []ent.Index { + return []ent.Index{ + // index.Fields("sentinel_library_id", "generated_id"). + // Unique(), + index.Fields("sentinel_info_id", "sentinel_library_reported_id", "generated_id"). + Unique(), + index.Fields("generated_id"), + index.Fields("app_binary_report_sequence"), + } +} + +func (SentinelAppBinary) Edges() []ent.Edge { + return []ent.Edge{ + // edge.To("sentinel_library", SentinelLibrary.Type). + // Required(). + // Unique(). + // Field("sentinel_library_id"), + // edge.From("sentinel_app_binary_file", SentinelAppBinaryFile.Type). + // Ref("sentinel_app_binary"), + } +} diff --git a/internal/data/internal/ent/schema/sentinel_app_binary_file.go b/internal/data/internal/ent/schema/sentinel_app_binary_file.go new file mode 100644 index 00000000..9f9aa869 --- /dev/null +++ b/internal/data/internal/ent/schema/sentinel_app_binary_file.go @@ -0,0 +1,54 @@ +package schema + +import ( + "time" + + "github.com/tuihub/librarian/internal/model" + + "entgo.io/ent" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" +) + +type SentinelAppBinaryFile struct { + ent.Schema +} + +func (SentinelAppBinaryFile) Fields() []ent.Field { + return []ent.Field{ + // field.Int("sentinel_app_binary_id"), + field.Int64("sentinel_info_id").GoType(model.InternalID(0)), + field.Int64("sentinel_library_reported_id"), + field.String("sentinel_app_binary_generated_id"), + field.String("name"), + field.Int64("size_bytes"), + field.Bytes("sha256"), + field.String("server_file_path"), + field.String("chunks_info").Optional(), + field.Time("updated_at"). + Default(time.Now).UpdateDefault(time.Now), + field.Time("created_at"). + Default(time.Now), + field.Int64("app_binary_report_sequence"), + } +} + +func (SentinelAppBinaryFile) Indexes() []ent.Index { + return []ent.Index{ + // index.Fields("sentinel_app_binary_id", "server_file_path"). + // Unique(), + index.Fields("sentinel_info_id", "sentinel_library_reported_id", + "sentinel_app_binary_generated_id", "server_file_path"). + Unique(), + index.Fields("app_binary_report_sequence"), + } +} + +func (SentinelAppBinaryFile) Edges() []ent.Edge { + return []ent.Edge{ + // edge.To("sentinel_app_binary", SentinelAppBinary.Type). + // Required(). + // Unique(). + // Field("sentinel_app_binary_id"), + } +} diff --git a/internal/data/internal/ent/schema/sentinel_info.go b/internal/data/internal/ent/schema/sentinel_info.go new file mode 100644 index 00000000..f435b4bd --- /dev/null +++ b/internal/data/internal/ent/schema/sentinel_info.go @@ -0,0 +1,40 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" +) + +type SentinelInfo struct { + ent.Schema +} + +func (SentinelInfo) Fields() []ent.Field { + return []ent.Field{ + defaultPrimaryKey(), + field.String("url"), + field.Strings("alternative_urls").Optional(), + field.String("get_token_path").Optional(), + field.String("download_file_base_path"), + field.Time("updated_at"). + Default(time.Now).UpdateDefault(time.Now), + field.Time("created_at"). + Default(time.Now), + field.Int64("library_report_sequence"), + field.Int64("app_binary_report_sequence"), + } +} + +func (SentinelInfo) Indexes() []ent.Index { + return []ent.Index{} +} + +func (SentinelInfo) Edges() []ent.Edge { + return []ent.Edge{ + edge.From("sentinel_library", SentinelLibrary.Type). + Ref("sentinel_info"), + } +} diff --git a/internal/data/internal/ent/schema/sentinel_library.go b/internal/data/internal/ent/schema/sentinel_library.go new file mode 100644 index 00000000..730db502 --- /dev/null +++ b/internal/data/internal/ent/schema/sentinel_library.go @@ -0,0 +1,48 @@ +package schema + +import ( + "time" + + "github.com/tuihub/librarian/internal/model" + + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" +) + +type SentinelLibrary struct { + ent.Schema +} + +func (SentinelLibrary) Fields() []ent.Field { + return []ent.Field{ + field.Int64("sentinel_info_id").GoType(model.InternalID(0)), + field.Int64("reported_id"), + field.String("download_base_path"), + field.Time("updated_at"). + Default(time.Now).UpdateDefault(time.Now), + field.Time("created_at"). + Default(time.Now), + field.Int64("library_report_sequence"), + } +} + +func (SentinelLibrary) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("sentinel_info_id", "reported_id"). + Unique(), + index.Fields("library_report_sequence"), + } +} + +func (SentinelLibrary) Edges() []ent.Edge { + return []ent.Edge{ + edge.To("sentinel_info", SentinelInfo.Type). + Required(). + Unique(). + Field("sentinel_info_id"), + // edge.From("sentinel_app_binary", SentinelAppBinary.Type). + // Ref("sentinel_library"), + } +} diff --git a/internal/data/internal/ent/sentinelappbinary.go b/internal/data/internal/ent/sentinelappbinary.go new file mode 100644 index 00000000..19165b83 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary.go @@ -0,0 +1,230 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelAppBinary is the model entity for the SentinelAppBinary schema. +type SentinelAppBinary struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // SentinelInfoID holds the value of the "sentinel_info_id" field. + SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` + // SentinelLibraryReportedID holds the value of the "sentinel_library_reported_id" field. + SentinelLibraryReportedID int64 `json:"sentinel_library_reported_id,omitempty"` + // GeneratedID holds the value of the "generated_id" field. + GeneratedID string `json:"generated_id,omitempty"` + // SizeBytes holds the value of the "size_bytes" field. + SizeBytes int64 `json:"size_bytes,omitempty"` + // NeedToken holds the value of the "need_token" field. + NeedToken bool `json:"need_token,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` + // Version holds the value of the "version" field. + Version string `json:"version,omitempty"` + // Developer holds the value of the "developer" field. + Developer string `json:"developer,omitempty"` + // Publisher holds the value of the "publisher" field. + Publisher string `json:"publisher,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // AppBinaryReportSequence holds the value of the "app_binary_report_sequence" field. + AppBinaryReportSequence int64 `json:"app_binary_report_sequence,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*SentinelAppBinary) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case sentinelappbinary.FieldNeedToken: + values[i] = new(sql.NullBool) + case sentinelappbinary.FieldID, sentinelappbinary.FieldSentinelInfoID, sentinelappbinary.FieldSentinelLibraryReportedID, sentinelappbinary.FieldSizeBytes, sentinelappbinary.FieldAppBinaryReportSequence: + values[i] = new(sql.NullInt64) + case sentinelappbinary.FieldGeneratedID, sentinelappbinary.FieldName, sentinelappbinary.FieldVersion, sentinelappbinary.FieldDeveloper, sentinelappbinary.FieldPublisher: + values[i] = new(sql.NullString) + case sentinelappbinary.FieldUpdatedAt, sentinelappbinary.FieldCreatedAt: + values[i] = new(sql.NullTime) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the SentinelAppBinary fields. +func (sab *SentinelAppBinary) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case sentinelappbinary.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + sab.ID = int(value.Int64) + case sentinelappbinary.FieldSentinelInfoID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field sentinel_info_id", values[i]) + } else if value.Valid { + sab.SentinelInfoID = model.InternalID(value.Int64) + } + case sentinelappbinary.FieldSentinelLibraryReportedID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field sentinel_library_reported_id", values[i]) + } else if value.Valid { + sab.SentinelLibraryReportedID = value.Int64 + } + case sentinelappbinary.FieldGeneratedID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field generated_id", values[i]) + } else if value.Valid { + sab.GeneratedID = value.String + } + case sentinelappbinary.FieldSizeBytes: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field size_bytes", values[i]) + } else if value.Valid { + sab.SizeBytes = value.Int64 + } + case sentinelappbinary.FieldNeedToken: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field need_token", values[i]) + } else if value.Valid { + sab.NeedToken = value.Bool + } + case sentinelappbinary.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + sab.Name = value.String + } + case sentinelappbinary.FieldVersion: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field version", values[i]) + } else if value.Valid { + sab.Version = value.String + } + case sentinelappbinary.FieldDeveloper: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field developer", values[i]) + } else if value.Valid { + sab.Developer = value.String + } + case sentinelappbinary.FieldPublisher: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field publisher", values[i]) + } else if value.Valid { + sab.Publisher = value.String + } + case sentinelappbinary.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + sab.UpdatedAt = value.Time + } + case sentinelappbinary.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + sab.CreatedAt = value.Time + } + case sentinelappbinary.FieldAppBinaryReportSequence: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field app_binary_report_sequence", values[i]) + } else if value.Valid { + sab.AppBinaryReportSequence = value.Int64 + } + default: + sab.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the SentinelAppBinary. +// This includes values selected through modifiers, order, etc. +func (sab *SentinelAppBinary) Value(name string) (ent.Value, error) { + return sab.selectValues.Get(name) +} + +// Update returns a builder for updating this SentinelAppBinary. +// Note that you need to call SentinelAppBinary.Unwrap() before calling this method if this SentinelAppBinary +// was returned from a transaction, and the transaction was committed or rolled back. +func (sab *SentinelAppBinary) Update() *SentinelAppBinaryUpdateOne { + return NewSentinelAppBinaryClient(sab.config).UpdateOne(sab) +} + +// Unwrap unwraps the SentinelAppBinary entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (sab *SentinelAppBinary) Unwrap() *SentinelAppBinary { + _tx, ok := sab.config.driver.(*txDriver) + if !ok { + panic("ent: SentinelAppBinary is not a transactional entity") + } + sab.config.driver = _tx.drv + return sab +} + +// String implements the fmt.Stringer. +func (sab *SentinelAppBinary) String() string { + var builder strings.Builder + builder.WriteString("SentinelAppBinary(") + builder.WriteString(fmt.Sprintf("id=%v, ", sab.ID)) + builder.WriteString("sentinel_info_id=") + builder.WriteString(fmt.Sprintf("%v", sab.SentinelInfoID)) + builder.WriteString(", ") + builder.WriteString("sentinel_library_reported_id=") + builder.WriteString(fmt.Sprintf("%v", sab.SentinelLibraryReportedID)) + builder.WriteString(", ") + builder.WriteString("generated_id=") + builder.WriteString(sab.GeneratedID) + builder.WriteString(", ") + builder.WriteString("size_bytes=") + builder.WriteString(fmt.Sprintf("%v", sab.SizeBytes)) + builder.WriteString(", ") + builder.WriteString("need_token=") + builder.WriteString(fmt.Sprintf("%v", sab.NeedToken)) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(sab.Name) + builder.WriteString(", ") + builder.WriteString("version=") + builder.WriteString(sab.Version) + builder.WriteString(", ") + builder.WriteString("developer=") + builder.WriteString(sab.Developer) + builder.WriteString(", ") + builder.WriteString("publisher=") + builder.WriteString(sab.Publisher) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(sab.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(sab.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("app_binary_report_sequence=") + builder.WriteString(fmt.Sprintf("%v", sab.AppBinaryReportSequence)) + builder.WriteByte(')') + return builder.String() +} + +// SentinelAppBinaries is a parsable slice of SentinelAppBinary. +type SentinelAppBinaries []*SentinelAppBinary diff --git a/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go b/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go new file mode 100644 index 00000000..599cd42a --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go @@ -0,0 +1,146 @@ +// Code generated by ent, DO NOT EDIT. + +package sentinelappbinary + +import ( + "time" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the sentinelappbinary type in the database. + Label = "sentinel_app_binary" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldSentinelInfoID holds the string denoting the sentinel_info_id field in the database. + FieldSentinelInfoID = "sentinel_info_id" + // FieldSentinelLibraryReportedID holds the string denoting the sentinel_library_reported_id field in the database. + FieldSentinelLibraryReportedID = "sentinel_library_reported_id" + // FieldGeneratedID holds the string denoting the generated_id field in the database. + FieldGeneratedID = "generated_id" + // FieldSizeBytes holds the string denoting the size_bytes field in the database. + FieldSizeBytes = "size_bytes" + // FieldNeedToken holds the string denoting the need_token field in the database. + FieldNeedToken = "need_token" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldVersion holds the string denoting the version field in the database. + FieldVersion = "version" + // FieldDeveloper holds the string denoting the developer field in the database. + FieldDeveloper = "developer" + // FieldPublisher holds the string denoting the publisher field in the database. + FieldPublisher = "publisher" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldAppBinaryReportSequence holds the string denoting the app_binary_report_sequence field in the database. + FieldAppBinaryReportSequence = "app_binary_report_sequence" + // Table holds the table name of the sentinelappbinary in the database. + Table = "sentinel_app_binaries" +) + +// Columns holds all SQL columns for sentinelappbinary fields. +var Columns = []string{ + FieldID, + FieldSentinelInfoID, + FieldSentinelLibraryReportedID, + FieldGeneratedID, + FieldSizeBytes, + FieldNeedToken, + FieldName, + FieldVersion, + FieldDeveloper, + FieldPublisher, + FieldUpdatedAt, + FieldCreatedAt, + FieldAppBinaryReportSequence, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time +) + +// OrderOption defines the ordering options for the SentinelAppBinary queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// BySentinelInfoID orders the results by the sentinel_info_id field. +func BySentinelInfoID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSentinelInfoID, opts...).ToFunc() +} + +// BySentinelLibraryReportedID orders the results by the sentinel_library_reported_id field. +func BySentinelLibraryReportedID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSentinelLibraryReportedID, opts...).ToFunc() +} + +// ByGeneratedID orders the results by the generated_id field. +func ByGeneratedID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldGeneratedID, opts...).ToFunc() +} + +// BySizeBytes orders the results by the size_bytes field. +func BySizeBytes(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSizeBytes, opts...).ToFunc() +} + +// ByNeedToken orders the results by the need_token field. +func ByNeedToken(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNeedToken, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByVersion orders the results by the version field. +func ByVersion(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldVersion, opts...).ToFunc() +} + +// ByDeveloper orders the results by the developer field. +func ByDeveloper(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeveloper, opts...).ToFunc() +} + +// ByPublisher orders the results by the publisher field. +func ByPublisher(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPublisher, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByAppBinaryReportSequence orders the results by the app_binary_report_sequence field. +func ByAppBinaryReportSequence(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAppBinaryReportSequence, opts...).ToFunc() +} diff --git a/internal/data/internal/ent/sentinelappbinary/where.go b/internal/data/internal/ent/sentinelappbinary/where.go new file mode 100644 index 00000000..347a35fe --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary/where.go @@ -0,0 +1,761 @@ +// Code generated by ent, DO NOT EDIT. + +package sentinelappbinary + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/model" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldID, id)) +} + +// SentinelInfoID applies equality check predicate on the "sentinel_info_id" field. It's identical to SentinelInfoIDEQ. +func SentinelInfoID(v model.InternalID) predicate.SentinelAppBinary { + vc := int64(v) + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelInfoID, vc)) +} + +// SentinelLibraryReportedID applies equality check predicate on the "sentinel_library_reported_id" field. It's identical to SentinelLibraryReportedIDEQ. +func SentinelLibraryReportedID(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryReportedID, v)) +} + +// GeneratedID applies equality check predicate on the "generated_id" field. It's identical to GeneratedIDEQ. +func GeneratedID(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldGeneratedID, v)) +} + +// SizeBytes applies equality check predicate on the "size_bytes" field. It's identical to SizeBytesEQ. +func SizeBytes(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSizeBytes, v)) +} + +// NeedToken applies equality check predicate on the "need_token" field. It's identical to NeedTokenEQ. +func NeedToken(v bool) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldNeedToken, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldName, v)) +} + +// Version applies equality check predicate on the "version" field. It's identical to VersionEQ. +func Version(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldVersion, v)) +} + +// Developer applies equality check predicate on the "developer" field. It's identical to DeveloperEQ. +func Developer(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldDeveloper, v)) +} + +// Publisher applies equality check predicate on the "publisher" field. It's identical to PublisherEQ. +func Publisher(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldPublisher, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldCreatedAt, v)) +} + +// AppBinaryReportSequence applies equality check predicate on the "app_binary_report_sequence" field. It's identical to AppBinaryReportSequenceEQ. +func AppBinaryReportSequence(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldAppBinaryReportSequence, v)) +} + +// SentinelInfoIDEQ applies the EQ predicate on the "sentinel_info_id" field. +func SentinelInfoIDEQ(v model.InternalID) predicate.SentinelAppBinary { + vc := int64(v) + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDNEQ applies the NEQ predicate on the "sentinel_info_id" field. +func SentinelInfoIDNEQ(v model.InternalID) predicate.SentinelAppBinary { + vc := int64(v) + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDIn applies the In predicate on the "sentinel_info_id" field. +func SentinelInfoIDIn(vs ...model.InternalID) predicate.SentinelAppBinary { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelAppBinary(sql.FieldIn(FieldSentinelInfoID, v...)) +} + +// SentinelInfoIDNotIn applies the NotIn predicate on the "sentinel_info_id" field. +func SentinelInfoIDNotIn(vs ...model.InternalID) predicate.SentinelAppBinary { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldSentinelInfoID, v...)) +} + +// SentinelInfoIDGT applies the GT predicate on the "sentinel_info_id" field. +func SentinelInfoIDGT(v model.InternalID) predicate.SentinelAppBinary { + vc := int64(v) + return predicate.SentinelAppBinary(sql.FieldGT(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDGTE applies the GTE predicate on the "sentinel_info_id" field. +func SentinelInfoIDGTE(v model.InternalID) predicate.SentinelAppBinary { + vc := int64(v) + return predicate.SentinelAppBinary(sql.FieldGTE(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDLT applies the LT predicate on the "sentinel_info_id" field. +func SentinelInfoIDLT(v model.InternalID) predicate.SentinelAppBinary { + vc := int64(v) + return predicate.SentinelAppBinary(sql.FieldLT(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDLTE applies the LTE predicate on the "sentinel_info_id" field. +func SentinelInfoIDLTE(v model.InternalID) predicate.SentinelAppBinary { + vc := int64(v) + return predicate.SentinelAppBinary(sql.FieldLTE(FieldSentinelInfoID, vc)) +} + +// SentinelLibraryReportedIDEQ applies the EQ predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDEQ(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryReportedID, v)) +} + +// SentinelLibraryReportedIDNEQ applies the NEQ predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDNEQ(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldSentinelLibraryReportedID, v)) +} + +// SentinelLibraryReportedIDIn applies the In predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDIn(vs ...int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldSentinelLibraryReportedID, vs...)) +} + +// SentinelLibraryReportedIDNotIn applies the NotIn predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDNotIn(vs ...int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldSentinelLibraryReportedID, vs...)) +} + +// SentinelLibraryReportedIDGT applies the GT predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDGT(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldSentinelLibraryReportedID, v)) +} + +// SentinelLibraryReportedIDGTE applies the GTE predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDGTE(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldSentinelLibraryReportedID, v)) +} + +// SentinelLibraryReportedIDLT applies the LT predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDLT(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldSentinelLibraryReportedID, v)) +} + +// SentinelLibraryReportedIDLTE applies the LTE predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDLTE(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldSentinelLibraryReportedID, v)) +} + +// GeneratedIDEQ applies the EQ predicate on the "generated_id" field. +func GeneratedIDEQ(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldGeneratedID, v)) +} + +// GeneratedIDNEQ applies the NEQ predicate on the "generated_id" field. +func GeneratedIDNEQ(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldGeneratedID, v)) +} + +// GeneratedIDIn applies the In predicate on the "generated_id" field. +func GeneratedIDIn(vs ...string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldGeneratedID, vs...)) +} + +// GeneratedIDNotIn applies the NotIn predicate on the "generated_id" field. +func GeneratedIDNotIn(vs ...string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldGeneratedID, vs...)) +} + +// GeneratedIDGT applies the GT predicate on the "generated_id" field. +func GeneratedIDGT(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldGeneratedID, v)) +} + +// GeneratedIDGTE applies the GTE predicate on the "generated_id" field. +func GeneratedIDGTE(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldGeneratedID, v)) +} + +// GeneratedIDLT applies the LT predicate on the "generated_id" field. +func GeneratedIDLT(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldGeneratedID, v)) +} + +// GeneratedIDLTE applies the LTE predicate on the "generated_id" field. +func GeneratedIDLTE(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldGeneratedID, v)) +} + +// GeneratedIDContains applies the Contains predicate on the "generated_id" field. +func GeneratedIDContains(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldContains(FieldGeneratedID, v)) +} + +// GeneratedIDHasPrefix applies the HasPrefix predicate on the "generated_id" field. +func GeneratedIDHasPrefix(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldHasPrefix(FieldGeneratedID, v)) +} + +// GeneratedIDHasSuffix applies the HasSuffix predicate on the "generated_id" field. +func GeneratedIDHasSuffix(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldHasSuffix(FieldGeneratedID, v)) +} + +// GeneratedIDEqualFold applies the EqualFold predicate on the "generated_id" field. +func GeneratedIDEqualFold(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEqualFold(FieldGeneratedID, v)) +} + +// GeneratedIDContainsFold applies the ContainsFold predicate on the "generated_id" field. +func GeneratedIDContainsFold(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldContainsFold(FieldGeneratedID, v)) +} + +// SizeBytesEQ applies the EQ predicate on the "size_bytes" field. +func SizeBytesEQ(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSizeBytes, v)) +} + +// SizeBytesNEQ applies the NEQ predicate on the "size_bytes" field. +func SizeBytesNEQ(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldSizeBytes, v)) +} + +// SizeBytesIn applies the In predicate on the "size_bytes" field. +func SizeBytesIn(vs ...int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldSizeBytes, vs...)) +} + +// SizeBytesNotIn applies the NotIn predicate on the "size_bytes" field. +func SizeBytesNotIn(vs ...int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldSizeBytes, vs...)) +} + +// SizeBytesGT applies the GT predicate on the "size_bytes" field. +func SizeBytesGT(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldSizeBytes, v)) +} + +// SizeBytesGTE applies the GTE predicate on the "size_bytes" field. +func SizeBytesGTE(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldSizeBytes, v)) +} + +// SizeBytesLT applies the LT predicate on the "size_bytes" field. +func SizeBytesLT(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldSizeBytes, v)) +} + +// SizeBytesLTE applies the LTE predicate on the "size_bytes" field. +func SizeBytesLTE(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldSizeBytes, v)) +} + +// NeedTokenEQ applies the EQ predicate on the "need_token" field. +func NeedTokenEQ(v bool) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldNeedToken, v)) +} + +// NeedTokenNEQ applies the NEQ predicate on the "need_token" field. +func NeedTokenNEQ(v bool) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldNeedToken, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldHasSuffix(FieldName, v)) +} + +// NameIsNil applies the IsNil predicate on the "name" field. +func NameIsNil() predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIsNull(FieldName)) +} + +// NameNotNil applies the NotNil predicate on the "name" field. +func NameNotNil() predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotNull(FieldName)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldContainsFold(FieldName, v)) +} + +// VersionEQ applies the EQ predicate on the "version" field. +func VersionEQ(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldVersion, v)) +} + +// VersionNEQ applies the NEQ predicate on the "version" field. +func VersionNEQ(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldVersion, v)) +} + +// VersionIn applies the In predicate on the "version" field. +func VersionIn(vs ...string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldVersion, vs...)) +} + +// VersionNotIn applies the NotIn predicate on the "version" field. +func VersionNotIn(vs ...string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldVersion, vs...)) +} + +// VersionGT applies the GT predicate on the "version" field. +func VersionGT(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldVersion, v)) +} + +// VersionGTE applies the GTE predicate on the "version" field. +func VersionGTE(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldVersion, v)) +} + +// VersionLT applies the LT predicate on the "version" field. +func VersionLT(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldVersion, v)) +} + +// VersionLTE applies the LTE predicate on the "version" field. +func VersionLTE(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldVersion, v)) +} + +// VersionContains applies the Contains predicate on the "version" field. +func VersionContains(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldContains(FieldVersion, v)) +} + +// VersionHasPrefix applies the HasPrefix predicate on the "version" field. +func VersionHasPrefix(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldHasPrefix(FieldVersion, v)) +} + +// VersionHasSuffix applies the HasSuffix predicate on the "version" field. +func VersionHasSuffix(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldHasSuffix(FieldVersion, v)) +} + +// VersionIsNil applies the IsNil predicate on the "version" field. +func VersionIsNil() predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIsNull(FieldVersion)) +} + +// VersionNotNil applies the NotNil predicate on the "version" field. +func VersionNotNil() predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotNull(FieldVersion)) +} + +// VersionEqualFold applies the EqualFold predicate on the "version" field. +func VersionEqualFold(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEqualFold(FieldVersion, v)) +} + +// VersionContainsFold applies the ContainsFold predicate on the "version" field. +func VersionContainsFold(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldContainsFold(FieldVersion, v)) +} + +// DeveloperEQ applies the EQ predicate on the "developer" field. +func DeveloperEQ(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldDeveloper, v)) +} + +// DeveloperNEQ applies the NEQ predicate on the "developer" field. +func DeveloperNEQ(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldDeveloper, v)) +} + +// DeveloperIn applies the In predicate on the "developer" field. +func DeveloperIn(vs ...string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldDeveloper, vs...)) +} + +// DeveloperNotIn applies the NotIn predicate on the "developer" field. +func DeveloperNotIn(vs ...string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldDeveloper, vs...)) +} + +// DeveloperGT applies the GT predicate on the "developer" field. +func DeveloperGT(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldDeveloper, v)) +} + +// DeveloperGTE applies the GTE predicate on the "developer" field. +func DeveloperGTE(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldDeveloper, v)) +} + +// DeveloperLT applies the LT predicate on the "developer" field. +func DeveloperLT(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldDeveloper, v)) +} + +// DeveloperLTE applies the LTE predicate on the "developer" field. +func DeveloperLTE(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldDeveloper, v)) +} + +// DeveloperContains applies the Contains predicate on the "developer" field. +func DeveloperContains(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldContains(FieldDeveloper, v)) +} + +// DeveloperHasPrefix applies the HasPrefix predicate on the "developer" field. +func DeveloperHasPrefix(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldHasPrefix(FieldDeveloper, v)) +} + +// DeveloperHasSuffix applies the HasSuffix predicate on the "developer" field. +func DeveloperHasSuffix(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldHasSuffix(FieldDeveloper, v)) +} + +// DeveloperIsNil applies the IsNil predicate on the "developer" field. +func DeveloperIsNil() predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIsNull(FieldDeveloper)) +} + +// DeveloperNotNil applies the NotNil predicate on the "developer" field. +func DeveloperNotNil() predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotNull(FieldDeveloper)) +} + +// DeveloperEqualFold applies the EqualFold predicate on the "developer" field. +func DeveloperEqualFold(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEqualFold(FieldDeveloper, v)) +} + +// DeveloperContainsFold applies the ContainsFold predicate on the "developer" field. +func DeveloperContainsFold(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldContainsFold(FieldDeveloper, v)) +} + +// PublisherEQ applies the EQ predicate on the "publisher" field. +func PublisherEQ(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldPublisher, v)) +} + +// PublisherNEQ applies the NEQ predicate on the "publisher" field. +func PublisherNEQ(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldPublisher, v)) +} + +// PublisherIn applies the In predicate on the "publisher" field. +func PublisherIn(vs ...string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldPublisher, vs...)) +} + +// PublisherNotIn applies the NotIn predicate on the "publisher" field. +func PublisherNotIn(vs ...string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldPublisher, vs...)) +} + +// PublisherGT applies the GT predicate on the "publisher" field. +func PublisherGT(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldPublisher, v)) +} + +// PublisherGTE applies the GTE predicate on the "publisher" field. +func PublisherGTE(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldPublisher, v)) +} + +// PublisherLT applies the LT predicate on the "publisher" field. +func PublisherLT(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldPublisher, v)) +} + +// PublisherLTE applies the LTE predicate on the "publisher" field. +func PublisherLTE(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldPublisher, v)) +} + +// PublisherContains applies the Contains predicate on the "publisher" field. +func PublisherContains(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldContains(FieldPublisher, v)) +} + +// PublisherHasPrefix applies the HasPrefix predicate on the "publisher" field. +func PublisherHasPrefix(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldHasPrefix(FieldPublisher, v)) +} + +// PublisherHasSuffix applies the HasSuffix predicate on the "publisher" field. +func PublisherHasSuffix(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldHasSuffix(FieldPublisher, v)) +} + +// PublisherIsNil applies the IsNil predicate on the "publisher" field. +func PublisherIsNil() predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIsNull(FieldPublisher)) +} + +// PublisherNotNil applies the NotNil predicate on the "publisher" field. +func PublisherNotNil() predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotNull(FieldPublisher)) +} + +// PublisherEqualFold applies the EqualFold predicate on the "publisher" field. +func PublisherEqualFold(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEqualFold(FieldPublisher, v)) +} + +// PublisherContainsFold applies the ContainsFold predicate on the "publisher" field. +func PublisherContainsFold(v string) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldContainsFold(FieldPublisher, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldCreatedAt, v)) +} + +// AppBinaryReportSequenceEQ applies the EQ predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceEQ(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceNEQ applies the NEQ predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceNEQ(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceIn applies the In predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceIn(vs ...int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldAppBinaryReportSequence, vs...)) +} + +// AppBinaryReportSequenceNotIn applies the NotIn predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceNotIn(vs ...int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldAppBinaryReportSequence, vs...)) +} + +// AppBinaryReportSequenceGT applies the GT predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceGT(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceGTE applies the GTE predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceGTE(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceLT applies the LT predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceLT(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceLTE applies the LTE predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceLTE(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldAppBinaryReportSequence, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.SentinelAppBinary) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.SentinelAppBinary) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.SentinelAppBinary) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.NotPredicates(p)) +} diff --git a/internal/data/internal/ent/sentinelappbinary_create.go b/internal/data/internal/ent/sentinelappbinary_create.go new file mode 100644 index 00000000..c841b3d2 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary_create.go @@ -0,0 +1,1249 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelAppBinaryCreate is the builder for creating a SentinelAppBinary entity. +type SentinelAppBinaryCreate struct { + config + mutation *SentinelAppBinaryMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (sabc *SentinelAppBinaryCreate) SetSentinelInfoID(mi model.InternalID) *SentinelAppBinaryCreate { + sabc.mutation.SetSentinelInfoID(mi) + return sabc +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (sabc *SentinelAppBinaryCreate) SetSentinelLibraryReportedID(i int64) *SentinelAppBinaryCreate { + sabc.mutation.SetSentinelLibraryReportedID(i) + return sabc +} + +// SetGeneratedID sets the "generated_id" field. +func (sabc *SentinelAppBinaryCreate) SetGeneratedID(s string) *SentinelAppBinaryCreate { + sabc.mutation.SetGeneratedID(s) + return sabc +} + +// SetSizeBytes sets the "size_bytes" field. +func (sabc *SentinelAppBinaryCreate) SetSizeBytes(i int64) *SentinelAppBinaryCreate { + sabc.mutation.SetSizeBytes(i) + return sabc +} + +// SetNeedToken sets the "need_token" field. +func (sabc *SentinelAppBinaryCreate) SetNeedToken(b bool) *SentinelAppBinaryCreate { + sabc.mutation.SetNeedToken(b) + return sabc +} + +// SetName sets the "name" field. +func (sabc *SentinelAppBinaryCreate) SetName(s string) *SentinelAppBinaryCreate { + sabc.mutation.SetName(s) + return sabc +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (sabc *SentinelAppBinaryCreate) SetNillableName(s *string) *SentinelAppBinaryCreate { + if s != nil { + sabc.SetName(*s) + } + return sabc +} + +// SetVersion sets the "version" field. +func (sabc *SentinelAppBinaryCreate) SetVersion(s string) *SentinelAppBinaryCreate { + sabc.mutation.SetVersion(s) + return sabc +} + +// SetNillableVersion sets the "version" field if the given value is not nil. +func (sabc *SentinelAppBinaryCreate) SetNillableVersion(s *string) *SentinelAppBinaryCreate { + if s != nil { + sabc.SetVersion(*s) + } + return sabc +} + +// SetDeveloper sets the "developer" field. +func (sabc *SentinelAppBinaryCreate) SetDeveloper(s string) *SentinelAppBinaryCreate { + sabc.mutation.SetDeveloper(s) + return sabc +} + +// SetNillableDeveloper sets the "developer" field if the given value is not nil. +func (sabc *SentinelAppBinaryCreate) SetNillableDeveloper(s *string) *SentinelAppBinaryCreate { + if s != nil { + sabc.SetDeveloper(*s) + } + return sabc +} + +// SetPublisher sets the "publisher" field. +func (sabc *SentinelAppBinaryCreate) SetPublisher(s string) *SentinelAppBinaryCreate { + sabc.mutation.SetPublisher(s) + return sabc +} + +// SetNillablePublisher sets the "publisher" field if the given value is not nil. +func (sabc *SentinelAppBinaryCreate) SetNillablePublisher(s *string) *SentinelAppBinaryCreate { + if s != nil { + sabc.SetPublisher(*s) + } + return sabc +} + +// SetUpdatedAt sets the "updated_at" field. +func (sabc *SentinelAppBinaryCreate) SetUpdatedAt(t time.Time) *SentinelAppBinaryCreate { + sabc.mutation.SetUpdatedAt(t) + return sabc +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (sabc *SentinelAppBinaryCreate) SetNillableUpdatedAt(t *time.Time) *SentinelAppBinaryCreate { + if t != nil { + sabc.SetUpdatedAt(*t) + } + return sabc +} + +// SetCreatedAt sets the "created_at" field. +func (sabc *SentinelAppBinaryCreate) SetCreatedAt(t time.Time) *SentinelAppBinaryCreate { + sabc.mutation.SetCreatedAt(t) + return sabc +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (sabc *SentinelAppBinaryCreate) SetNillableCreatedAt(t *time.Time) *SentinelAppBinaryCreate { + if t != nil { + sabc.SetCreatedAt(*t) + } + return sabc +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (sabc *SentinelAppBinaryCreate) SetAppBinaryReportSequence(i int64) *SentinelAppBinaryCreate { + sabc.mutation.SetAppBinaryReportSequence(i) + return sabc +} + +// Mutation returns the SentinelAppBinaryMutation object of the builder. +func (sabc *SentinelAppBinaryCreate) Mutation() *SentinelAppBinaryMutation { + return sabc.mutation +} + +// Save creates the SentinelAppBinary in the database. +func (sabc *SentinelAppBinaryCreate) Save(ctx context.Context) (*SentinelAppBinary, error) { + sabc.defaults() + return withHooks(ctx, sabc.sqlSave, sabc.mutation, sabc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (sabc *SentinelAppBinaryCreate) SaveX(ctx context.Context) *SentinelAppBinary { + v, err := sabc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (sabc *SentinelAppBinaryCreate) Exec(ctx context.Context) error { + _, err := sabc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabc *SentinelAppBinaryCreate) ExecX(ctx context.Context) { + if err := sabc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (sabc *SentinelAppBinaryCreate) defaults() { + if _, ok := sabc.mutation.UpdatedAt(); !ok { + v := sentinelappbinary.DefaultUpdatedAt() + sabc.mutation.SetUpdatedAt(v) + } + if _, ok := sabc.mutation.CreatedAt(); !ok { + v := sentinelappbinary.DefaultCreatedAt() + sabc.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (sabc *SentinelAppBinaryCreate) check() error { + if _, ok := sabc.mutation.SentinelInfoID(); !ok { + return &ValidationError{Name: "sentinel_info_id", err: errors.New(`ent: missing required field "SentinelAppBinary.sentinel_info_id"`)} + } + if _, ok := sabc.mutation.SentinelLibraryReportedID(); !ok { + return &ValidationError{Name: "sentinel_library_reported_id", err: errors.New(`ent: missing required field "SentinelAppBinary.sentinel_library_reported_id"`)} + } + if _, ok := sabc.mutation.GeneratedID(); !ok { + return &ValidationError{Name: "generated_id", err: errors.New(`ent: missing required field "SentinelAppBinary.generated_id"`)} + } + if _, ok := sabc.mutation.SizeBytes(); !ok { + return &ValidationError{Name: "size_bytes", err: errors.New(`ent: missing required field "SentinelAppBinary.size_bytes"`)} + } + if _, ok := sabc.mutation.NeedToken(); !ok { + return &ValidationError{Name: "need_token", err: errors.New(`ent: missing required field "SentinelAppBinary.need_token"`)} + } + if _, ok := sabc.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SentinelAppBinary.updated_at"`)} + } + if _, ok := sabc.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SentinelAppBinary.created_at"`)} + } + if _, ok := sabc.mutation.AppBinaryReportSequence(); !ok { + return &ValidationError{Name: "app_binary_report_sequence", err: errors.New(`ent: missing required field "SentinelAppBinary.app_binary_report_sequence"`)} + } + return nil +} + +func (sabc *SentinelAppBinaryCreate) sqlSave(ctx context.Context) (*SentinelAppBinary, error) { + if err := sabc.check(); err != nil { + return nil, err + } + _node, _spec := sabc.createSpec() + if err := sqlgraph.CreateNode(ctx, sabc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + sabc.mutation.id = &_node.ID + sabc.mutation.done = true + return _node, nil +} + +func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph.CreateSpec) { + var ( + _node = &SentinelAppBinary{config: sabc.config} + _spec = sqlgraph.NewCreateSpec(sentinelappbinary.Table, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt)) + ) + _spec.OnConflict = sabc.conflict + if value, ok := sabc.mutation.SentinelInfoID(); ok { + _spec.SetField(sentinelappbinary.FieldSentinelInfoID, field.TypeInt64, value) + _node.SentinelInfoID = value + } + if value, ok := sabc.mutation.SentinelLibraryReportedID(); ok { + _spec.SetField(sentinelappbinary.FieldSentinelLibraryReportedID, field.TypeInt64, value) + _node.SentinelLibraryReportedID = value + } + if value, ok := sabc.mutation.GeneratedID(); ok { + _spec.SetField(sentinelappbinary.FieldGeneratedID, field.TypeString, value) + _node.GeneratedID = value + } + if value, ok := sabc.mutation.SizeBytes(); ok { + _spec.SetField(sentinelappbinary.FieldSizeBytes, field.TypeInt64, value) + _node.SizeBytes = value + } + if value, ok := sabc.mutation.NeedToken(); ok { + _spec.SetField(sentinelappbinary.FieldNeedToken, field.TypeBool, value) + _node.NeedToken = value + } + if value, ok := sabc.mutation.Name(); ok { + _spec.SetField(sentinelappbinary.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := sabc.mutation.Version(); ok { + _spec.SetField(sentinelappbinary.FieldVersion, field.TypeString, value) + _node.Version = value + } + if value, ok := sabc.mutation.Developer(); ok { + _spec.SetField(sentinelappbinary.FieldDeveloper, field.TypeString, value) + _node.Developer = value + } + if value, ok := sabc.mutation.Publisher(); ok { + _spec.SetField(sentinelappbinary.FieldPublisher, field.TypeString, value) + _node.Publisher = value + } + if value, ok := sabc.mutation.UpdatedAt(); ok { + _spec.SetField(sentinelappbinary.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := sabc.mutation.CreatedAt(); ok { + _spec.SetField(sentinelappbinary.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := sabc.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) + _node.AppBinaryReportSequence = value + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.SentinelAppBinary.Create(). +// SetSentinelInfoID(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.SentinelAppBinaryUpsert) { +// SetSentinelInfoID(v+v). +// }). +// Exec(ctx) +func (sabc *SentinelAppBinaryCreate) OnConflict(opts ...sql.ConflictOption) *SentinelAppBinaryUpsertOne { + sabc.conflict = opts + return &SentinelAppBinaryUpsertOne{ + create: sabc, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.SentinelAppBinary.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (sabc *SentinelAppBinaryCreate) OnConflictColumns(columns ...string) *SentinelAppBinaryUpsertOne { + sabc.conflict = append(sabc.conflict, sql.ConflictColumns(columns...)) + return &SentinelAppBinaryUpsertOne{ + create: sabc, + } +} + +type ( + // SentinelAppBinaryUpsertOne is the builder for "upsert"-ing + // one SentinelAppBinary node. + SentinelAppBinaryUpsertOne struct { + create *SentinelAppBinaryCreate + } + + // SentinelAppBinaryUpsert is the "OnConflict" setter. + SentinelAppBinaryUpsert struct { + *sql.UpdateSet + } +) + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (u *SentinelAppBinaryUpsert) SetSentinelInfoID(v model.InternalID) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldSentinelInfoID, v) + return u +} + +// UpdateSentinelInfoID sets the "sentinel_info_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateSentinelInfoID() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldSentinelInfoID) + return u +} + +// AddSentinelInfoID adds v to the "sentinel_info_id" field. +func (u *SentinelAppBinaryUpsert) AddSentinelInfoID(v model.InternalID) *SentinelAppBinaryUpsert { + u.Add(sentinelappbinary.FieldSentinelInfoID, v) + return u +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryUpsert) SetSentinelLibraryReportedID(v int64) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldSentinelLibraryReportedID, v) + return u +} + +// UpdateSentinelLibraryReportedID sets the "sentinel_library_reported_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateSentinelLibraryReportedID() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldSentinelLibraryReportedID) + return u +} + +// AddSentinelLibraryReportedID adds v to the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryUpsert) AddSentinelLibraryReportedID(v int64) *SentinelAppBinaryUpsert { + u.Add(sentinelappbinary.FieldSentinelLibraryReportedID, v) + return u +} + +// SetGeneratedID sets the "generated_id" field. +func (u *SentinelAppBinaryUpsert) SetGeneratedID(v string) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldGeneratedID, v) + return u +} + +// UpdateGeneratedID sets the "generated_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateGeneratedID() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldGeneratedID) + return u +} + +// SetSizeBytes sets the "size_bytes" field. +func (u *SentinelAppBinaryUpsert) SetSizeBytes(v int64) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldSizeBytes, v) + return u +} + +// UpdateSizeBytes sets the "size_bytes" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateSizeBytes() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldSizeBytes) + return u +} + +// AddSizeBytes adds v to the "size_bytes" field. +func (u *SentinelAppBinaryUpsert) AddSizeBytes(v int64) *SentinelAppBinaryUpsert { + u.Add(sentinelappbinary.FieldSizeBytes, v) + return u +} + +// SetNeedToken sets the "need_token" field. +func (u *SentinelAppBinaryUpsert) SetNeedToken(v bool) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldNeedToken, v) + return u +} + +// UpdateNeedToken sets the "need_token" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateNeedToken() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldNeedToken) + return u +} + +// SetName sets the "name" field. +func (u *SentinelAppBinaryUpsert) SetName(v string) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldName, v) + return u +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateName() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldName) + return u +} + +// ClearName clears the value of the "name" field. +func (u *SentinelAppBinaryUpsert) ClearName() *SentinelAppBinaryUpsert { + u.SetNull(sentinelappbinary.FieldName) + return u +} + +// SetVersion sets the "version" field. +func (u *SentinelAppBinaryUpsert) SetVersion(v string) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldVersion, v) + return u +} + +// UpdateVersion sets the "version" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateVersion() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldVersion) + return u +} + +// ClearVersion clears the value of the "version" field. +func (u *SentinelAppBinaryUpsert) ClearVersion() *SentinelAppBinaryUpsert { + u.SetNull(sentinelappbinary.FieldVersion) + return u +} + +// SetDeveloper sets the "developer" field. +func (u *SentinelAppBinaryUpsert) SetDeveloper(v string) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldDeveloper, v) + return u +} + +// UpdateDeveloper sets the "developer" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateDeveloper() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldDeveloper) + return u +} + +// ClearDeveloper clears the value of the "developer" field. +func (u *SentinelAppBinaryUpsert) ClearDeveloper() *SentinelAppBinaryUpsert { + u.SetNull(sentinelappbinary.FieldDeveloper) + return u +} + +// SetPublisher sets the "publisher" field. +func (u *SentinelAppBinaryUpsert) SetPublisher(v string) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldPublisher, v) + return u +} + +// UpdatePublisher sets the "publisher" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdatePublisher() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldPublisher) + return u +} + +// ClearPublisher clears the value of the "publisher" field. +func (u *SentinelAppBinaryUpsert) ClearPublisher() *SentinelAppBinaryUpsert { + u.SetNull(sentinelappbinary.FieldPublisher) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelAppBinaryUpsert) SetUpdatedAt(v time.Time) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateUpdatedAt() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldUpdatedAt) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelAppBinaryUpsert) SetCreatedAt(v time.Time) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateCreatedAt() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldCreatedAt) + return u +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryUpsert) SetAppBinaryReportSequence(v int64) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldAppBinaryReportSequence, v) + return u +} + +// UpdateAppBinaryReportSequence sets the "app_binary_report_sequence" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateAppBinaryReportSequence() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldAppBinaryReportSequence) + return u +} + +// AddAppBinaryReportSequence adds v to the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryUpsert) AddAppBinaryReportSequence(v int64) *SentinelAppBinaryUpsert { + u.Add(sentinelappbinary.FieldAppBinaryReportSequence, v) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create. +// Using this option is equivalent to using: +// +// client.SentinelAppBinary.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *SentinelAppBinaryUpsertOne) UpdateNewValues() *SentinelAppBinaryUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.SentinelAppBinary.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SentinelAppBinaryUpsertOne) Ignore() *SentinelAppBinaryUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *SentinelAppBinaryUpsertOne) DoNothing() *SentinelAppBinaryUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SentinelAppBinaryCreate.OnConflict +// documentation for more info. +func (u *SentinelAppBinaryUpsertOne) Update(set func(*SentinelAppBinaryUpsert)) *SentinelAppBinaryUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SentinelAppBinaryUpsert{UpdateSet: update}) + })) + return u +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (u *SentinelAppBinaryUpsertOne) SetSentinelInfoID(v model.InternalID) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetSentinelInfoID(v) + }) +} + +// AddSentinelInfoID adds v to the "sentinel_info_id" field. +func (u *SentinelAppBinaryUpsertOne) AddSentinelInfoID(v model.InternalID) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.AddSentinelInfoID(v) + }) +} + +// UpdateSentinelInfoID sets the "sentinel_info_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateSentinelInfoID() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateSentinelInfoID() + }) +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryUpsertOne) SetSentinelLibraryReportedID(v int64) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetSentinelLibraryReportedID(v) + }) +} + +// AddSentinelLibraryReportedID adds v to the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryUpsertOne) AddSentinelLibraryReportedID(v int64) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.AddSentinelLibraryReportedID(v) + }) +} + +// UpdateSentinelLibraryReportedID sets the "sentinel_library_reported_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateSentinelLibraryReportedID() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateSentinelLibraryReportedID() + }) +} + +// SetGeneratedID sets the "generated_id" field. +func (u *SentinelAppBinaryUpsertOne) SetGeneratedID(v string) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetGeneratedID(v) + }) +} + +// UpdateGeneratedID sets the "generated_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateGeneratedID() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateGeneratedID() + }) +} + +// SetSizeBytes sets the "size_bytes" field. +func (u *SentinelAppBinaryUpsertOne) SetSizeBytes(v int64) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetSizeBytes(v) + }) +} + +// AddSizeBytes adds v to the "size_bytes" field. +func (u *SentinelAppBinaryUpsertOne) AddSizeBytes(v int64) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.AddSizeBytes(v) + }) +} + +// UpdateSizeBytes sets the "size_bytes" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateSizeBytes() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateSizeBytes() + }) +} + +// SetNeedToken sets the "need_token" field. +func (u *SentinelAppBinaryUpsertOne) SetNeedToken(v bool) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetNeedToken(v) + }) +} + +// UpdateNeedToken sets the "need_token" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateNeedToken() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateNeedToken() + }) +} + +// SetName sets the "name" field. +func (u *SentinelAppBinaryUpsertOne) SetName(v string) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateName() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateName() + }) +} + +// ClearName clears the value of the "name" field. +func (u *SentinelAppBinaryUpsertOne) ClearName() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.ClearName() + }) +} + +// SetVersion sets the "version" field. +func (u *SentinelAppBinaryUpsertOne) SetVersion(v string) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetVersion(v) + }) +} + +// UpdateVersion sets the "version" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateVersion() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateVersion() + }) +} + +// ClearVersion clears the value of the "version" field. +func (u *SentinelAppBinaryUpsertOne) ClearVersion() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.ClearVersion() + }) +} + +// SetDeveloper sets the "developer" field. +func (u *SentinelAppBinaryUpsertOne) SetDeveloper(v string) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetDeveloper(v) + }) +} + +// UpdateDeveloper sets the "developer" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateDeveloper() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateDeveloper() + }) +} + +// ClearDeveloper clears the value of the "developer" field. +func (u *SentinelAppBinaryUpsertOne) ClearDeveloper() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.ClearDeveloper() + }) +} + +// SetPublisher sets the "publisher" field. +func (u *SentinelAppBinaryUpsertOne) SetPublisher(v string) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetPublisher(v) + }) +} + +// UpdatePublisher sets the "publisher" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdatePublisher() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdatePublisher() + }) +} + +// ClearPublisher clears the value of the "publisher" field. +func (u *SentinelAppBinaryUpsertOne) ClearPublisher() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.ClearPublisher() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelAppBinaryUpsertOne) SetUpdatedAt(v time.Time) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateUpdatedAt() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelAppBinaryUpsertOne) SetCreatedAt(v time.Time) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateCreatedAt() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryUpsertOne) SetAppBinaryReportSequence(v int64) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetAppBinaryReportSequence(v) + }) +} + +// AddAppBinaryReportSequence adds v to the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryUpsertOne) AddAppBinaryReportSequence(v int64) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.AddAppBinaryReportSequence(v) + }) +} + +// UpdateAppBinaryReportSequence sets the "app_binary_report_sequence" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateAppBinaryReportSequence() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateAppBinaryReportSequence() + }) +} + +// Exec executes the query. +func (u *SentinelAppBinaryUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for SentinelAppBinaryCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SentinelAppBinaryUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *SentinelAppBinaryUpsertOne) ID(ctx context.Context) (id int, err error) { + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *SentinelAppBinaryUpsertOne) IDX(ctx context.Context) int { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// SentinelAppBinaryCreateBulk is the builder for creating many SentinelAppBinary entities in bulk. +type SentinelAppBinaryCreateBulk struct { + config + err error + builders []*SentinelAppBinaryCreate + conflict []sql.ConflictOption +} + +// Save creates the SentinelAppBinary entities in the database. +func (sabcb *SentinelAppBinaryCreateBulk) Save(ctx context.Context) ([]*SentinelAppBinary, error) { + if sabcb.err != nil { + return nil, sabcb.err + } + specs := make([]*sqlgraph.CreateSpec, len(sabcb.builders)) + nodes := make([]*SentinelAppBinary, len(sabcb.builders)) + mutators := make([]Mutator, len(sabcb.builders)) + for i := range sabcb.builders { + func(i int, root context.Context) { + builder := sabcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*SentinelAppBinaryMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, sabcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = sabcb.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, sabcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + if specs[i].ID.Value != nil { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(id) + } + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, sabcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (sabcb *SentinelAppBinaryCreateBulk) SaveX(ctx context.Context) []*SentinelAppBinary { + v, err := sabcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (sabcb *SentinelAppBinaryCreateBulk) Exec(ctx context.Context) error { + _, err := sabcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabcb *SentinelAppBinaryCreateBulk) ExecX(ctx context.Context) { + if err := sabcb.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.SentinelAppBinary.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.SentinelAppBinaryUpsert) { +// SetSentinelInfoID(v+v). +// }). +// Exec(ctx) +func (sabcb *SentinelAppBinaryCreateBulk) OnConflict(opts ...sql.ConflictOption) *SentinelAppBinaryUpsertBulk { + sabcb.conflict = opts + return &SentinelAppBinaryUpsertBulk{ + create: sabcb, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.SentinelAppBinary.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (sabcb *SentinelAppBinaryCreateBulk) OnConflictColumns(columns ...string) *SentinelAppBinaryUpsertBulk { + sabcb.conflict = append(sabcb.conflict, sql.ConflictColumns(columns...)) + return &SentinelAppBinaryUpsertBulk{ + create: sabcb, + } +} + +// SentinelAppBinaryUpsertBulk is the builder for "upsert"-ing +// a bulk of SentinelAppBinary nodes. +type SentinelAppBinaryUpsertBulk struct { + create *SentinelAppBinaryCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.SentinelAppBinary.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *SentinelAppBinaryUpsertBulk) UpdateNewValues() *SentinelAppBinaryUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.SentinelAppBinary.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SentinelAppBinaryUpsertBulk) Ignore() *SentinelAppBinaryUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *SentinelAppBinaryUpsertBulk) DoNothing() *SentinelAppBinaryUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SentinelAppBinaryCreateBulk.OnConflict +// documentation for more info. +func (u *SentinelAppBinaryUpsertBulk) Update(set func(*SentinelAppBinaryUpsert)) *SentinelAppBinaryUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SentinelAppBinaryUpsert{UpdateSet: update}) + })) + return u +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (u *SentinelAppBinaryUpsertBulk) SetSentinelInfoID(v model.InternalID) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetSentinelInfoID(v) + }) +} + +// AddSentinelInfoID adds v to the "sentinel_info_id" field. +func (u *SentinelAppBinaryUpsertBulk) AddSentinelInfoID(v model.InternalID) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.AddSentinelInfoID(v) + }) +} + +// UpdateSentinelInfoID sets the "sentinel_info_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateSentinelInfoID() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateSentinelInfoID() + }) +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryUpsertBulk) SetSentinelLibraryReportedID(v int64) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetSentinelLibraryReportedID(v) + }) +} + +// AddSentinelLibraryReportedID adds v to the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryUpsertBulk) AddSentinelLibraryReportedID(v int64) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.AddSentinelLibraryReportedID(v) + }) +} + +// UpdateSentinelLibraryReportedID sets the "sentinel_library_reported_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateSentinelLibraryReportedID() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateSentinelLibraryReportedID() + }) +} + +// SetGeneratedID sets the "generated_id" field. +func (u *SentinelAppBinaryUpsertBulk) SetGeneratedID(v string) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetGeneratedID(v) + }) +} + +// UpdateGeneratedID sets the "generated_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateGeneratedID() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateGeneratedID() + }) +} + +// SetSizeBytes sets the "size_bytes" field. +func (u *SentinelAppBinaryUpsertBulk) SetSizeBytes(v int64) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetSizeBytes(v) + }) +} + +// AddSizeBytes adds v to the "size_bytes" field. +func (u *SentinelAppBinaryUpsertBulk) AddSizeBytes(v int64) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.AddSizeBytes(v) + }) +} + +// UpdateSizeBytes sets the "size_bytes" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateSizeBytes() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateSizeBytes() + }) +} + +// SetNeedToken sets the "need_token" field. +func (u *SentinelAppBinaryUpsertBulk) SetNeedToken(v bool) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetNeedToken(v) + }) +} + +// UpdateNeedToken sets the "need_token" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateNeedToken() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateNeedToken() + }) +} + +// SetName sets the "name" field. +func (u *SentinelAppBinaryUpsertBulk) SetName(v string) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateName() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateName() + }) +} + +// ClearName clears the value of the "name" field. +func (u *SentinelAppBinaryUpsertBulk) ClearName() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.ClearName() + }) +} + +// SetVersion sets the "version" field. +func (u *SentinelAppBinaryUpsertBulk) SetVersion(v string) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetVersion(v) + }) +} + +// UpdateVersion sets the "version" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateVersion() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateVersion() + }) +} + +// ClearVersion clears the value of the "version" field. +func (u *SentinelAppBinaryUpsertBulk) ClearVersion() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.ClearVersion() + }) +} + +// SetDeveloper sets the "developer" field. +func (u *SentinelAppBinaryUpsertBulk) SetDeveloper(v string) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetDeveloper(v) + }) +} + +// UpdateDeveloper sets the "developer" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateDeveloper() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateDeveloper() + }) +} + +// ClearDeveloper clears the value of the "developer" field. +func (u *SentinelAppBinaryUpsertBulk) ClearDeveloper() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.ClearDeveloper() + }) +} + +// SetPublisher sets the "publisher" field. +func (u *SentinelAppBinaryUpsertBulk) SetPublisher(v string) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetPublisher(v) + }) +} + +// UpdatePublisher sets the "publisher" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdatePublisher() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdatePublisher() + }) +} + +// ClearPublisher clears the value of the "publisher" field. +func (u *SentinelAppBinaryUpsertBulk) ClearPublisher() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.ClearPublisher() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelAppBinaryUpsertBulk) SetUpdatedAt(v time.Time) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateUpdatedAt() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelAppBinaryUpsertBulk) SetCreatedAt(v time.Time) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateCreatedAt() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryUpsertBulk) SetAppBinaryReportSequence(v int64) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetAppBinaryReportSequence(v) + }) +} + +// AddAppBinaryReportSequence adds v to the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryUpsertBulk) AddAppBinaryReportSequence(v int64) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.AddAppBinaryReportSequence(v) + }) +} + +// UpdateAppBinaryReportSequence sets the "app_binary_report_sequence" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateAppBinaryReportSequence() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateAppBinaryReportSequence() + }) +} + +// Exec executes the query. +func (u *SentinelAppBinaryUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the SentinelAppBinaryCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for SentinelAppBinaryCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SentinelAppBinaryUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/data/internal/ent/sentinelappbinary_delete.go b/internal/data/internal/ent/sentinelappbinary_delete.go new file mode 100644 index 00000000..34ba2f90 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" +) + +// SentinelAppBinaryDelete is the builder for deleting a SentinelAppBinary entity. +type SentinelAppBinaryDelete struct { + config + hooks []Hook + mutation *SentinelAppBinaryMutation +} + +// Where appends a list predicates to the SentinelAppBinaryDelete builder. +func (sabd *SentinelAppBinaryDelete) Where(ps ...predicate.SentinelAppBinary) *SentinelAppBinaryDelete { + sabd.mutation.Where(ps...) + return sabd +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (sabd *SentinelAppBinaryDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, sabd.sqlExec, sabd.mutation, sabd.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabd *SentinelAppBinaryDelete) ExecX(ctx context.Context) int { + n, err := sabd.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (sabd *SentinelAppBinaryDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(sentinelappbinary.Table, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt)) + if ps := sabd.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, sabd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + sabd.mutation.done = true + return affected, err +} + +// SentinelAppBinaryDeleteOne is the builder for deleting a single SentinelAppBinary entity. +type SentinelAppBinaryDeleteOne struct { + sabd *SentinelAppBinaryDelete +} + +// Where appends a list predicates to the SentinelAppBinaryDelete builder. +func (sabdo *SentinelAppBinaryDeleteOne) Where(ps ...predicate.SentinelAppBinary) *SentinelAppBinaryDeleteOne { + sabdo.sabd.mutation.Where(ps...) + return sabdo +} + +// Exec executes the deletion query. +func (sabdo *SentinelAppBinaryDeleteOne) Exec(ctx context.Context) error { + n, err := sabdo.sabd.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{sentinelappbinary.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabdo *SentinelAppBinaryDeleteOne) ExecX(ctx context.Context) { + if err := sabdo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/data/internal/ent/sentinelappbinary_query.go b/internal/data/internal/ent/sentinelappbinary_query.go new file mode 100644 index 00000000..4e318dce --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary_query.go @@ -0,0 +1,527 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" +) + +// SentinelAppBinaryQuery is the builder for querying SentinelAppBinary entities. +type SentinelAppBinaryQuery struct { + config + ctx *QueryContext + order []sentinelappbinary.OrderOption + inters []Interceptor + predicates []predicate.SentinelAppBinary + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the SentinelAppBinaryQuery builder. +func (sabq *SentinelAppBinaryQuery) Where(ps ...predicate.SentinelAppBinary) *SentinelAppBinaryQuery { + sabq.predicates = append(sabq.predicates, ps...) + return sabq +} + +// Limit the number of records to be returned by this query. +func (sabq *SentinelAppBinaryQuery) Limit(limit int) *SentinelAppBinaryQuery { + sabq.ctx.Limit = &limit + return sabq +} + +// Offset to start from. +func (sabq *SentinelAppBinaryQuery) Offset(offset int) *SentinelAppBinaryQuery { + sabq.ctx.Offset = &offset + return sabq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (sabq *SentinelAppBinaryQuery) Unique(unique bool) *SentinelAppBinaryQuery { + sabq.ctx.Unique = &unique + return sabq +} + +// Order specifies how the records should be ordered. +func (sabq *SentinelAppBinaryQuery) Order(o ...sentinelappbinary.OrderOption) *SentinelAppBinaryQuery { + sabq.order = append(sabq.order, o...) + return sabq +} + +// First returns the first SentinelAppBinary entity from the query. +// Returns a *NotFoundError when no SentinelAppBinary was found. +func (sabq *SentinelAppBinaryQuery) First(ctx context.Context) (*SentinelAppBinary, error) { + nodes, err := sabq.Limit(1).All(setContextOp(ctx, sabq.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{sentinelappbinary.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (sabq *SentinelAppBinaryQuery) FirstX(ctx context.Context) *SentinelAppBinary { + node, err := sabq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first SentinelAppBinary ID from the query. +// Returns a *NotFoundError when no SentinelAppBinary ID was found. +func (sabq *SentinelAppBinaryQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = sabq.Limit(1).IDs(setContextOp(ctx, sabq.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{sentinelappbinary.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (sabq *SentinelAppBinaryQuery) FirstIDX(ctx context.Context) int { + id, err := sabq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single SentinelAppBinary entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one SentinelAppBinary entity is found. +// Returns a *NotFoundError when no SentinelAppBinary entities are found. +func (sabq *SentinelAppBinaryQuery) Only(ctx context.Context) (*SentinelAppBinary, error) { + nodes, err := sabq.Limit(2).All(setContextOp(ctx, sabq.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{sentinelappbinary.Label} + default: + return nil, &NotSingularError{sentinelappbinary.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (sabq *SentinelAppBinaryQuery) OnlyX(ctx context.Context) *SentinelAppBinary { + node, err := sabq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only SentinelAppBinary ID in the query. +// Returns a *NotSingularError when more than one SentinelAppBinary ID is found. +// Returns a *NotFoundError when no entities are found. +func (sabq *SentinelAppBinaryQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = sabq.Limit(2).IDs(setContextOp(ctx, sabq.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{sentinelappbinary.Label} + default: + err = &NotSingularError{sentinelappbinary.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (sabq *SentinelAppBinaryQuery) OnlyIDX(ctx context.Context) int { + id, err := sabq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of SentinelAppBinaries. +func (sabq *SentinelAppBinaryQuery) All(ctx context.Context) ([]*SentinelAppBinary, error) { + ctx = setContextOp(ctx, sabq.ctx, ent.OpQueryAll) + if err := sabq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*SentinelAppBinary, *SentinelAppBinaryQuery]() + return withInterceptors[[]*SentinelAppBinary](ctx, sabq, qr, sabq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (sabq *SentinelAppBinaryQuery) AllX(ctx context.Context) []*SentinelAppBinary { + nodes, err := sabq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of SentinelAppBinary IDs. +func (sabq *SentinelAppBinaryQuery) IDs(ctx context.Context) (ids []int, err error) { + if sabq.ctx.Unique == nil && sabq.path != nil { + sabq.Unique(true) + } + ctx = setContextOp(ctx, sabq.ctx, ent.OpQueryIDs) + if err = sabq.Select(sentinelappbinary.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (sabq *SentinelAppBinaryQuery) IDsX(ctx context.Context) []int { + ids, err := sabq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (sabq *SentinelAppBinaryQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, sabq.ctx, ent.OpQueryCount) + if err := sabq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, sabq, querierCount[*SentinelAppBinaryQuery](), sabq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (sabq *SentinelAppBinaryQuery) CountX(ctx context.Context) int { + count, err := sabq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (sabq *SentinelAppBinaryQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, sabq.ctx, ent.OpQueryExist) + switch _, err := sabq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (sabq *SentinelAppBinaryQuery) ExistX(ctx context.Context) bool { + exist, err := sabq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the SentinelAppBinaryQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (sabq *SentinelAppBinaryQuery) Clone() *SentinelAppBinaryQuery { + if sabq == nil { + return nil + } + return &SentinelAppBinaryQuery{ + config: sabq.config, + ctx: sabq.ctx.Clone(), + order: append([]sentinelappbinary.OrderOption{}, sabq.order...), + inters: append([]Interceptor{}, sabq.inters...), + predicates: append([]predicate.SentinelAppBinary{}, sabq.predicates...), + // clone intermediate query. + sql: sabq.sql.Clone(), + path: sabq.path, + } +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.SentinelAppBinary.Query(). +// GroupBy(sentinelappbinary.FieldSentinelInfoID). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (sabq *SentinelAppBinaryQuery) GroupBy(field string, fields ...string) *SentinelAppBinaryGroupBy { + sabq.ctx.Fields = append([]string{field}, fields...) + grbuild := &SentinelAppBinaryGroupBy{build: sabq} + grbuild.flds = &sabq.ctx.Fields + grbuild.label = sentinelappbinary.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` +// } +// +// client.SentinelAppBinary.Query(). +// Select(sentinelappbinary.FieldSentinelInfoID). +// Scan(ctx, &v) +func (sabq *SentinelAppBinaryQuery) Select(fields ...string) *SentinelAppBinarySelect { + sabq.ctx.Fields = append(sabq.ctx.Fields, fields...) + sbuild := &SentinelAppBinarySelect{SentinelAppBinaryQuery: sabq} + sbuild.label = sentinelappbinary.Label + sbuild.flds, sbuild.scan = &sabq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a SentinelAppBinarySelect configured with the given aggregations. +func (sabq *SentinelAppBinaryQuery) Aggregate(fns ...AggregateFunc) *SentinelAppBinarySelect { + return sabq.Select().Aggregate(fns...) +} + +func (sabq *SentinelAppBinaryQuery) prepareQuery(ctx context.Context) error { + for _, inter := range sabq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, sabq); err != nil { + return err + } + } + } + for _, f := range sabq.ctx.Fields { + if !sentinelappbinary.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if sabq.path != nil { + prev, err := sabq.path(ctx) + if err != nil { + return err + } + sabq.sql = prev + } + return nil +} + +func (sabq *SentinelAppBinaryQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SentinelAppBinary, error) { + var ( + nodes = []*SentinelAppBinary{} + _spec = sabq.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*SentinelAppBinary).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &SentinelAppBinary{config: sabq.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, sabq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (sabq *SentinelAppBinaryQuery) sqlCount(ctx context.Context) (int, error) { + _spec := sabq.querySpec() + _spec.Node.Columns = sabq.ctx.Fields + if len(sabq.ctx.Fields) > 0 { + _spec.Unique = sabq.ctx.Unique != nil && *sabq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, sabq.driver, _spec) +} + +func (sabq *SentinelAppBinaryQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt)) + _spec.From = sabq.sql + if unique := sabq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if sabq.path != nil { + _spec.Unique = true + } + if fields := sabq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, sentinelappbinary.FieldID) + for i := range fields { + if fields[i] != sentinelappbinary.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := sabq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := sabq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := sabq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := sabq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (sabq *SentinelAppBinaryQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(sabq.driver.Dialect()) + t1 := builder.Table(sentinelappbinary.Table) + columns := sabq.ctx.Fields + if len(columns) == 0 { + columns = sentinelappbinary.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if sabq.sql != nil { + selector = sabq.sql + selector.Select(selector.Columns(columns...)...) + } + if sabq.ctx.Unique != nil && *sabq.ctx.Unique { + selector.Distinct() + } + for _, p := range sabq.predicates { + p(selector) + } + for _, p := range sabq.order { + p(selector) + } + if offset := sabq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := sabq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// SentinelAppBinaryGroupBy is the group-by builder for SentinelAppBinary entities. +type SentinelAppBinaryGroupBy struct { + selector + build *SentinelAppBinaryQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (sabgb *SentinelAppBinaryGroupBy) Aggregate(fns ...AggregateFunc) *SentinelAppBinaryGroupBy { + sabgb.fns = append(sabgb.fns, fns...) + return sabgb +} + +// Scan applies the selector query and scans the result into the given value. +func (sabgb *SentinelAppBinaryGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, sabgb.build.ctx, ent.OpQueryGroupBy) + if err := sabgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*SentinelAppBinaryQuery, *SentinelAppBinaryGroupBy](ctx, sabgb.build, sabgb, sabgb.build.inters, v) +} + +func (sabgb *SentinelAppBinaryGroupBy) sqlScan(ctx context.Context, root *SentinelAppBinaryQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(sabgb.fns)) + for _, fn := range sabgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*sabgb.flds)+len(sabgb.fns)) + for _, f := range *sabgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*sabgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := sabgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// SentinelAppBinarySelect is the builder for selecting fields of SentinelAppBinary entities. +type SentinelAppBinarySelect struct { + *SentinelAppBinaryQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (sabs *SentinelAppBinarySelect) Aggregate(fns ...AggregateFunc) *SentinelAppBinarySelect { + sabs.fns = append(sabs.fns, fns...) + return sabs +} + +// Scan applies the selector query and scans the result into the given value. +func (sabs *SentinelAppBinarySelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, sabs.ctx, ent.OpQuerySelect) + if err := sabs.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*SentinelAppBinaryQuery, *SentinelAppBinarySelect](ctx, sabs.SentinelAppBinaryQuery, sabs, sabs.inters, v) +} + +func (sabs *SentinelAppBinarySelect) sqlScan(ctx context.Context, root *SentinelAppBinaryQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(sabs.fns)) + for _, fn := range sabs.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*sabs.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := sabs.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/internal/data/internal/ent/sentinelappbinary_update.go b/internal/data/internal/ent/sentinelappbinary_update.go new file mode 100644 index 00000000..9cef1b34 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary_update.go @@ -0,0 +1,739 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelAppBinaryUpdate is the builder for updating SentinelAppBinary entities. +type SentinelAppBinaryUpdate struct { + config + hooks []Hook + mutation *SentinelAppBinaryMutation +} + +// Where appends a list predicates to the SentinelAppBinaryUpdate builder. +func (sabu *SentinelAppBinaryUpdate) Where(ps ...predicate.SentinelAppBinary) *SentinelAppBinaryUpdate { + sabu.mutation.Where(ps...) + return sabu +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (sabu *SentinelAppBinaryUpdate) SetSentinelInfoID(mi model.InternalID) *SentinelAppBinaryUpdate { + sabu.mutation.ResetSentinelInfoID() + sabu.mutation.SetSentinelInfoID(mi) + return sabu +} + +// SetNillableSentinelInfoID sets the "sentinel_info_id" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableSentinelInfoID(mi *model.InternalID) *SentinelAppBinaryUpdate { + if mi != nil { + sabu.SetSentinelInfoID(*mi) + } + return sabu +} + +// AddSentinelInfoID adds mi to the "sentinel_info_id" field. +func (sabu *SentinelAppBinaryUpdate) AddSentinelInfoID(mi model.InternalID) *SentinelAppBinaryUpdate { + sabu.mutation.AddSentinelInfoID(mi) + return sabu +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (sabu *SentinelAppBinaryUpdate) SetSentinelLibraryReportedID(i int64) *SentinelAppBinaryUpdate { + sabu.mutation.ResetSentinelLibraryReportedID() + sabu.mutation.SetSentinelLibraryReportedID(i) + return sabu +} + +// SetNillableSentinelLibraryReportedID sets the "sentinel_library_reported_id" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableSentinelLibraryReportedID(i *int64) *SentinelAppBinaryUpdate { + if i != nil { + sabu.SetSentinelLibraryReportedID(*i) + } + return sabu +} + +// AddSentinelLibraryReportedID adds i to the "sentinel_library_reported_id" field. +func (sabu *SentinelAppBinaryUpdate) AddSentinelLibraryReportedID(i int64) *SentinelAppBinaryUpdate { + sabu.mutation.AddSentinelLibraryReportedID(i) + return sabu +} + +// SetGeneratedID sets the "generated_id" field. +func (sabu *SentinelAppBinaryUpdate) SetGeneratedID(s string) *SentinelAppBinaryUpdate { + sabu.mutation.SetGeneratedID(s) + return sabu +} + +// SetNillableGeneratedID sets the "generated_id" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableGeneratedID(s *string) *SentinelAppBinaryUpdate { + if s != nil { + sabu.SetGeneratedID(*s) + } + return sabu +} + +// SetSizeBytes sets the "size_bytes" field. +func (sabu *SentinelAppBinaryUpdate) SetSizeBytes(i int64) *SentinelAppBinaryUpdate { + sabu.mutation.ResetSizeBytes() + sabu.mutation.SetSizeBytes(i) + return sabu +} + +// SetNillableSizeBytes sets the "size_bytes" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableSizeBytes(i *int64) *SentinelAppBinaryUpdate { + if i != nil { + sabu.SetSizeBytes(*i) + } + return sabu +} + +// AddSizeBytes adds i to the "size_bytes" field. +func (sabu *SentinelAppBinaryUpdate) AddSizeBytes(i int64) *SentinelAppBinaryUpdate { + sabu.mutation.AddSizeBytes(i) + return sabu +} + +// SetNeedToken sets the "need_token" field. +func (sabu *SentinelAppBinaryUpdate) SetNeedToken(b bool) *SentinelAppBinaryUpdate { + sabu.mutation.SetNeedToken(b) + return sabu +} + +// SetNillableNeedToken sets the "need_token" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableNeedToken(b *bool) *SentinelAppBinaryUpdate { + if b != nil { + sabu.SetNeedToken(*b) + } + return sabu +} + +// SetName sets the "name" field. +func (sabu *SentinelAppBinaryUpdate) SetName(s string) *SentinelAppBinaryUpdate { + sabu.mutation.SetName(s) + return sabu +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableName(s *string) *SentinelAppBinaryUpdate { + if s != nil { + sabu.SetName(*s) + } + return sabu +} + +// ClearName clears the value of the "name" field. +func (sabu *SentinelAppBinaryUpdate) ClearName() *SentinelAppBinaryUpdate { + sabu.mutation.ClearName() + return sabu +} + +// SetVersion sets the "version" field. +func (sabu *SentinelAppBinaryUpdate) SetVersion(s string) *SentinelAppBinaryUpdate { + sabu.mutation.SetVersion(s) + return sabu +} + +// SetNillableVersion sets the "version" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableVersion(s *string) *SentinelAppBinaryUpdate { + if s != nil { + sabu.SetVersion(*s) + } + return sabu +} + +// ClearVersion clears the value of the "version" field. +func (sabu *SentinelAppBinaryUpdate) ClearVersion() *SentinelAppBinaryUpdate { + sabu.mutation.ClearVersion() + return sabu +} + +// SetDeveloper sets the "developer" field. +func (sabu *SentinelAppBinaryUpdate) SetDeveloper(s string) *SentinelAppBinaryUpdate { + sabu.mutation.SetDeveloper(s) + return sabu +} + +// SetNillableDeveloper sets the "developer" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableDeveloper(s *string) *SentinelAppBinaryUpdate { + if s != nil { + sabu.SetDeveloper(*s) + } + return sabu +} + +// ClearDeveloper clears the value of the "developer" field. +func (sabu *SentinelAppBinaryUpdate) ClearDeveloper() *SentinelAppBinaryUpdate { + sabu.mutation.ClearDeveloper() + return sabu +} + +// SetPublisher sets the "publisher" field. +func (sabu *SentinelAppBinaryUpdate) SetPublisher(s string) *SentinelAppBinaryUpdate { + sabu.mutation.SetPublisher(s) + return sabu +} + +// SetNillablePublisher sets the "publisher" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillablePublisher(s *string) *SentinelAppBinaryUpdate { + if s != nil { + sabu.SetPublisher(*s) + } + return sabu +} + +// ClearPublisher clears the value of the "publisher" field. +func (sabu *SentinelAppBinaryUpdate) ClearPublisher() *SentinelAppBinaryUpdate { + sabu.mutation.ClearPublisher() + return sabu +} + +// SetUpdatedAt sets the "updated_at" field. +func (sabu *SentinelAppBinaryUpdate) SetUpdatedAt(t time.Time) *SentinelAppBinaryUpdate { + sabu.mutation.SetUpdatedAt(t) + return sabu +} + +// SetCreatedAt sets the "created_at" field. +func (sabu *SentinelAppBinaryUpdate) SetCreatedAt(t time.Time) *SentinelAppBinaryUpdate { + sabu.mutation.SetCreatedAt(t) + return sabu +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableCreatedAt(t *time.Time) *SentinelAppBinaryUpdate { + if t != nil { + sabu.SetCreatedAt(*t) + } + return sabu +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (sabu *SentinelAppBinaryUpdate) SetAppBinaryReportSequence(i int64) *SentinelAppBinaryUpdate { + sabu.mutation.ResetAppBinaryReportSequence() + sabu.mutation.SetAppBinaryReportSequence(i) + return sabu +} + +// SetNillableAppBinaryReportSequence sets the "app_binary_report_sequence" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableAppBinaryReportSequence(i *int64) *SentinelAppBinaryUpdate { + if i != nil { + sabu.SetAppBinaryReportSequence(*i) + } + return sabu +} + +// AddAppBinaryReportSequence adds i to the "app_binary_report_sequence" field. +func (sabu *SentinelAppBinaryUpdate) AddAppBinaryReportSequence(i int64) *SentinelAppBinaryUpdate { + sabu.mutation.AddAppBinaryReportSequence(i) + return sabu +} + +// Mutation returns the SentinelAppBinaryMutation object of the builder. +func (sabu *SentinelAppBinaryUpdate) Mutation() *SentinelAppBinaryMutation { + return sabu.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (sabu *SentinelAppBinaryUpdate) Save(ctx context.Context) (int, error) { + sabu.defaults() + return withHooks(ctx, sabu.sqlSave, sabu.mutation, sabu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (sabu *SentinelAppBinaryUpdate) SaveX(ctx context.Context) int { + affected, err := sabu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (sabu *SentinelAppBinaryUpdate) Exec(ctx context.Context) error { + _, err := sabu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabu *SentinelAppBinaryUpdate) ExecX(ctx context.Context) { + if err := sabu.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (sabu *SentinelAppBinaryUpdate) defaults() { + if _, ok := sabu.mutation.UpdatedAt(); !ok { + v := sentinelappbinary.UpdateDefaultUpdatedAt() + sabu.mutation.SetUpdatedAt(v) + } +} + +func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := sqlgraph.NewUpdateSpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt)) + if ps := sabu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := sabu.mutation.SentinelInfoID(); ok { + _spec.SetField(sentinelappbinary.FieldSentinelInfoID, field.TypeInt64, value) + } + if value, ok := sabu.mutation.AddedSentinelInfoID(); ok { + _spec.AddField(sentinelappbinary.FieldSentinelInfoID, field.TypeInt64, value) + } + if value, ok := sabu.mutation.SentinelLibraryReportedID(); ok { + _spec.SetField(sentinelappbinary.FieldSentinelLibraryReportedID, field.TypeInt64, value) + } + if value, ok := sabu.mutation.AddedSentinelLibraryReportedID(); ok { + _spec.AddField(sentinelappbinary.FieldSentinelLibraryReportedID, field.TypeInt64, value) + } + if value, ok := sabu.mutation.GeneratedID(); ok { + _spec.SetField(sentinelappbinary.FieldGeneratedID, field.TypeString, value) + } + if value, ok := sabu.mutation.SizeBytes(); ok { + _spec.SetField(sentinelappbinary.FieldSizeBytes, field.TypeInt64, value) + } + if value, ok := sabu.mutation.AddedSizeBytes(); ok { + _spec.AddField(sentinelappbinary.FieldSizeBytes, field.TypeInt64, value) + } + if value, ok := sabu.mutation.NeedToken(); ok { + _spec.SetField(sentinelappbinary.FieldNeedToken, field.TypeBool, value) + } + if value, ok := sabu.mutation.Name(); ok { + _spec.SetField(sentinelappbinary.FieldName, field.TypeString, value) + } + if sabu.mutation.NameCleared() { + _spec.ClearField(sentinelappbinary.FieldName, field.TypeString) + } + if value, ok := sabu.mutation.Version(); ok { + _spec.SetField(sentinelappbinary.FieldVersion, field.TypeString, value) + } + if sabu.mutation.VersionCleared() { + _spec.ClearField(sentinelappbinary.FieldVersion, field.TypeString) + } + if value, ok := sabu.mutation.Developer(); ok { + _spec.SetField(sentinelappbinary.FieldDeveloper, field.TypeString, value) + } + if sabu.mutation.DeveloperCleared() { + _spec.ClearField(sentinelappbinary.FieldDeveloper, field.TypeString) + } + if value, ok := sabu.mutation.Publisher(); ok { + _spec.SetField(sentinelappbinary.FieldPublisher, field.TypeString, value) + } + if sabu.mutation.PublisherCleared() { + _spec.ClearField(sentinelappbinary.FieldPublisher, field.TypeString) + } + if value, ok := sabu.mutation.UpdatedAt(); ok { + _spec.SetField(sentinelappbinary.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := sabu.mutation.CreatedAt(); ok { + _spec.SetField(sentinelappbinary.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := sabu.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + if value, ok := sabu.mutation.AddedAppBinaryReportSequence(); ok { + _spec.AddField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + if n, err = sqlgraph.UpdateNodes(ctx, sabu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{sentinelappbinary.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + sabu.mutation.done = true + return n, nil +} + +// SentinelAppBinaryUpdateOne is the builder for updating a single SentinelAppBinary entity. +type SentinelAppBinaryUpdateOne struct { + config + fields []string + hooks []Hook + mutation *SentinelAppBinaryMutation +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelInfoID(mi model.InternalID) *SentinelAppBinaryUpdateOne { + sabuo.mutation.ResetSentinelInfoID() + sabuo.mutation.SetSentinelInfoID(mi) + return sabuo +} + +// SetNillableSentinelInfoID sets the "sentinel_info_id" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableSentinelInfoID(mi *model.InternalID) *SentinelAppBinaryUpdateOne { + if mi != nil { + sabuo.SetSentinelInfoID(*mi) + } + return sabuo +} + +// AddSentinelInfoID adds mi to the "sentinel_info_id" field. +func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelInfoID(mi model.InternalID) *SentinelAppBinaryUpdateOne { + sabuo.mutation.AddSentinelInfoID(mi) + return sabuo +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelLibraryReportedID(i int64) *SentinelAppBinaryUpdateOne { + sabuo.mutation.ResetSentinelLibraryReportedID() + sabuo.mutation.SetSentinelLibraryReportedID(i) + return sabuo +} + +// SetNillableSentinelLibraryReportedID sets the "sentinel_library_reported_id" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableSentinelLibraryReportedID(i *int64) *SentinelAppBinaryUpdateOne { + if i != nil { + sabuo.SetSentinelLibraryReportedID(*i) + } + return sabuo +} + +// AddSentinelLibraryReportedID adds i to the "sentinel_library_reported_id" field. +func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelLibraryReportedID(i int64) *SentinelAppBinaryUpdateOne { + sabuo.mutation.AddSentinelLibraryReportedID(i) + return sabuo +} + +// SetGeneratedID sets the "generated_id" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetGeneratedID(s string) *SentinelAppBinaryUpdateOne { + sabuo.mutation.SetGeneratedID(s) + return sabuo +} + +// SetNillableGeneratedID sets the "generated_id" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableGeneratedID(s *string) *SentinelAppBinaryUpdateOne { + if s != nil { + sabuo.SetGeneratedID(*s) + } + return sabuo +} + +// SetSizeBytes sets the "size_bytes" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetSizeBytes(i int64) *SentinelAppBinaryUpdateOne { + sabuo.mutation.ResetSizeBytes() + sabuo.mutation.SetSizeBytes(i) + return sabuo +} + +// SetNillableSizeBytes sets the "size_bytes" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableSizeBytes(i *int64) *SentinelAppBinaryUpdateOne { + if i != nil { + sabuo.SetSizeBytes(*i) + } + return sabuo +} + +// AddSizeBytes adds i to the "size_bytes" field. +func (sabuo *SentinelAppBinaryUpdateOne) AddSizeBytes(i int64) *SentinelAppBinaryUpdateOne { + sabuo.mutation.AddSizeBytes(i) + return sabuo +} + +// SetNeedToken sets the "need_token" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetNeedToken(b bool) *SentinelAppBinaryUpdateOne { + sabuo.mutation.SetNeedToken(b) + return sabuo +} + +// SetNillableNeedToken sets the "need_token" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableNeedToken(b *bool) *SentinelAppBinaryUpdateOne { + if b != nil { + sabuo.SetNeedToken(*b) + } + return sabuo +} + +// SetName sets the "name" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetName(s string) *SentinelAppBinaryUpdateOne { + sabuo.mutation.SetName(s) + return sabuo +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableName(s *string) *SentinelAppBinaryUpdateOne { + if s != nil { + sabuo.SetName(*s) + } + return sabuo +} + +// ClearName clears the value of the "name" field. +func (sabuo *SentinelAppBinaryUpdateOne) ClearName() *SentinelAppBinaryUpdateOne { + sabuo.mutation.ClearName() + return sabuo +} + +// SetVersion sets the "version" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetVersion(s string) *SentinelAppBinaryUpdateOne { + sabuo.mutation.SetVersion(s) + return sabuo +} + +// SetNillableVersion sets the "version" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableVersion(s *string) *SentinelAppBinaryUpdateOne { + if s != nil { + sabuo.SetVersion(*s) + } + return sabuo +} + +// ClearVersion clears the value of the "version" field. +func (sabuo *SentinelAppBinaryUpdateOne) ClearVersion() *SentinelAppBinaryUpdateOne { + sabuo.mutation.ClearVersion() + return sabuo +} + +// SetDeveloper sets the "developer" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetDeveloper(s string) *SentinelAppBinaryUpdateOne { + sabuo.mutation.SetDeveloper(s) + return sabuo +} + +// SetNillableDeveloper sets the "developer" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableDeveloper(s *string) *SentinelAppBinaryUpdateOne { + if s != nil { + sabuo.SetDeveloper(*s) + } + return sabuo +} + +// ClearDeveloper clears the value of the "developer" field. +func (sabuo *SentinelAppBinaryUpdateOne) ClearDeveloper() *SentinelAppBinaryUpdateOne { + sabuo.mutation.ClearDeveloper() + return sabuo +} + +// SetPublisher sets the "publisher" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetPublisher(s string) *SentinelAppBinaryUpdateOne { + sabuo.mutation.SetPublisher(s) + return sabuo +} + +// SetNillablePublisher sets the "publisher" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillablePublisher(s *string) *SentinelAppBinaryUpdateOne { + if s != nil { + sabuo.SetPublisher(*s) + } + return sabuo +} + +// ClearPublisher clears the value of the "publisher" field. +func (sabuo *SentinelAppBinaryUpdateOne) ClearPublisher() *SentinelAppBinaryUpdateOne { + sabuo.mutation.ClearPublisher() + return sabuo +} + +// SetUpdatedAt sets the "updated_at" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetUpdatedAt(t time.Time) *SentinelAppBinaryUpdateOne { + sabuo.mutation.SetUpdatedAt(t) + return sabuo +} + +// SetCreatedAt sets the "created_at" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetCreatedAt(t time.Time) *SentinelAppBinaryUpdateOne { + sabuo.mutation.SetCreatedAt(t) + return sabuo +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableCreatedAt(t *time.Time) *SentinelAppBinaryUpdateOne { + if t != nil { + sabuo.SetCreatedAt(*t) + } + return sabuo +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetAppBinaryReportSequence(i int64) *SentinelAppBinaryUpdateOne { + sabuo.mutation.ResetAppBinaryReportSequence() + sabuo.mutation.SetAppBinaryReportSequence(i) + return sabuo +} + +// SetNillableAppBinaryReportSequence sets the "app_binary_report_sequence" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableAppBinaryReportSequence(i *int64) *SentinelAppBinaryUpdateOne { + if i != nil { + sabuo.SetAppBinaryReportSequence(*i) + } + return sabuo +} + +// AddAppBinaryReportSequence adds i to the "app_binary_report_sequence" field. +func (sabuo *SentinelAppBinaryUpdateOne) AddAppBinaryReportSequence(i int64) *SentinelAppBinaryUpdateOne { + sabuo.mutation.AddAppBinaryReportSequence(i) + return sabuo +} + +// Mutation returns the SentinelAppBinaryMutation object of the builder. +func (sabuo *SentinelAppBinaryUpdateOne) Mutation() *SentinelAppBinaryMutation { + return sabuo.mutation +} + +// Where appends a list predicates to the SentinelAppBinaryUpdate builder. +func (sabuo *SentinelAppBinaryUpdateOne) Where(ps ...predicate.SentinelAppBinary) *SentinelAppBinaryUpdateOne { + sabuo.mutation.Where(ps...) + return sabuo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (sabuo *SentinelAppBinaryUpdateOne) Select(field string, fields ...string) *SentinelAppBinaryUpdateOne { + sabuo.fields = append([]string{field}, fields...) + return sabuo +} + +// Save executes the query and returns the updated SentinelAppBinary entity. +func (sabuo *SentinelAppBinaryUpdateOne) Save(ctx context.Context) (*SentinelAppBinary, error) { + sabuo.defaults() + return withHooks(ctx, sabuo.sqlSave, sabuo.mutation, sabuo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (sabuo *SentinelAppBinaryUpdateOne) SaveX(ctx context.Context) *SentinelAppBinary { + node, err := sabuo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (sabuo *SentinelAppBinaryUpdateOne) Exec(ctx context.Context) error { + _, err := sabuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabuo *SentinelAppBinaryUpdateOne) ExecX(ctx context.Context) { + if err := sabuo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (sabuo *SentinelAppBinaryUpdateOne) defaults() { + if _, ok := sabuo.mutation.UpdatedAt(); !ok { + v := sentinelappbinary.UpdateDefaultUpdatedAt() + sabuo.mutation.SetUpdatedAt(v) + } +} + +func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *SentinelAppBinary, err error) { + _spec := sqlgraph.NewUpdateSpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt)) + id, ok := sabuo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SentinelAppBinary.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := sabuo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, sentinelappbinary.FieldID) + for _, f := range fields { + if !sentinelappbinary.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != sentinelappbinary.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := sabuo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := sabuo.mutation.SentinelInfoID(); ok { + _spec.SetField(sentinelappbinary.FieldSentinelInfoID, field.TypeInt64, value) + } + if value, ok := sabuo.mutation.AddedSentinelInfoID(); ok { + _spec.AddField(sentinelappbinary.FieldSentinelInfoID, field.TypeInt64, value) + } + if value, ok := sabuo.mutation.SentinelLibraryReportedID(); ok { + _spec.SetField(sentinelappbinary.FieldSentinelLibraryReportedID, field.TypeInt64, value) + } + if value, ok := sabuo.mutation.AddedSentinelLibraryReportedID(); ok { + _spec.AddField(sentinelappbinary.FieldSentinelLibraryReportedID, field.TypeInt64, value) + } + if value, ok := sabuo.mutation.GeneratedID(); ok { + _spec.SetField(sentinelappbinary.FieldGeneratedID, field.TypeString, value) + } + if value, ok := sabuo.mutation.SizeBytes(); ok { + _spec.SetField(sentinelappbinary.FieldSizeBytes, field.TypeInt64, value) + } + if value, ok := sabuo.mutation.AddedSizeBytes(); ok { + _spec.AddField(sentinelappbinary.FieldSizeBytes, field.TypeInt64, value) + } + if value, ok := sabuo.mutation.NeedToken(); ok { + _spec.SetField(sentinelappbinary.FieldNeedToken, field.TypeBool, value) + } + if value, ok := sabuo.mutation.Name(); ok { + _spec.SetField(sentinelappbinary.FieldName, field.TypeString, value) + } + if sabuo.mutation.NameCleared() { + _spec.ClearField(sentinelappbinary.FieldName, field.TypeString) + } + if value, ok := sabuo.mutation.Version(); ok { + _spec.SetField(sentinelappbinary.FieldVersion, field.TypeString, value) + } + if sabuo.mutation.VersionCleared() { + _spec.ClearField(sentinelappbinary.FieldVersion, field.TypeString) + } + if value, ok := sabuo.mutation.Developer(); ok { + _spec.SetField(sentinelappbinary.FieldDeveloper, field.TypeString, value) + } + if sabuo.mutation.DeveloperCleared() { + _spec.ClearField(sentinelappbinary.FieldDeveloper, field.TypeString) + } + if value, ok := sabuo.mutation.Publisher(); ok { + _spec.SetField(sentinelappbinary.FieldPublisher, field.TypeString, value) + } + if sabuo.mutation.PublisherCleared() { + _spec.ClearField(sentinelappbinary.FieldPublisher, field.TypeString) + } + if value, ok := sabuo.mutation.UpdatedAt(); ok { + _spec.SetField(sentinelappbinary.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := sabuo.mutation.CreatedAt(); ok { + _spec.SetField(sentinelappbinary.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := sabuo.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + if value, ok := sabuo.mutation.AddedAppBinaryReportSequence(); ok { + _spec.AddField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + _node = &SentinelAppBinary{config: sabuo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, sabuo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{sentinelappbinary.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + sabuo.mutation.done = true + return _node, nil +} diff --git a/internal/data/internal/ent/sentinelappbinaryfile.go b/internal/data/internal/ent/sentinelappbinaryfile.go new file mode 100644 index 00000000..f33364bf --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile.go @@ -0,0 +1,219 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelAppBinaryFile is the model entity for the SentinelAppBinaryFile schema. +type SentinelAppBinaryFile struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // SentinelInfoID holds the value of the "sentinel_info_id" field. + SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` + // SentinelLibraryReportedID holds the value of the "sentinel_library_reported_id" field. + SentinelLibraryReportedID int64 `json:"sentinel_library_reported_id,omitempty"` + // SentinelAppBinaryGeneratedID holds the value of the "sentinel_app_binary_generated_id" field. + SentinelAppBinaryGeneratedID string `json:"sentinel_app_binary_generated_id,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` + // SizeBytes holds the value of the "size_bytes" field. + SizeBytes int64 `json:"size_bytes,omitempty"` + // Sha256 holds the value of the "sha256" field. + Sha256 []byte `json:"sha256,omitempty"` + // ServerFilePath holds the value of the "server_file_path" field. + ServerFilePath string `json:"server_file_path,omitempty"` + // ChunksInfo holds the value of the "chunks_info" field. + ChunksInfo string `json:"chunks_info,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // AppBinaryReportSequence holds the value of the "app_binary_report_sequence" field. + AppBinaryReportSequence int64 `json:"app_binary_report_sequence,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*SentinelAppBinaryFile) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case sentinelappbinaryfile.FieldSha256: + values[i] = new([]byte) + case sentinelappbinaryfile.FieldID, sentinelappbinaryfile.FieldSentinelInfoID, sentinelappbinaryfile.FieldSentinelLibraryReportedID, sentinelappbinaryfile.FieldSizeBytes, sentinelappbinaryfile.FieldAppBinaryReportSequence: + values[i] = new(sql.NullInt64) + case sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID, sentinelappbinaryfile.FieldName, sentinelappbinaryfile.FieldServerFilePath, sentinelappbinaryfile.FieldChunksInfo: + values[i] = new(sql.NullString) + case sentinelappbinaryfile.FieldUpdatedAt, sentinelappbinaryfile.FieldCreatedAt: + values[i] = new(sql.NullTime) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the SentinelAppBinaryFile fields. +func (sabf *SentinelAppBinaryFile) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case sentinelappbinaryfile.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + sabf.ID = int(value.Int64) + case sentinelappbinaryfile.FieldSentinelInfoID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field sentinel_info_id", values[i]) + } else if value.Valid { + sabf.SentinelInfoID = model.InternalID(value.Int64) + } + case sentinelappbinaryfile.FieldSentinelLibraryReportedID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field sentinel_library_reported_id", values[i]) + } else if value.Valid { + sabf.SentinelLibraryReportedID = value.Int64 + } + case sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field sentinel_app_binary_generated_id", values[i]) + } else if value.Valid { + sabf.SentinelAppBinaryGeneratedID = value.String + } + case sentinelappbinaryfile.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + sabf.Name = value.String + } + case sentinelappbinaryfile.FieldSizeBytes: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field size_bytes", values[i]) + } else if value.Valid { + sabf.SizeBytes = value.Int64 + } + case sentinelappbinaryfile.FieldSha256: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field sha256", values[i]) + } else if value != nil { + sabf.Sha256 = *value + } + case sentinelappbinaryfile.FieldServerFilePath: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field server_file_path", values[i]) + } else if value.Valid { + sabf.ServerFilePath = value.String + } + case sentinelappbinaryfile.FieldChunksInfo: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field chunks_info", values[i]) + } else if value.Valid { + sabf.ChunksInfo = value.String + } + case sentinelappbinaryfile.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + sabf.UpdatedAt = value.Time + } + case sentinelappbinaryfile.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + sabf.CreatedAt = value.Time + } + case sentinelappbinaryfile.FieldAppBinaryReportSequence: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field app_binary_report_sequence", values[i]) + } else if value.Valid { + sabf.AppBinaryReportSequence = value.Int64 + } + default: + sabf.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the SentinelAppBinaryFile. +// This includes values selected through modifiers, order, etc. +func (sabf *SentinelAppBinaryFile) Value(name string) (ent.Value, error) { + return sabf.selectValues.Get(name) +} + +// Update returns a builder for updating this SentinelAppBinaryFile. +// Note that you need to call SentinelAppBinaryFile.Unwrap() before calling this method if this SentinelAppBinaryFile +// was returned from a transaction, and the transaction was committed or rolled back. +func (sabf *SentinelAppBinaryFile) Update() *SentinelAppBinaryFileUpdateOne { + return NewSentinelAppBinaryFileClient(sabf.config).UpdateOne(sabf) +} + +// Unwrap unwraps the SentinelAppBinaryFile entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (sabf *SentinelAppBinaryFile) Unwrap() *SentinelAppBinaryFile { + _tx, ok := sabf.config.driver.(*txDriver) + if !ok { + panic("ent: SentinelAppBinaryFile is not a transactional entity") + } + sabf.config.driver = _tx.drv + return sabf +} + +// String implements the fmt.Stringer. +func (sabf *SentinelAppBinaryFile) String() string { + var builder strings.Builder + builder.WriteString("SentinelAppBinaryFile(") + builder.WriteString(fmt.Sprintf("id=%v, ", sabf.ID)) + builder.WriteString("sentinel_info_id=") + builder.WriteString(fmt.Sprintf("%v", sabf.SentinelInfoID)) + builder.WriteString(", ") + builder.WriteString("sentinel_library_reported_id=") + builder.WriteString(fmt.Sprintf("%v", sabf.SentinelLibraryReportedID)) + builder.WriteString(", ") + builder.WriteString("sentinel_app_binary_generated_id=") + builder.WriteString(sabf.SentinelAppBinaryGeneratedID) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(sabf.Name) + builder.WriteString(", ") + builder.WriteString("size_bytes=") + builder.WriteString(fmt.Sprintf("%v", sabf.SizeBytes)) + builder.WriteString(", ") + builder.WriteString("sha256=") + builder.WriteString(fmt.Sprintf("%v", sabf.Sha256)) + builder.WriteString(", ") + builder.WriteString("server_file_path=") + builder.WriteString(sabf.ServerFilePath) + builder.WriteString(", ") + builder.WriteString("chunks_info=") + builder.WriteString(sabf.ChunksInfo) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(sabf.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(sabf.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("app_binary_report_sequence=") + builder.WriteString(fmt.Sprintf("%v", sabf.AppBinaryReportSequence)) + builder.WriteByte(')') + return builder.String() +} + +// SentinelAppBinaryFiles is a parsable slice of SentinelAppBinaryFile. +type SentinelAppBinaryFiles []*SentinelAppBinaryFile diff --git a/internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go b/internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go new file mode 100644 index 00000000..faaf4a12 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go @@ -0,0 +1,133 @@ +// Code generated by ent, DO NOT EDIT. + +package sentinelappbinaryfile + +import ( + "time" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the sentinelappbinaryfile type in the database. + Label = "sentinel_app_binary_file" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldSentinelInfoID holds the string denoting the sentinel_info_id field in the database. + FieldSentinelInfoID = "sentinel_info_id" + // FieldSentinelLibraryReportedID holds the string denoting the sentinel_library_reported_id field in the database. + FieldSentinelLibraryReportedID = "sentinel_library_reported_id" + // FieldSentinelAppBinaryGeneratedID holds the string denoting the sentinel_app_binary_generated_id field in the database. + FieldSentinelAppBinaryGeneratedID = "sentinel_app_binary_generated_id" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldSizeBytes holds the string denoting the size_bytes field in the database. + FieldSizeBytes = "size_bytes" + // FieldSha256 holds the string denoting the sha256 field in the database. + FieldSha256 = "sha256" + // FieldServerFilePath holds the string denoting the server_file_path field in the database. + FieldServerFilePath = "server_file_path" + // FieldChunksInfo holds the string denoting the chunks_info field in the database. + FieldChunksInfo = "chunks_info" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldAppBinaryReportSequence holds the string denoting the app_binary_report_sequence field in the database. + FieldAppBinaryReportSequence = "app_binary_report_sequence" + // Table holds the table name of the sentinelappbinaryfile in the database. + Table = "sentinel_app_binary_files" +) + +// Columns holds all SQL columns for sentinelappbinaryfile fields. +var Columns = []string{ + FieldID, + FieldSentinelInfoID, + FieldSentinelLibraryReportedID, + FieldSentinelAppBinaryGeneratedID, + FieldName, + FieldSizeBytes, + FieldSha256, + FieldServerFilePath, + FieldChunksInfo, + FieldUpdatedAt, + FieldCreatedAt, + FieldAppBinaryReportSequence, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time +) + +// OrderOption defines the ordering options for the SentinelAppBinaryFile queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// BySentinelInfoID orders the results by the sentinel_info_id field. +func BySentinelInfoID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSentinelInfoID, opts...).ToFunc() +} + +// BySentinelLibraryReportedID orders the results by the sentinel_library_reported_id field. +func BySentinelLibraryReportedID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSentinelLibraryReportedID, opts...).ToFunc() +} + +// BySentinelAppBinaryGeneratedID orders the results by the sentinel_app_binary_generated_id field. +func BySentinelAppBinaryGeneratedID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSentinelAppBinaryGeneratedID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// BySizeBytes orders the results by the size_bytes field. +func BySizeBytes(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSizeBytes, opts...).ToFunc() +} + +// ByServerFilePath orders the results by the server_file_path field. +func ByServerFilePath(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldServerFilePath, opts...).ToFunc() +} + +// ByChunksInfo orders the results by the chunks_info field. +func ByChunksInfo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldChunksInfo, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByAppBinaryReportSequence orders the results by the app_binary_report_sequence field. +func ByAppBinaryReportSequence(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAppBinaryReportSequence, opts...).ToFunc() +} diff --git a/internal/data/internal/ent/sentinelappbinaryfile/where.go b/internal/data/internal/ent/sentinelappbinaryfile/where.go new file mode 100644 index 00000000..43100946 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile/where.go @@ -0,0 +1,691 @@ +// Code generated by ent, DO NOT EDIT. + +package sentinelappbinaryfile + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/model" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldID, id)) +} + +// SentinelInfoID applies equality check predicate on the "sentinel_info_id" field. It's identical to SentinelInfoIDEQ. +func SentinelInfoID(v model.InternalID) predicate.SentinelAppBinaryFile { + vc := int64(v) + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelInfoID, vc)) +} + +// SentinelLibraryReportedID applies equality check predicate on the "sentinel_library_reported_id" field. It's identical to SentinelLibraryReportedIDEQ. +func SentinelLibraryReportedID(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelLibraryReportedID, v)) +} + +// SentinelAppBinaryGeneratedID applies equality check predicate on the "sentinel_app_binary_generated_id" field. It's identical to SentinelAppBinaryGeneratedIDEQ. +func SentinelAppBinaryGeneratedID(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryGeneratedID, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldName, v)) +} + +// SizeBytes applies equality check predicate on the "size_bytes" field. It's identical to SizeBytesEQ. +func SizeBytes(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSizeBytes, v)) +} + +// Sha256 applies equality check predicate on the "sha256" field. It's identical to Sha256EQ. +func Sha256(v []byte) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSha256, v)) +} + +// ServerFilePath applies equality check predicate on the "server_file_path" field. It's identical to ServerFilePathEQ. +func ServerFilePath(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldServerFilePath, v)) +} + +// ChunksInfo applies equality check predicate on the "chunks_info" field. It's identical to ChunksInfoEQ. +func ChunksInfo(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldChunksInfo, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldCreatedAt, v)) +} + +// AppBinaryReportSequence applies equality check predicate on the "app_binary_report_sequence" field. It's identical to AppBinaryReportSequenceEQ. +func AppBinaryReportSequence(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldAppBinaryReportSequence, v)) +} + +// SentinelInfoIDEQ applies the EQ predicate on the "sentinel_info_id" field. +func SentinelInfoIDEQ(v model.InternalID) predicate.SentinelAppBinaryFile { + vc := int64(v) + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDNEQ applies the NEQ predicate on the "sentinel_info_id" field. +func SentinelInfoIDNEQ(v model.InternalID) predicate.SentinelAppBinaryFile { + vc := int64(v) + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDIn applies the In predicate on the "sentinel_info_id" field. +func SentinelInfoIDIn(vs ...model.InternalID) predicate.SentinelAppBinaryFile { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldSentinelInfoID, v...)) +} + +// SentinelInfoIDNotIn applies the NotIn predicate on the "sentinel_info_id" field. +func SentinelInfoIDNotIn(vs ...model.InternalID) predicate.SentinelAppBinaryFile { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldSentinelInfoID, v...)) +} + +// SentinelInfoIDGT applies the GT predicate on the "sentinel_info_id" field. +func SentinelInfoIDGT(v model.InternalID) predicate.SentinelAppBinaryFile { + vc := int64(v) + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDGTE applies the GTE predicate on the "sentinel_info_id" field. +func SentinelInfoIDGTE(v model.InternalID) predicate.SentinelAppBinaryFile { + vc := int64(v) + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDLT applies the LT predicate on the "sentinel_info_id" field. +func SentinelInfoIDLT(v model.InternalID) predicate.SentinelAppBinaryFile { + vc := int64(v) + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDLTE applies the LTE predicate on the "sentinel_info_id" field. +func SentinelInfoIDLTE(v model.InternalID) predicate.SentinelAppBinaryFile { + vc := int64(v) + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldSentinelInfoID, vc)) +} + +// SentinelLibraryReportedIDEQ applies the EQ predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDEQ(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelLibraryReportedID, v)) +} + +// SentinelLibraryReportedIDNEQ applies the NEQ predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDNEQ(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldSentinelLibraryReportedID, v)) +} + +// SentinelLibraryReportedIDIn applies the In predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDIn(vs ...int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldSentinelLibraryReportedID, vs...)) +} + +// SentinelLibraryReportedIDNotIn applies the NotIn predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDNotIn(vs ...int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldSentinelLibraryReportedID, vs...)) +} + +// SentinelLibraryReportedIDGT applies the GT predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDGT(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldSentinelLibraryReportedID, v)) +} + +// SentinelLibraryReportedIDGTE applies the GTE predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDGTE(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldSentinelLibraryReportedID, v)) +} + +// SentinelLibraryReportedIDLT applies the LT predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDLT(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldSentinelLibraryReportedID, v)) +} + +// SentinelLibraryReportedIDLTE applies the LTE predicate on the "sentinel_library_reported_id" field. +func SentinelLibraryReportedIDLTE(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldSentinelLibraryReportedID, v)) +} + +// SentinelAppBinaryGeneratedIDEQ applies the EQ predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDEQ(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryGeneratedID, v)) +} + +// SentinelAppBinaryGeneratedIDNEQ applies the NEQ predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDNEQ(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldSentinelAppBinaryGeneratedID, v)) +} + +// SentinelAppBinaryGeneratedIDIn applies the In predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDIn(vs ...string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldSentinelAppBinaryGeneratedID, vs...)) +} + +// SentinelAppBinaryGeneratedIDNotIn applies the NotIn predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDNotIn(vs ...string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldSentinelAppBinaryGeneratedID, vs...)) +} + +// SentinelAppBinaryGeneratedIDGT applies the GT predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDGT(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldSentinelAppBinaryGeneratedID, v)) +} + +// SentinelAppBinaryGeneratedIDGTE applies the GTE predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDGTE(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldSentinelAppBinaryGeneratedID, v)) +} + +// SentinelAppBinaryGeneratedIDLT applies the LT predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDLT(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldSentinelAppBinaryGeneratedID, v)) +} + +// SentinelAppBinaryGeneratedIDLTE applies the LTE predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDLTE(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldSentinelAppBinaryGeneratedID, v)) +} + +// SentinelAppBinaryGeneratedIDContains applies the Contains predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDContains(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldContains(FieldSentinelAppBinaryGeneratedID, v)) +} + +// SentinelAppBinaryGeneratedIDHasPrefix applies the HasPrefix predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDHasPrefix(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldHasPrefix(FieldSentinelAppBinaryGeneratedID, v)) +} + +// SentinelAppBinaryGeneratedIDHasSuffix applies the HasSuffix predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDHasSuffix(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldHasSuffix(FieldSentinelAppBinaryGeneratedID, v)) +} + +// SentinelAppBinaryGeneratedIDEqualFold applies the EqualFold predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDEqualFold(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEqualFold(FieldSentinelAppBinaryGeneratedID, v)) +} + +// SentinelAppBinaryGeneratedIDContainsFold applies the ContainsFold predicate on the "sentinel_app_binary_generated_id" field. +func SentinelAppBinaryGeneratedIDContainsFold(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldContainsFold(FieldSentinelAppBinaryGeneratedID, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldContainsFold(FieldName, v)) +} + +// SizeBytesEQ applies the EQ predicate on the "size_bytes" field. +func SizeBytesEQ(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSizeBytes, v)) +} + +// SizeBytesNEQ applies the NEQ predicate on the "size_bytes" field. +func SizeBytesNEQ(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldSizeBytes, v)) +} + +// SizeBytesIn applies the In predicate on the "size_bytes" field. +func SizeBytesIn(vs ...int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldSizeBytes, vs...)) +} + +// SizeBytesNotIn applies the NotIn predicate on the "size_bytes" field. +func SizeBytesNotIn(vs ...int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldSizeBytes, vs...)) +} + +// SizeBytesGT applies the GT predicate on the "size_bytes" field. +func SizeBytesGT(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldSizeBytes, v)) +} + +// SizeBytesGTE applies the GTE predicate on the "size_bytes" field. +func SizeBytesGTE(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldSizeBytes, v)) +} + +// SizeBytesLT applies the LT predicate on the "size_bytes" field. +func SizeBytesLT(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldSizeBytes, v)) +} + +// SizeBytesLTE applies the LTE predicate on the "size_bytes" field. +func SizeBytesLTE(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldSizeBytes, v)) +} + +// Sha256EQ applies the EQ predicate on the "sha256" field. +func Sha256EQ(v []byte) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSha256, v)) +} + +// Sha256NEQ applies the NEQ predicate on the "sha256" field. +func Sha256NEQ(v []byte) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldSha256, v)) +} + +// Sha256In applies the In predicate on the "sha256" field. +func Sha256In(vs ...[]byte) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldSha256, vs...)) +} + +// Sha256NotIn applies the NotIn predicate on the "sha256" field. +func Sha256NotIn(vs ...[]byte) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldSha256, vs...)) +} + +// Sha256GT applies the GT predicate on the "sha256" field. +func Sha256GT(v []byte) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldSha256, v)) +} + +// Sha256GTE applies the GTE predicate on the "sha256" field. +func Sha256GTE(v []byte) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldSha256, v)) +} + +// Sha256LT applies the LT predicate on the "sha256" field. +func Sha256LT(v []byte) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldSha256, v)) +} + +// Sha256LTE applies the LTE predicate on the "sha256" field. +func Sha256LTE(v []byte) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldSha256, v)) +} + +// ServerFilePathEQ applies the EQ predicate on the "server_file_path" field. +func ServerFilePathEQ(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldServerFilePath, v)) +} + +// ServerFilePathNEQ applies the NEQ predicate on the "server_file_path" field. +func ServerFilePathNEQ(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldServerFilePath, v)) +} + +// ServerFilePathIn applies the In predicate on the "server_file_path" field. +func ServerFilePathIn(vs ...string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldServerFilePath, vs...)) +} + +// ServerFilePathNotIn applies the NotIn predicate on the "server_file_path" field. +func ServerFilePathNotIn(vs ...string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldServerFilePath, vs...)) +} + +// ServerFilePathGT applies the GT predicate on the "server_file_path" field. +func ServerFilePathGT(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldServerFilePath, v)) +} + +// ServerFilePathGTE applies the GTE predicate on the "server_file_path" field. +func ServerFilePathGTE(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldServerFilePath, v)) +} + +// ServerFilePathLT applies the LT predicate on the "server_file_path" field. +func ServerFilePathLT(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldServerFilePath, v)) +} + +// ServerFilePathLTE applies the LTE predicate on the "server_file_path" field. +func ServerFilePathLTE(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldServerFilePath, v)) +} + +// ServerFilePathContains applies the Contains predicate on the "server_file_path" field. +func ServerFilePathContains(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldContains(FieldServerFilePath, v)) +} + +// ServerFilePathHasPrefix applies the HasPrefix predicate on the "server_file_path" field. +func ServerFilePathHasPrefix(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldHasPrefix(FieldServerFilePath, v)) +} + +// ServerFilePathHasSuffix applies the HasSuffix predicate on the "server_file_path" field. +func ServerFilePathHasSuffix(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldHasSuffix(FieldServerFilePath, v)) +} + +// ServerFilePathEqualFold applies the EqualFold predicate on the "server_file_path" field. +func ServerFilePathEqualFold(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEqualFold(FieldServerFilePath, v)) +} + +// ServerFilePathContainsFold applies the ContainsFold predicate on the "server_file_path" field. +func ServerFilePathContainsFold(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldContainsFold(FieldServerFilePath, v)) +} + +// ChunksInfoEQ applies the EQ predicate on the "chunks_info" field. +func ChunksInfoEQ(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldChunksInfo, v)) +} + +// ChunksInfoNEQ applies the NEQ predicate on the "chunks_info" field. +func ChunksInfoNEQ(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldChunksInfo, v)) +} + +// ChunksInfoIn applies the In predicate on the "chunks_info" field. +func ChunksInfoIn(vs ...string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldChunksInfo, vs...)) +} + +// ChunksInfoNotIn applies the NotIn predicate on the "chunks_info" field. +func ChunksInfoNotIn(vs ...string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldChunksInfo, vs...)) +} + +// ChunksInfoGT applies the GT predicate on the "chunks_info" field. +func ChunksInfoGT(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldChunksInfo, v)) +} + +// ChunksInfoGTE applies the GTE predicate on the "chunks_info" field. +func ChunksInfoGTE(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldChunksInfo, v)) +} + +// ChunksInfoLT applies the LT predicate on the "chunks_info" field. +func ChunksInfoLT(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldChunksInfo, v)) +} + +// ChunksInfoLTE applies the LTE predicate on the "chunks_info" field. +func ChunksInfoLTE(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldChunksInfo, v)) +} + +// ChunksInfoContains applies the Contains predicate on the "chunks_info" field. +func ChunksInfoContains(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldContains(FieldChunksInfo, v)) +} + +// ChunksInfoHasPrefix applies the HasPrefix predicate on the "chunks_info" field. +func ChunksInfoHasPrefix(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldHasPrefix(FieldChunksInfo, v)) +} + +// ChunksInfoHasSuffix applies the HasSuffix predicate on the "chunks_info" field. +func ChunksInfoHasSuffix(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldHasSuffix(FieldChunksInfo, v)) +} + +// ChunksInfoIsNil applies the IsNil predicate on the "chunks_info" field. +func ChunksInfoIsNil() predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIsNull(FieldChunksInfo)) +} + +// ChunksInfoNotNil applies the NotNil predicate on the "chunks_info" field. +func ChunksInfoNotNil() predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotNull(FieldChunksInfo)) +} + +// ChunksInfoEqualFold applies the EqualFold predicate on the "chunks_info" field. +func ChunksInfoEqualFold(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEqualFold(FieldChunksInfo, v)) +} + +// ChunksInfoContainsFold applies the ContainsFold predicate on the "chunks_info" field. +func ChunksInfoContainsFold(v string) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldContainsFold(FieldChunksInfo, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldCreatedAt, v)) +} + +// AppBinaryReportSequenceEQ applies the EQ predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceEQ(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceNEQ applies the NEQ predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceNEQ(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceIn applies the In predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceIn(vs ...int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldAppBinaryReportSequence, vs...)) +} + +// AppBinaryReportSequenceNotIn applies the NotIn predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceNotIn(vs ...int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldAppBinaryReportSequence, vs...)) +} + +// AppBinaryReportSequenceGT applies the GT predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceGT(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceGTE applies the GTE predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceGTE(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceLT applies the LT predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceLT(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceLTE applies the LTE predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceLTE(v int64) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldAppBinaryReportSequence, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.SentinelAppBinaryFile) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.SentinelAppBinaryFile) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.SentinelAppBinaryFile) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.NotPredicates(p)) +} diff --git a/internal/data/internal/ent/sentinelappbinaryfile_create.go b/internal/data/internal/ent/sentinelappbinaryfile_create.go new file mode 100644 index 00000000..128d4f00 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile_create.go @@ -0,0 +1,1121 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelAppBinaryFileCreate is the builder for creating a SentinelAppBinaryFile entity. +type SentinelAppBinaryFileCreate struct { + config + mutation *SentinelAppBinaryFileMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (sabfc *SentinelAppBinaryFileCreate) SetSentinelInfoID(mi model.InternalID) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetSentinelInfoID(mi) + return sabfc +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (sabfc *SentinelAppBinaryFileCreate) SetSentinelLibraryReportedID(i int64) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetSentinelLibraryReportedID(i) + return sabfc +} + +// SetSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field. +func (sabfc *SentinelAppBinaryFileCreate) SetSentinelAppBinaryGeneratedID(s string) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetSentinelAppBinaryGeneratedID(s) + return sabfc +} + +// SetName sets the "name" field. +func (sabfc *SentinelAppBinaryFileCreate) SetName(s string) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetName(s) + return sabfc +} + +// SetSizeBytes sets the "size_bytes" field. +func (sabfc *SentinelAppBinaryFileCreate) SetSizeBytes(i int64) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetSizeBytes(i) + return sabfc +} + +// SetSha256 sets the "sha256" field. +func (sabfc *SentinelAppBinaryFileCreate) SetSha256(b []byte) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetSha256(b) + return sabfc +} + +// SetServerFilePath sets the "server_file_path" field. +func (sabfc *SentinelAppBinaryFileCreate) SetServerFilePath(s string) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetServerFilePath(s) + return sabfc +} + +// SetChunksInfo sets the "chunks_info" field. +func (sabfc *SentinelAppBinaryFileCreate) SetChunksInfo(s string) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetChunksInfo(s) + return sabfc +} + +// SetNillableChunksInfo sets the "chunks_info" field if the given value is not nil. +func (sabfc *SentinelAppBinaryFileCreate) SetNillableChunksInfo(s *string) *SentinelAppBinaryFileCreate { + if s != nil { + sabfc.SetChunksInfo(*s) + } + return sabfc +} + +// SetUpdatedAt sets the "updated_at" field. +func (sabfc *SentinelAppBinaryFileCreate) SetUpdatedAt(t time.Time) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetUpdatedAt(t) + return sabfc +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (sabfc *SentinelAppBinaryFileCreate) SetNillableUpdatedAt(t *time.Time) *SentinelAppBinaryFileCreate { + if t != nil { + sabfc.SetUpdatedAt(*t) + } + return sabfc +} + +// SetCreatedAt sets the "created_at" field. +func (sabfc *SentinelAppBinaryFileCreate) SetCreatedAt(t time.Time) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetCreatedAt(t) + return sabfc +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (sabfc *SentinelAppBinaryFileCreate) SetNillableCreatedAt(t *time.Time) *SentinelAppBinaryFileCreate { + if t != nil { + sabfc.SetCreatedAt(*t) + } + return sabfc +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (sabfc *SentinelAppBinaryFileCreate) SetAppBinaryReportSequence(i int64) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetAppBinaryReportSequence(i) + return sabfc +} + +// Mutation returns the SentinelAppBinaryFileMutation object of the builder. +func (sabfc *SentinelAppBinaryFileCreate) Mutation() *SentinelAppBinaryFileMutation { + return sabfc.mutation +} + +// Save creates the SentinelAppBinaryFile in the database. +func (sabfc *SentinelAppBinaryFileCreate) Save(ctx context.Context) (*SentinelAppBinaryFile, error) { + sabfc.defaults() + return withHooks(ctx, sabfc.sqlSave, sabfc.mutation, sabfc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (sabfc *SentinelAppBinaryFileCreate) SaveX(ctx context.Context) *SentinelAppBinaryFile { + v, err := sabfc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (sabfc *SentinelAppBinaryFileCreate) Exec(ctx context.Context) error { + _, err := sabfc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabfc *SentinelAppBinaryFileCreate) ExecX(ctx context.Context) { + if err := sabfc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (sabfc *SentinelAppBinaryFileCreate) defaults() { + if _, ok := sabfc.mutation.UpdatedAt(); !ok { + v := sentinelappbinaryfile.DefaultUpdatedAt() + sabfc.mutation.SetUpdatedAt(v) + } + if _, ok := sabfc.mutation.CreatedAt(); !ok { + v := sentinelappbinaryfile.DefaultCreatedAt() + sabfc.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (sabfc *SentinelAppBinaryFileCreate) check() error { + if _, ok := sabfc.mutation.SentinelInfoID(); !ok { + return &ValidationError{Name: "sentinel_info_id", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.sentinel_info_id"`)} + } + if _, ok := sabfc.mutation.SentinelLibraryReportedID(); !ok { + return &ValidationError{Name: "sentinel_library_reported_id", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.sentinel_library_reported_id"`)} + } + if _, ok := sabfc.mutation.SentinelAppBinaryGeneratedID(); !ok { + return &ValidationError{Name: "sentinel_app_binary_generated_id", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.sentinel_app_binary_generated_id"`)} + } + if _, ok := sabfc.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.name"`)} + } + if _, ok := sabfc.mutation.SizeBytes(); !ok { + return &ValidationError{Name: "size_bytes", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.size_bytes"`)} + } + if _, ok := sabfc.mutation.Sha256(); !ok { + return &ValidationError{Name: "sha256", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.sha256"`)} + } + if _, ok := sabfc.mutation.ServerFilePath(); !ok { + return &ValidationError{Name: "server_file_path", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.server_file_path"`)} + } + if _, ok := sabfc.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.updated_at"`)} + } + if _, ok := sabfc.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.created_at"`)} + } + if _, ok := sabfc.mutation.AppBinaryReportSequence(); !ok { + return &ValidationError{Name: "app_binary_report_sequence", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.app_binary_report_sequence"`)} + } + return nil +} + +func (sabfc *SentinelAppBinaryFileCreate) sqlSave(ctx context.Context) (*SentinelAppBinaryFile, error) { + if err := sabfc.check(); err != nil { + return nil, err + } + _node, _spec := sabfc.createSpec() + if err := sqlgraph.CreateNode(ctx, sabfc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + sabfc.mutation.id = &_node.ID + sabfc.mutation.done = true + return _node, nil +} + +func (sabfc *SentinelAppBinaryFileCreate) createSpec() (*SentinelAppBinaryFile, *sqlgraph.CreateSpec) { + var ( + _node = &SentinelAppBinaryFile{config: sabfc.config} + _spec = sqlgraph.NewCreateSpec(sentinelappbinaryfile.Table, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt)) + ) + _spec.OnConflict = sabfc.conflict + if value, ok := sabfc.mutation.SentinelInfoID(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSentinelInfoID, field.TypeInt64, value) + _node.SentinelInfoID = value + } + if value, ok := sabfc.mutation.SentinelLibraryReportedID(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSentinelLibraryReportedID, field.TypeInt64, value) + _node.SentinelLibraryReportedID = value + } + if value, ok := sabfc.mutation.SentinelAppBinaryGeneratedID(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID, field.TypeString, value) + _node.SentinelAppBinaryGeneratedID = value + } + if value, ok := sabfc.mutation.Name(); ok { + _spec.SetField(sentinelappbinaryfile.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := sabfc.mutation.SizeBytes(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSizeBytes, field.TypeInt64, value) + _node.SizeBytes = value + } + if value, ok := sabfc.mutation.Sha256(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSha256, field.TypeBytes, value) + _node.Sha256 = value + } + if value, ok := sabfc.mutation.ServerFilePath(); ok { + _spec.SetField(sentinelappbinaryfile.FieldServerFilePath, field.TypeString, value) + _node.ServerFilePath = value + } + if value, ok := sabfc.mutation.ChunksInfo(); ok { + _spec.SetField(sentinelappbinaryfile.FieldChunksInfo, field.TypeString, value) + _node.ChunksInfo = value + } + if value, ok := sabfc.mutation.UpdatedAt(); ok { + _spec.SetField(sentinelappbinaryfile.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := sabfc.mutation.CreatedAt(); ok { + _spec.SetField(sentinelappbinaryfile.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := sabfc.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelappbinaryfile.FieldAppBinaryReportSequence, field.TypeInt64, value) + _node.AppBinaryReportSequence = value + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.SentinelAppBinaryFile.Create(). +// SetSentinelInfoID(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.SentinelAppBinaryFileUpsert) { +// SetSentinelInfoID(v+v). +// }). +// Exec(ctx) +func (sabfc *SentinelAppBinaryFileCreate) OnConflict(opts ...sql.ConflictOption) *SentinelAppBinaryFileUpsertOne { + sabfc.conflict = opts + return &SentinelAppBinaryFileUpsertOne{ + create: sabfc, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.SentinelAppBinaryFile.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (sabfc *SentinelAppBinaryFileCreate) OnConflictColumns(columns ...string) *SentinelAppBinaryFileUpsertOne { + sabfc.conflict = append(sabfc.conflict, sql.ConflictColumns(columns...)) + return &SentinelAppBinaryFileUpsertOne{ + create: sabfc, + } +} + +type ( + // SentinelAppBinaryFileUpsertOne is the builder for "upsert"-ing + // one SentinelAppBinaryFile node. + SentinelAppBinaryFileUpsertOne struct { + create *SentinelAppBinaryFileCreate + } + + // SentinelAppBinaryFileUpsert is the "OnConflict" setter. + SentinelAppBinaryFileUpsert struct { + *sql.UpdateSet + } +) + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (u *SentinelAppBinaryFileUpsert) SetSentinelInfoID(v model.InternalID) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldSentinelInfoID, v) + return u +} + +// UpdateSentinelInfoID sets the "sentinel_info_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateSentinelInfoID() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldSentinelInfoID) + return u +} + +// AddSentinelInfoID adds v to the "sentinel_info_id" field. +func (u *SentinelAppBinaryFileUpsert) AddSentinelInfoID(v model.InternalID) *SentinelAppBinaryFileUpsert { + u.Add(sentinelappbinaryfile.FieldSentinelInfoID, v) + return u +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryFileUpsert) SetSentinelLibraryReportedID(v int64) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldSentinelLibraryReportedID, v) + return u +} + +// UpdateSentinelLibraryReportedID sets the "sentinel_library_reported_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateSentinelLibraryReportedID() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldSentinelLibraryReportedID) + return u +} + +// AddSentinelLibraryReportedID adds v to the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryFileUpsert) AddSentinelLibraryReportedID(v int64) *SentinelAppBinaryFileUpsert { + u.Add(sentinelappbinaryfile.FieldSentinelLibraryReportedID, v) + return u +} + +// SetSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field. +func (u *SentinelAppBinaryFileUpsert) SetSentinelAppBinaryGeneratedID(v string) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID, v) + return u +} + +// UpdateSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateSentinelAppBinaryGeneratedID() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID) + return u +} + +// SetName sets the "name" field. +func (u *SentinelAppBinaryFileUpsert) SetName(v string) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldName, v) + return u +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateName() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldName) + return u +} + +// SetSizeBytes sets the "size_bytes" field. +func (u *SentinelAppBinaryFileUpsert) SetSizeBytes(v int64) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldSizeBytes, v) + return u +} + +// UpdateSizeBytes sets the "size_bytes" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateSizeBytes() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldSizeBytes) + return u +} + +// AddSizeBytes adds v to the "size_bytes" field. +func (u *SentinelAppBinaryFileUpsert) AddSizeBytes(v int64) *SentinelAppBinaryFileUpsert { + u.Add(sentinelappbinaryfile.FieldSizeBytes, v) + return u +} + +// SetSha256 sets the "sha256" field. +func (u *SentinelAppBinaryFileUpsert) SetSha256(v []byte) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldSha256, v) + return u +} + +// UpdateSha256 sets the "sha256" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateSha256() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldSha256) + return u +} + +// SetServerFilePath sets the "server_file_path" field. +func (u *SentinelAppBinaryFileUpsert) SetServerFilePath(v string) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldServerFilePath, v) + return u +} + +// UpdateServerFilePath sets the "server_file_path" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateServerFilePath() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldServerFilePath) + return u +} + +// SetChunksInfo sets the "chunks_info" field. +func (u *SentinelAppBinaryFileUpsert) SetChunksInfo(v string) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldChunksInfo, v) + return u +} + +// UpdateChunksInfo sets the "chunks_info" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateChunksInfo() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldChunksInfo) + return u +} + +// ClearChunksInfo clears the value of the "chunks_info" field. +func (u *SentinelAppBinaryFileUpsert) ClearChunksInfo() *SentinelAppBinaryFileUpsert { + u.SetNull(sentinelappbinaryfile.FieldChunksInfo) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelAppBinaryFileUpsert) SetUpdatedAt(v time.Time) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateUpdatedAt() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldUpdatedAt) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelAppBinaryFileUpsert) SetCreatedAt(v time.Time) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateCreatedAt() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldCreatedAt) + return u +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryFileUpsert) SetAppBinaryReportSequence(v int64) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldAppBinaryReportSequence, v) + return u +} + +// UpdateAppBinaryReportSequence sets the "app_binary_report_sequence" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateAppBinaryReportSequence() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldAppBinaryReportSequence) + return u +} + +// AddAppBinaryReportSequence adds v to the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryFileUpsert) AddAppBinaryReportSequence(v int64) *SentinelAppBinaryFileUpsert { + u.Add(sentinelappbinaryfile.FieldAppBinaryReportSequence, v) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create. +// Using this option is equivalent to using: +// +// client.SentinelAppBinaryFile.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *SentinelAppBinaryFileUpsertOne) UpdateNewValues() *SentinelAppBinaryFileUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.SentinelAppBinaryFile.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SentinelAppBinaryFileUpsertOne) Ignore() *SentinelAppBinaryFileUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *SentinelAppBinaryFileUpsertOne) DoNothing() *SentinelAppBinaryFileUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SentinelAppBinaryFileCreate.OnConflict +// documentation for more info. +func (u *SentinelAppBinaryFileUpsertOne) Update(set func(*SentinelAppBinaryFileUpsert)) *SentinelAppBinaryFileUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SentinelAppBinaryFileUpsert{UpdateSet: update}) + })) + return u +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (u *SentinelAppBinaryFileUpsertOne) SetSentinelInfoID(v model.InternalID) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSentinelInfoID(v) + }) +} + +// AddSentinelInfoID adds v to the "sentinel_info_id" field. +func (u *SentinelAppBinaryFileUpsertOne) AddSentinelInfoID(v model.InternalID) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.AddSentinelInfoID(v) + }) +} + +// UpdateSentinelInfoID sets the "sentinel_info_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateSentinelInfoID() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSentinelInfoID() + }) +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryFileUpsertOne) SetSentinelLibraryReportedID(v int64) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSentinelLibraryReportedID(v) + }) +} + +// AddSentinelLibraryReportedID adds v to the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryFileUpsertOne) AddSentinelLibraryReportedID(v int64) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.AddSentinelLibraryReportedID(v) + }) +} + +// UpdateSentinelLibraryReportedID sets the "sentinel_library_reported_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateSentinelLibraryReportedID() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSentinelLibraryReportedID() + }) +} + +// SetSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field. +func (u *SentinelAppBinaryFileUpsertOne) SetSentinelAppBinaryGeneratedID(v string) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSentinelAppBinaryGeneratedID(v) + }) +} + +// UpdateSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateSentinelAppBinaryGeneratedID() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSentinelAppBinaryGeneratedID() + }) +} + +// SetName sets the "name" field. +func (u *SentinelAppBinaryFileUpsertOne) SetName(v string) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateName() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateName() + }) +} + +// SetSizeBytes sets the "size_bytes" field. +func (u *SentinelAppBinaryFileUpsertOne) SetSizeBytes(v int64) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSizeBytes(v) + }) +} + +// AddSizeBytes adds v to the "size_bytes" field. +func (u *SentinelAppBinaryFileUpsertOne) AddSizeBytes(v int64) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.AddSizeBytes(v) + }) +} + +// UpdateSizeBytes sets the "size_bytes" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateSizeBytes() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSizeBytes() + }) +} + +// SetSha256 sets the "sha256" field. +func (u *SentinelAppBinaryFileUpsertOne) SetSha256(v []byte) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSha256(v) + }) +} + +// UpdateSha256 sets the "sha256" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateSha256() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSha256() + }) +} + +// SetServerFilePath sets the "server_file_path" field. +func (u *SentinelAppBinaryFileUpsertOne) SetServerFilePath(v string) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetServerFilePath(v) + }) +} + +// UpdateServerFilePath sets the "server_file_path" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateServerFilePath() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateServerFilePath() + }) +} + +// SetChunksInfo sets the "chunks_info" field. +func (u *SentinelAppBinaryFileUpsertOne) SetChunksInfo(v string) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetChunksInfo(v) + }) +} + +// UpdateChunksInfo sets the "chunks_info" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateChunksInfo() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateChunksInfo() + }) +} + +// ClearChunksInfo clears the value of the "chunks_info" field. +func (u *SentinelAppBinaryFileUpsertOne) ClearChunksInfo() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.ClearChunksInfo() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelAppBinaryFileUpsertOne) SetUpdatedAt(v time.Time) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateUpdatedAt() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelAppBinaryFileUpsertOne) SetCreatedAt(v time.Time) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateCreatedAt() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryFileUpsertOne) SetAppBinaryReportSequence(v int64) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetAppBinaryReportSequence(v) + }) +} + +// AddAppBinaryReportSequence adds v to the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryFileUpsertOne) AddAppBinaryReportSequence(v int64) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.AddAppBinaryReportSequence(v) + }) +} + +// UpdateAppBinaryReportSequence sets the "app_binary_report_sequence" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateAppBinaryReportSequence() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateAppBinaryReportSequence() + }) +} + +// Exec executes the query. +func (u *SentinelAppBinaryFileUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for SentinelAppBinaryFileCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SentinelAppBinaryFileUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *SentinelAppBinaryFileUpsertOne) ID(ctx context.Context) (id int, err error) { + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *SentinelAppBinaryFileUpsertOne) IDX(ctx context.Context) int { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// SentinelAppBinaryFileCreateBulk is the builder for creating many SentinelAppBinaryFile entities in bulk. +type SentinelAppBinaryFileCreateBulk struct { + config + err error + builders []*SentinelAppBinaryFileCreate + conflict []sql.ConflictOption +} + +// Save creates the SentinelAppBinaryFile entities in the database. +func (sabfcb *SentinelAppBinaryFileCreateBulk) Save(ctx context.Context) ([]*SentinelAppBinaryFile, error) { + if sabfcb.err != nil { + return nil, sabfcb.err + } + specs := make([]*sqlgraph.CreateSpec, len(sabfcb.builders)) + nodes := make([]*SentinelAppBinaryFile, len(sabfcb.builders)) + mutators := make([]Mutator, len(sabfcb.builders)) + for i := range sabfcb.builders { + func(i int, root context.Context) { + builder := sabfcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*SentinelAppBinaryFileMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, sabfcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = sabfcb.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, sabfcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + if specs[i].ID.Value != nil { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(id) + } + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, sabfcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (sabfcb *SentinelAppBinaryFileCreateBulk) SaveX(ctx context.Context) []*SentinelAppBinaryFile { + v, err := sabfcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (sabfcb *SentinelAppBinaryFileCreateBulk) Exec(ctx context.Context) error { + _, err := sabfcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabfcb *SentinelAppBinaryFileCreateBulk) ExecX(ctx context.Context) { + if err := sabfcb.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.SentinelAppBinaryFile.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.SentinelAppBinaryFileUpsert) { +// SetSentinelInfoID(v+v). +// }). +// Exec(ctx) +func (sabfcb *SentinelAppBinaryFileCreateBulk) OnConflict(opts ...sql.ConflictOption) *SentinelAppBinaryFileUpsertBulk { + sabfcb.conflict = opts + return &SentinelAppBinaryFileUpsertBulk{ + create: sabfcb, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.SentinelAppBinaryFile.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (sabfcb *SentinelAppBinaryFileCreateBulk) OnConflictColumns(columns ...string) *SentinelAppBinaryFileUpsertBulk { + sabfcb.conflict = append(sabfcb.conflict, sql.ConflictColumns(columns...)) + return &SentinelAppBinaryFileUpsertBulk{ + create: sabfcb, + } +} + +// SentinelAppBinaryFileUpsertBulk is the builder for "upsert"-ing +// a bulk of SentinelAppBinaryFile nodes. +type SentinelAppBinaryFileUpsertBulk struct { + create *SentinelAppBinaryFileCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.SentinelAppBinaryFile.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *SentinelAppBinaryFileUpsertBulk) UpdateNewValues() *SentinelAppBinaryFileUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.SentinelAppBinaryFile.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SentinelAppBinaryFileUpsertBulk) Ignore() *SentinelAppBinaryFileUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *SentinelAppBinaryFileUpsertBulk) DoNothing() *SentinelAppBinaryFileUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SentinelAppBinaryFileCreateBulk.OnConflict +// documentation for more info. +func (u *SentinelAppBinaryFileUpsertBulk) Update(set func(*SentinelAppBinaryFileUpsert)) *SentinelAppBinaryFileUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SentinelAppBinaryFileUpsert{UpdateSet: update}) + })) + return u +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetSentinelInfoID(v model.InternalID) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSentinelInfoID(v) + }) +} + +// AddSentinelInfoID adds v to the "sentinel_info_id" field. +func (u *SentinelAppBinaryFileUpsertBulk) AddSentinelInfoID(v model.InternalID) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.AddSentinelInfoID(v) + }) +} + +// UpdateSentinelInfoID sets the "sentinel_info_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateSentinelInfoID() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSentinelInfoID() + }) +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetSentinelLibraryReportedID(v int64) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSentinelLibraryReportedID(v) + }) +} + +// AddSentinelLibraryReportedID adds v to the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryFileUpsertBulk) AddSentinelLibraryReportedID(v int64) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.AddSentinelLibraryReportedID(v) + }) +} + +// UpdateSentinelLibraryReportedID sets the "sentinel_library_reported_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateSentinelLibraryReportedID() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSentinelLibraryReportedID() + }) +} + +// SetSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetSentinelAppBinaryGeneratedID(v string) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSentinelAppBinaryGeneratedID(v) + }) +} + +// UpdateSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateSentinelAppBinaryGeneratedID() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSentinelAppBinaryGeneratedID() + }) +} + +// SetName sets the "name" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetName(v string) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetName(v) + }) +} + +// UpdateName sets the "name" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateName() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateName() + }) +} + +// SetSizeBytes sets the "size_bytes" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetSizeBytes(v int64) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSizeBytes(v) + }) +} + +// AddSizeBytes adds v to the "size_bytes" field. +func (u *SentinelAppBinaryFileUpsertBulk) AddSizeBytes(v int64) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.AddSizeBytes(v) + }) +} + +// UpdateSizeBytes sets the "size_bytes" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateSizeBytes() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSizeBytes() + }) +} + +// SetSha256 sets the "sha256" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetSha256(v []byte) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSha256(v) + }) +} + +// UpdateSha256 sets the "sha256" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateSha256() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSha256() + }) +} + +// SetServerFilePath sets the "server_file_path" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetServerFilePath(v string) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetServerFilePath(v) + }) +} + +// UpdateServerFilePath sets the "server_file_path" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateServerFilePath() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateServerFilePath() + }) +} + +// SetChunksInfo sets the "chunks_info" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetChunksInfo(v string) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetChunksInfo(v) + }) +} + +// UpdateChunksInfo sets the "chunks_info" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateChunksInfo() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateChunksInfo() + }) +} + +// ClearChunksInfo clears the value of the "chunks_info" field. +func (u *SentinelAppBinaryFileUpsertBulk) ClearChunksInfo() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.ClearChunksInfo() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetUpdatedAt(v time.Time) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateUpdatedAt() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetCreatedAt(v time.Time) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateCreatedAt() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetAppBinaryReportSequence(v int64) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetAppBinaryReportSequence(v) + }) +} + +// AddAppBinaryReportSequence adds v to the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryFileUpsertBulk) AddAppBinaryReportSequence(v int64) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.AddAppBinaryReportSequence(v) + }) +} + +// UpdateAppBinaryReportSequence sets the "app_binary_report_sequence" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateAppBinaryReportSequence() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateAppBinaryReportSequence() + }) +} + +// Exec executes the query. +func (u *SentinelAppBinaryFileUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the SentinelAppBinaryFileCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for SentinelAppBinaryFileCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SentinelAppBinaryFileUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/data/internal/ent/sentinelappbinaryfile_delete.go b/internal/data/internal/ent/sentinelappbinaryfile_delete.go new file mode 100644 index 00000000..78472628 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" +) + +// SentinelAppBinaryFileDelete is the builder for deleting a SentinelAppBinaryFile entity. +type SentinelAppBinaryFileDelete struct { + config + hooks []Hook + mutation *SentinelAppBinaryFileMutation +} + +// Where appends a list predicates to the SentinelAppBinaryFileDelete builder. +func (sabfd *SentinelAppBinaryFileDelete) Where(ps ...predicate.SentinelAppBinaryFile) *SentinelAppBinaryFileDelete { + sabfd.mutation.Where(ps...) + return sabfd +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (sabfd *SentinelAppBinaryFileDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, sabfd.sqlExec, sabfd.mutation, sabfd.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabfd *SentinelAppBinaryFileDelete) ExecX(ctx context.Context) int { + n, err := sabfd.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (sabfd *SentinelAppBinaryFileDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(sentinelappbinaryfile.Table, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt)) + if ps := sabfd.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, sabfd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + sabfd.mutation.done = true + return affected, err +} + +// SentinelAppBinaryFileDeleteOne is the builder for deleting a single SentinelAppBinaryFile entity. +type SentinelAppBinaryFileDeleteOne struct { + sabfd *SentinelAppBinaryFileDelete +} + +// Where appends a list predicates to the SentinelAppBinaryFileDelete builder. +func (sabfdo *SentinelAppBinaryFileDeleteOne) Where(ps ...predicate.SentinelAppBinaryFile) *SentinelAppBinaryFileDeleteOne { + sabfdo.sabfd.mutation.Where(ps...) + return sabfdo +} + +// Exec executes the deletion query. +func (sabfdo *SentinelAppBinaryFileDeleteOne) Exec(ctx context.Context) error { + n, err := sabfdo.sabfd.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{sentinelappbinaryfile.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabfdo *SentinelAppBinaryFileDeleteOne) ExecX(ctx context.Context) { + if err := sabfdo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/data/internal/ent/sentinelappbinaryfile_query.go b/internal/data/internal/ent/sentinelappbinaryfile_query.go new file mode 100644 index 00000000..ee1eec96 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile_query.go @@ -0,0 +1,527 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" +) + +// SentinelAppBinaryFileQuery is the builder for querying SentinelAppBinaryFile entities. +type SentinelAppBinaryFileQuery struct { + config + ctx *QueryContext + order []sentinelappbinaryfile.OrderOption + inters []Interceptor + predicates []predicate.SentinelAppBinaryFile + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the SentinelAppBinaryFileQuery builder. +func (sabfq *SentinelAppBinaryFileQuery) Where(ps ...predicate.SentinelAppBinaryFile) *SentinelAppBinaryFileQuery { + sabfq.predicates = append(sabfq.predicates, ps...) + return sabfq +} + +// Limit the number of records to be returned by this query. +func (sabfq *SentinelAppBinaryFileQuery) Limit(limit int) *SentinelAppBinaryFileQuery { + sabfq.ctx.Limit = &limit + return sabfq +} + +// Offset to start from. +func (sabfq *SentinelAppBinaryFileQuery) Offset(offset int) *SentinelAppBinaryFileQuery { + sabfq.ctx.Offset = &offset + return sabfq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (sabfq *SentinelAppBinaryFileQuery) Unique(unique bool) *SentinelAppBinaryFileQuery { + sabfq.ctx.Unique = &unique + return sabfq +} + +// Order specifies how the records should be ordered. +func (sabfq *SentinelAppBinaryFileQuery) Order(o ...sentinelappbinaryfile.OrderOption) *SentinelAppBinaryFileQuery { + sabfq.order = append(sabfq.order, o...) + return sabfq +} + +// First returns the first SentinelAppBinaryFile entity from the query. +// Returns a *NotFoundError when no SentinelAppBinaryFile was found. +func (sabfq *SentinelAppBinaryFileQuery) First(ctx context.Context) (*SentinelAppBinaryFile, error) { + nodes, err := sabfq.Limit(1).All(setContextOp(ctx, sabfq.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{sentinelappbinaryfile.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (sabfq *SentinelAppBinaryFileQuery) FirstX(ctx context.Context) *SentinelAppBinaryFile { + node, err := sabfq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first SentinelAppBinaryFile ID from the query. +// Returns a *NotFoundError when no SentinelAppBinaryFile ID was found. +func (sabfq *SentinelAppBinaryFileQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = sabfq.Limit(1).IDs(setContextOp(ctx, sabfq.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{sentinelappbinaryfile.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (sabfq *SentinelAppBinaryFileQuery) FirstIDX(ctx context.Context) int { + id, err := sabfq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single SentinelAppBinaryFile entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one SentinelAppBinaryFile entity is found. +// Returns a *NotFoundError when no SentinelAppBinaryFile entities are found. +func (sabfq *SentinelAppBinaryFileQuery) Only(ctx context.Context) (*SentinelAppBinaryFile, error) { + nodes, err := sabfq.Limit(2).All(setContextOp(ctx, sabfq.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{sentinelappbinaryfile.Label} + default: + return nil, &NotSingularError{sentinelappbinaryfile.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (sabfq *SentinelAppBinaryFileQuery) OnlyX(ctx context.Context) *SentinelAppBinaryFile { + node, err := sabfq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only SentinelAppBinaryFile ID in the query. +// Returns a *NotSingularError when more than one SentinelAppBinaryFile ID is found. +// Returns a *NotFoundError when no entities are found. +func (sabfq *SentinelAppBinaryFileQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = sabfq.Limit(2).IDs(setContextOp(ctx, sabfq.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{sentinelappbinaryfile.Label} + default: + err = &NotSingularError{sentinelappbinaryfile.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (sabfq *SentinelAppBinaryFileQuery) OnlyIDX(ctx context.Context) int { + id, err := sabfq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of SentinelAppBinaryFiles. +func (sabfq *SentinelAppBinaryFileQuery) All(ctx context.Context) ([]*SentinelAppBinaryFile, error) { + ctx = setContextOp(ctx, sabfq.ctx, ent.OpQueryAll) + if err := sabfq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*SentinelAppBinaryFile, *SentinelAppBinaryFileQuery]() + return withInterceptors[[]*SentinelAppBinaryFile](ctx, sabfq, qr, sabfq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (sabfq *SentinelAppBinaryFileQuery) AllX(ctx context.Context) []*SentinelAppBinaryFile { + nodes, err := sabfq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of SentinelAppBinaryFile IDs. +func (sabfq *SentinelAppBinaryFileQuery) IDs(ctx context.Context) (ids []int, err error) { + if sabfq.ctx.Unique == nil && sabfq.path != nil { + sabfq.Unique(true) + } + ctx = setContextOp(ctx, sabfq.ctx, ent.OpQueryIDs) + if err = sabfq.Select(sentinelappbinaryfile.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (sabfq *SentinelAppBinaryFileQuery) IDsX(ctx context.Context) []int { + ids, err := sabfq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (sabfq *SentinelAppBinaryFileQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, sabfq.ctx, ent.OpQueryCount) + if err := sabfq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, sabfq, querierCount[*SentinelAppBinaryFileQuery](), sabfq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (sabfq *SentinelAppBinaryFileQuery) CountX(ctx context.Context) int { + count, err := sabfq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (sabfq *SentinelAppBinaryFileQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, sabfq.ctx, ent.OpQueryExist) + switch _, err := sabfq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (sabfq *SentinelAppBinaryFileQuery) ExistX(ctx context.Context) bool { + exist, err := sabfq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the SentinelAppBinaryFileQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (sabfq *SentinelAppBinaryFileQuery) Clone() *SentinelAppBinaryFileQuery { + if sabfq == nil { + return nil + } + return &SentinelAppBinaryFileQuery{ + config: sabfq.config, + ctx: sabfq.ctx.Clone(), + order: append([]sentinelappbinaryfile.OrderOption{}, sabfq.order...), + inters: append([]Interceptor{}, sabfq.inters...), + predicates: append([]predicate.SentinelAppBinaryFile{}, sabfq.predicates...), + // clone intermediate query. + sql: sabfq.sql.Clone(), + path: sabfq.path, + } +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.SentinelAppBinaryFile.Query(). +// GroupBy(sentinelappbinaryfile.FieldSentinelInfoID). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (sabfq *SentinelAppBinaryFileQuery) GroupBy(field string, fields ...string) *SentinelAppBinaryFileGroupBy { + sabfq.ctx.Fields = append([]string{field}, fields...) + grbuild := &SentinelAppBinaryFileGroupBy{build: sabfq} + grbuild.flds = &sabfq.ctx.Fields + grbuild.label = sentinelappbinaryfile.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` +// } +// +// client.SentinelAppBinaryFile.Query(). +// Select(sentinelappbinaryfile.FieldSentinelInfoID). +// Scan(ctx, &v) +func (sabfq *SentinelAppBinaryFileQuery) Select(fields ...string) *SentinelAppBinaryFileSelect { + sabfq.ctx.Fields = append(sabfq.ctx.Fields, fields...) + sbuild := &SentinelAppBinaryFileSelect{SentinelAppBinaryFileQuery: sabfq} + sbuild.label = sentinelappbinaryfile.Label + sbuild.flds, sbuild.scan = &sabfq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a SentinelAppBinaryFileSelect configured with the given aggregations. +func (sabfq *SentinelAppBinaryFileQuery) Aggregate(fns ...AggregateFunc) *SentinelAppBinaryFileSelect { + return sabfq.Select().Aggregate(fns...) +} + +func (sabfq *SentinelAppBinaryFileQuery) prepareQuery(ctx context.Context) error { + for _, inter := range sabfq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, sabfq); err != nil { + return err + } + } + } + for _, f := range sabfq.ctx.Fields { + if !sentinelappbinaryfile.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if sabfq.path != nil { + prev, err := sabfq.path(ctx) + if err != nil { + return err + } + sabfq.sql = prev + } + return nil +} + +func (sabfq *SentinelAppBinaryFileQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SentinelAppBinaryFile, error) { + var ( + nodes = []*SentinelAppBinaryFile{} + _spec = sabfq.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*SentinelAppBinaryFile).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &SentinelAppBinaryFile{config: sabfq.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, sabfq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (sabfq *SentinelAppBinaryFileQuery) sqlCount(ctx context.Context) (int, error) { + _spec := sabfq.querySpec() + _spec.Node.Columns = sabfq.ctx.Fields + if len(sabfq.ctx.Fields) > 0 { + _spec.Unique = sabfq.ctx.Unique != nil && *sabfq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, sabfq.driver, _spec) +} + +func (sabfq *SentinelAppBinaryFileQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt)) + _spec.From = sabfq.sql + if unique := sabfq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if sabfq.path != nil { + _spec.Unique = true + } + if fields := sabfq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, sentinelappbinaryfile.FieldID) + for i := range fields { + if fields[i] != sentinelappbinaryfile.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := sabfq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := sabfq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := sabfq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := sabfq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (sabfq *SentinelAppBinaryFileQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(sabfq.driver.Dialect()) + t1 := builder.Table(sentinelappbinaryfile.Table) + columns := sabfq.ctx.Fields + if len(columns) == 0 { + columns = sentinelappbinaryfile.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if sabfq.sql != nil { + selector = sabfq.sql + selector.Select(selector.Columns(columns...)...) + } + if sabfq.ctx.Unique != nil && *sabfq.ctx.Unique { + selector.Distinct() + } + for _, p := range sabfq.predicates { + p(selector) + } + for _, p := range sabfq.order { + p(selector) + } + if offset := sabfq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := sabfq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// SentinelAppBinaryFileGroupBy is the group-by builder for SentinelAppBinaryFile entities. +type SentinelAppBinaryFileGroupBy struct { + selector + build *SentinelAppBinaryFileQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (sabfgb *SentinelAppBinaryFileGroupBy) Aggregate(fns ...AggregateFunc) *SentinelAppBinaryFileGroupBy { + sabfgb.fns = append(sabfgb.fns, fns...) + return sabfgb +} + +// Scan applies the selector query and scans the result into the given value. +func (sabfgb *SentinelAppBinaryFileGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, sabfgb.build.ctx, ent.OpQueryGroupBy) + if err := sabfgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*SentinelAppBinaryFileQuery, *SentinelAppBinaryFileGroupBy](ctx, sabfgb.build, sabfgb, sabfgb.build.inters, v) +} + +func (sabfgb *SentinelAppBinaryFileGroupBy) sqlScan(ctx context.Context, root *SentinelAppBinaryFileQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(sabfgb.fns)) + for _, fn := range sabfgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*sabfgb.flds)+len(sabfgb.fns)) + for _, f := range *sabfgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*sabfgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := sabfgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// SentinelAppBinaryFileSelect is the builder for selecting fields of SentinelAppBinaryFile entities. +type SentinelAppBinaryFileSelect struct { + *SentinelAppBinaryFileQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (sabfs *SentinelAppBinaryFileSelect) Aggregate(fns ...AggregateFunc) *SentinelAppBinaryFileSelect { + sabfs.fns = append(sabfs.fns, fns...) + return sabfs +} + +// Scan applies the selector query and scans the result into the given value. +func (sabfs *SentinelAppBinaryFileSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, sabfs.ctx, ent.OpQuerySelect) + if err := sabfs.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*SentinelAppBinaryFileQuery, *SentinelAppBinaryFileSelect](ctx, sabfs.SentinelAppBinaryFileQuery, sabfs, sabfs.inters, v) +} + +func (sabfs *SentinelAppBinaryFileSelect) sqlScan(ctx context.Context, root *SentinelAppBinaryFileQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(sabfs.fns)) + for _, fn := range sabfs.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*sabfs.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := sabfs.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/internal/data/internal/ent/sentinelappbinaryfile_update.go b/internal/data/internal/ent/sentinelappbinaryfile_update.go new file mode 100644 index 00000000..889f00a7 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile_update.go @@ -0,0 +1,635 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelAppBinaryFileUpdate is the builder for updating SentinelAppBinaryFile entities. +type SentinelAppBinaryFileUpdate struct { + config + hooks []Hook + mutation *SentinelAppBinaryFileMutation +} + +// Where appends a list predicates to the SentinelAppBinaryFileUpdate builder. +func (sabfu *SentinelAppBinaryFileUpdate) Where(ps ...predicate.SentinelAppBinaryFile) *SentinelAppBinaryFileUpdate { + sabfu.mutation.Where(ps...) + return sabfu +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelInfoID(mi model.InternalID) *SentinelAppBinaryFileUpdate { + sabfu.mutation.ResetSentinelInfoID() + sabfu.mutation.SetSentinelInfoID(mi) + return sabfu +} + +// SetNillableSentinelInfoID sets the "sentinel_info_id" field if the given value is not nil. +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableSentinelInfoID(mi *model.InternalID) *SentinelAppBinaryFileUpdate { + if mi != nil { + sabfu.SetSentinelInfoID(*mi) + } + return sabfu +} + +// AddSentinelInfoID adds mi to the "sentinel_info_id" field. +func (sabfu *SentinelAppBinaryFileUpdate) AddSentinelInfoID(mi model.InternalID) *SentinelAppBinaryFileUpdate { + sabfu.mutation.AddSentinelInfoID(mi) + return sabfu +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelLibraryReportedID(i int64) *SentinelAppBinaryFileUpdate { + sabfu.mutation.ResetSentinelLibraryReportedID() + sabfu.mutation.SetSentinelLibraryReportedID(i) + return sabfu +} + +// SetNillableSentinelLibraryReportedID sets the "sentinel_library_reported_id" field if the given value is not nil. +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableSentinelLibraryReportedID(i *int64) *SentinelAppBinaryFileUpdate { + if i != nil { + sabfu.SetSentinelLibraryReportedID(*i) + } + return sabfu +} + +// AddSentinelLibraryReportedID adds i to the "sentinel_library_reported_id" field. +func (sabfu *SentinelAppBinaryFileUpdate) AddSentinelLibraryReportedID(i int64) *SentinelAppBinaryFileUpdate { + sabfu.mutation.AddSentinelLibraryReportedID(i) + return sabfu +} + +// SetSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelAppBinaryGeneratedID(s string) *SentinelAppBinaryFileUpdate { + sabfu.mutation.SetSentinelAppBinaryGeneratedID(s) + return sabfu +} + +// SetNillableSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field if the given value is not nil. +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableSentinelAppBinaryGeneratedID(s *string) *SentinelAppBinaryFileUpdate { + if s != nil { + sabfu.SetSentinelAppBinaryGeneratedID(*s) + } + return sabfu +} + +// SetName sets the "name" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetName(s string) *SentinelAppBinaryFileUpdate { + sabfu.mutation.SetName(s) + return sabfu +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableName(s *string) *SentinelAppBinaryFileUpdate { + if s != nil { + sabfu.SetName(*s) + } + return sabfu +} + +// SetSizeBytes sets the "size_bytes" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetSizeBytes(i int64) *SentinelAppBinaryFileUpdate { + sabfu.mutation.ResetSizeBytes() + sabfu.mutation.SetSizeBytes(i) + return sabfu +} + +// SetNillableSizeBytes sets the "size_bytes" field if the given value is not nil. +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableSizeBytes(i *int64) *SentinelAppBinaryFileUpdate { + if i != nil { + sabfu.SetSizeBytes(*i) + } + return sabfu +} + +// AddSizeBytes adds i to the "size_bytes" field. +func (sabfu *SentinelAppBinaryFileUpdate) AddSizeBytes(i int64) *SentinelAppBinaryFileUpdate { + sabfu.mutation.AddSizeBytes(i) + return sabfu +} + +// SetSha256 sets the "sha256" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetSha256(b []byte) *SentinelAppBinaryFileUpdate { + sabfu.mutation.SetSha256(b) + return sabfu +} + +// SetServerFilePath sets the "server_file_path" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetServerFilePath(s string) *SentinelAppBinaryFileUpdate { + sabfu.mutation.SetServerFilePath(s) + return sabfu +} + +// SetNillableServerFilePath sets the "server_file_path" field if the given value is not nil. +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableServerFilePath(s *string) *SentinelAppBinaryFileUpdate { + if s != nil { + sabfu.SetServerFilePath(*s) + } + return sabfu +} + +// SetChunksInfo sets the "chunks_info" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetChunksInfo(s string) *SentinelAppBinaryFileUpdate { + sabfu.mutation.SetChunksInfo(s) + return sabfu +} + +// SetNillableChunksInfo sets the "chunks_info" field if the given value is not nil. +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableChunksInfo(s *string) *SentinelAppBinaryFileUpdate { + if s != nil { + sabfu.SetChunksInfo(*s) + } + return sabfu +} + +// ClearChunksInfo clears the value of the "chunks_info" field. +func (sabfu *SentinelAppBinaryFileUpdate) ClearChunksInfo() *SentinelAppBinaryFileUpdate { + sabfu.mutation.ClearChunksInfo() + return sabfu +} + +// SetUpdatedAt sets the "updated_at" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetUpdatedAt(t time.Time) *SentinelAppBinaryFileUpdate { + sabfu.mutation.SetUpdatedAt(t) + return sabfu +} + +// SetCreatedAt sets the "created_at" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetCreatedAt(t time.Time) *SentinelAppBinaryFileUpdate { + sabfu.mutation.SetCreatedAt(t) + return sabfu +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableCreatedAt(t *time.Time) *SentinelAppBinaryFileUpdate { + if t != nil { + sabfu.SetCreatedAt(*t) + } + return sabfu +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetAppBinaryReportSequence(i int64) *SentinelAppBinaryFileUpdate { + sabfu.mutation.ResetAppBinaryReportSequence() + sabfu.mutation.SetAppBinaryReportSequence(i) + return sabfu +} + +// SetNillableAppBinaryReportSequence sets the "app_binary_report_sequence" field if the given value is not nil. +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableAppBinaryReportSequence(i *int64) *SentinelAppBinaryFileUpdate { + if i != nil { + sabfu.SetAppBinaryReportSequence(*i) + } + return sabfu +} + +// AddAppBinaryReportSequence adds i to the "app_binary_report_sequence" field. +func (sabfu *SentinelAppBinaryFileUpdate) AddAppBinaryReportSequence(i int64) *SentinelAppBinaryFileUpdate { + sabfu.mutation.AddAppBinaryReportSequence(i) + return sabfu +} + +// Mutation returns the SentinelAppBinaryFileMutation object of the builder. +func (sabfu *SentinelAppBinaryFileUpdate) Mutation() *SentinelAppBinaryFileMutation { + return sabfu.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (sabfu *SentinelAppBinaryFileUpdate) Save(ctx context.Context) (int, error) { + sabfu.defaults() + return withHooks(ctx, sabfu.sqlSave, sabfu.mutation, sabfu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (sabfu *SentinelAppBinaryFileUpdate) SaveX(ctx context.Context) int { + affected, err := sabfu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (sabfu *SentinelAppBinaryFileUpdate) Exec(ctx context.Context) error { + _, err := sabfu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabfu *SentinelAppBinaryFileUpdate) ExecX(ctx context.Context) { + if err := sabfu.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (sabfu *SentinelAppBinaryFileUpdate) defaults() { + if _, ok := sabfu.mutation.UpdatedAt(); !ok { + v := sentinelappbinaryfile.UpdateDefaultUpdatedAt() + sabfu.mutation.SetUpdatedAt(v) + } +} + +func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := sqlgraph.NewUpdateSpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt)) + if ps := sabfu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := sabfu.mutation.SentinelInfoID(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSentinelInfoID, field.TypeInt64, value) + } + if value, ok := sabfu.mutation.AddedSentinelInfoID(); ok { + _spec.AddField(sentinelappbinaryfile.FieldSentinelInfoID, field.TypeInt64, value) + } + if value, ok := sabfu.mutation.SentinelLibraryReportedID(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSentinelLibraryReportedID, field.TypeInt64, value) + } + if value, ok := sabfu.mutation.AddedSentinelLibraryReportedID(); ok { + _spec.AddField(sentinelappbinaryfile.FieldSentinelLibraryReportedID, field.TypeInt64, value) + } + if value, ok := sabfu.mutation.SentinelAppBinaryGeneratedID(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID, field.TypeString, value) + } + if value, ok := sabfu.mutation.Name(); ok { + _spec.SetField(sentinelappbinaryfile.FieldName, field.TypeString, value) + } + if value, ok := sabfu.mutation.SizeBytes(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSizeBytes, field.TypeInt64, value) + } + if value, ok := sabfu.mutation.AddedSizeBytes(); ok { + _spec.AddField(sentinelappbinaryfile.FieldSizeBytes, field.TypeInt64, value) + } + if value, ok := sabfu.mutation.Sha256(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSha256, field.TypeBytes, value) + } + if value, ok := sabfu.mutation.ServerFilePath(); ok { + _spec.SetField(sentinelappbinaryfile.FieldServerFilePath, field.TypeString, value) + } + if value, ok := sabfu.mutation.ChunksInfo(); ok { + _spec.SetField(sentinelappbinaryfile.FieldChunksInfo, field.TypeString, value) + } + if sabfu.mutation.ChunksInfoCleared() { + _spec.ClearField(sentinelappbinaryfile.FieldChunksInfo, field.TypeString) + } + if value, ok := sabfu.mutation.UpdatedAt(); ok { + _spec.SetField(sentinelappbinaryfile.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := sabfu.mutation.CreatedAt(); ok { + _spec.SetField(sentinelappbinaryfile.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := sabfu.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelappbinaryfile.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + if value, ok := sabfu.mutation.AddedAppBinaryReportSequence(); ok { + _spec.AddField(sentinelappbinaryfile.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + if n, err = sqlgraph.UpdateNodes(ctx, sabfu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{sentinelappbinaryfile.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + sabfu.mutation.done = true + return n, nil +} + +// SentinelAppBinaryFileUpdateOne is the builder for updating a single SentinelAppBinaryFile entity. +type SentinelAppBinaryFileUpdateOne struct { + config + fields []string + hooks []Hook + mutation *SentinelAppBinaryFileMutation +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelInfoID(mi model.InternalID) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.ResetSentinelInfoID() + sabfuo.mutation.SetSentinelInfoID(mi) + return sabfuo +} + +// SetNillableSentinelInfoID sets the "sentinel_info_id" field if the given value is not nil. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableSentinelInfoID(mi *model.InternalID) *SentinelAppBinaryFileUpdateOne { + if mi != nil { + sabfuo.SetSentinelInfoID(*mi) + } + return sabfuo +} + +// AddSentinelInfoID adds mi to the "sentinel_info_id" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) AddSentinelInfoID(mi model.InternalID) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.AddSentinelInfoID(mi) + return sabfuo +} + +// SetSentinelLibraryReportedID sets the "sentinel_library_reported_id" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelLibraryReportedID(i int64) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.ResetSentinelLibraryReportedID() + sabfuo.mutation.SetSentinelLibraryReportedID(i) + return sabfuo +} + +// SetNillableSentinelLibraryReportedID sets the "sentinel_library_reported_id" field if the given value is not nil. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableSentinelLibraryReportedID(i *int64) *SentinelAppBinaryFileUpdateOne { + if i != nil { + sabfuo.SetSentinelLibraryReportedID(*i) + } + return sabfuo +} + +// AddSentinelLibraryReportedID adds i to the "sentinel_library_reported_id" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) AddSentinelLibraryReportedID(i int64) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.AddSentinelLibraryReportedID(i) + return sabfuo +} + +// SetSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelAppBinaryGeneratedID(s string) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.SetSentinelAppBinaryGeneratedID(s) + return sabfuo +} + +// SetNillableSentinelAppBinaryGeneratedID sets the "sentinel_app_binary_generated_id" field if the given value is not nil. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableSentinelAppBinaryGeneratedID(s *string) *SentinelAppBinaryFileUpdateOne { + if s != nil { + sabfuo.SetSentinelAppBinaryGeneratedID(*s) + } + return sabfuo +} + +// SetName sets the "name" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetName(s string) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.SetName(s) + return sabfuo +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableName(s *string) *SentinelAppBinaryFileUpdateOne { + if s != nil { + sabfuo.SetName(*s) + } + return sabfuo +} + +// SetSizeBytes sets the "size_bytes" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSizeBytes(i int64) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.ResetSizeBytes() + sabfuo.mutation.SetSizeBytes(i) + return sabfuo +} + +// SetNillableSizeBytes sets the "size_bytes" field if the given value is not nil. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableSizeBytes(i *int64) *SentinelAppBinaryFileUpdateOne { + if i != nil { + sabfuo.SetSizeBytes(*i) + } + return sabfuo +} + +// AddSizeBytes adds i to the "size_bytes" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) AddSizeBytes(i int64) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.AddSizeBytes(i) + return sabfuo +} + +// SetSha256 sets the "sha256" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSha256(b []byte) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.SetSha256(b) + return sabfuo +} + +// SetServerFilePath sets the "server_file_path" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetServerFilePath(s string) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.SetServerFilePath(s) + return sabfuo +} + +// SetNillableServerFilePath sets the "server_file_path" field if the given value is not nil. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableServerFilePath(s *string) *SentinelAppBinaryFileUpdateOne { + if s != nil { + sabfuo.SetServerFilePath(*s) + } + return sabfuo +} + +// SetChunksInfo sets the "chunks_info" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetChunksInfo(s string) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.SetChunksInfo(s) + return sabfuo +} + +// SetNillableChunksInfo sets the "chunks_info" field if the given value is not nil. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableChunksInfo(s *string) *SentinelAppBinaryFileUpdateOne { + if s != nil { + sabfuo.SetChunksInfo(*s) + } + return sabfuo +} + +// ClearChunksInfo clears the value of the "chunks_info" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) ClearChunksInfo() *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.ClearChunksInfo() + return sabfuo +} + +// SetUpdatedAt sets the "updated_at" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetUpdatedAt(t time.Time) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.SetUpdatedAt(t) + return sabfuo +} + +// SetCreatedAt sets the "created_at" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetCreatedAt(t time.Time) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.SetCreatedAt(t) + return sabfuo +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableCreatedAt(t *time.Time) *SentinelAppBinaryFileUpdateOne { + if t != nil { + sabfuo.SetCreatedAt(*t) + } + return sabfuo +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetAppBinaryReportSequence(i int64) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.ResetAppBinaryReportSequence() + sabfuo.mutation.SetAppBinaryReportSequence(i) + return sabfuo +} + +// SetNillableAppBinaryReportSequence sets the "app_binary_report_sequence" field if the given value is not nil. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableAppBinaryReportSequence(i *int64) *SentinelAppBinaryFileUpdateOne { + if i != nil { + sabfuo.SetAppBinaryReportSequence(*i) + } + return sabfuo +} + +// AddAppBinaryReportSequence adds i to the "app_binary_report_sequence" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) AddAppBinaryReportSequence(i int64) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.AddAppBinaryReportSequence(i) + return sabfuo +} + +// Mutation returns the SentinelAppBinaryFileMutation object of the builder. +func (sabfuo *SentinelAppBinaryFileUpdateOne) Mutation() *SentinelAppBinaryFileMutation { + return sabfuo.mutation +} + +// Where appends a list predicates to the SentinelAppBinaryFileUpdate builder. +func (sabfuo *SentinelAppBinaryFileUpdateOne) Where(ps ...predicate.SentinelAppBinaryFile) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.Where(ps...) + return sabfuo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (sabfuo *SentinelAppBinaryFileUpdateOne) Select(field string, fields ...string) *SentinelAppBinaryFileUpdateOne { + sabfuo.fields = append([]string{field}, fields...) + return sabfuo +} + +// Save executes the query and returns the updated SentinelAppBinaryFile entity. +func (sabfuo *SentinelAppBinaryFileUpdateOne) Save(ctx context.Context) (*SentinelAppBinaryFile, error) { + sabfuo.defaults() + return withHooks(ctx, sabfuo.sqlSave, sabfuo.mutation, sabfuo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SaveX(ctx context.Context) *SentinelAppBinaryFile { + node, err := sabfuo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (sabfuo *SentinelAppBinaryFileUpdateOne) Exec(ctx context.Context) error { + _, err := sabfuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (sabfuo *SentinelAppBinaryFileUpdateOne) ExecX(ctx context.Context) { + if err := sabfuo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (sabfuo *SentinelAppBinaryFileUpdateOne) defaults() { + if _, ok := sabfuo.mutation.UpdatedAt(); !ok { + v := sentinelappbinaryfile.UpdateDefaultUpdatedAt() + sabfuo.mutation.SetUpdatedAt(v) + } +} + +func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_node *SentinelAppBinaryFile, err error) { + _spec := sqlgraph.NewUpdateSpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt)) + id, ok := sabfuo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SentinelAppBinaryFile.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := sabfuo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, sentinelappbinaryfile.FieldID) + for _, f := range fields { + if !sentinelappbinaryfile.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != sentinelappbinaryfile.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := sabfuo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := sabfuo.mutation.SentinelInfoID(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSentinelInfoID, field.TypeInt64, value) + } + if value, ok := sabfuo.mutation.AddedSentinelInfoID(); ok { + _spec.AddField(sentinelappbinaryfile.FieldSentinelInfoID, field.TypeInt64, value) + } + if value, ok := sabfuo.mutation.SentinelLibraryReportedID(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSentinelLibraryReportedID, field.TypeInt64, value) + } + if value, ok := sabfuo.mutation.AddedSentinelLibraryReportedID(); ok { + _spec.AddField(sentinelappbinaryfile.FieldSentinelLibraryReportedID, field.TypeInt64, value) + } + if value, ok := sabfuo.mutation.SentinelAppBinaryGeneratedID(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID, field.TypeString, value) + } + if value, ok := sabfuo.mutation.Name(); ok { + _spec.SetField(sentinelappbinaryfile.FieldName, field.TypeString, value) + } + if value, ok := sabfuo.mutation.SizeBytes(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSizeBytes, field.TypeInt64, value) + } + if value, ok := sabfuo.mutation.AddedSizeBytes(); ok { + _spec.AddField(sentinelappbinaryfile.FieldSizeBytes, field.TypeInt64, value) + } + if value, ok := sabfuo.mutation.Sha256(); ok { + _spec.SetField(sentinelappbinaryfile.FieldSha256, field.TypeBytes, value) + } + if value, ok := sabfuo.mutation.ServerFilePath(); ok { + _spec.SetField(sentinelappbinaryfile.FieldServerFilePath, field.TypeString, value) + } + if value, ok := sabfuo.mutation.ChunksInfo(); ok { + _spec.SetField(sentinelappbinaryfile.FieldChunksInfo, field.TypeString, value) + } + if sabfuo.mutation.ChunksInfoCleared() { + _spec.ClearField(sentinelappbinaryfile.FieldChunksInfo, field.TypeString) + } + if value, ok := sabfuo.mutation.UpdatedAt(); ok { + _spec.SetField(sentinelappbinaryfile.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := sabfuo.mutation.CreatedAt(); ok { + _spec.SetField(sentinelappbinaryfile.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := sabfuo.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelappbinaryfile.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + if value, ok := sabfuo.mutation.AddedAppBinaryReportSequence(); ok { + _spec.AddField(sentinelappbinaryfile.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + _node = &SentinelAppBinaryFile{config: sabfuo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, sabfuo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{sentinelappbinaryfile.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + sabfuo.mutation.done = true + return _node, nil +} diff --git a/internal/data/internal/ent/sentinelinfo.go b/internal/data/internal/ent/sentinelinfo.go new file mode 100644 index 00000000..4c540950 --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo.go @@ -0,0 +1,215 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "encoding/json" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelInfo is the model entity for the SentinelInfo schema. +type SentinelInfo struct { + config `json:"-"` + // ID of the ent. + ID model.InternalID `json:"id,omitempty"` + // URL holds the value of the "url" field. + URL string `json:"url,omitempty"` + // AlternativeUrls holds the value of the "alternative_urls" field. + AlternativeUrls []string `json:"alternative_urls,omitempty"` + // GetTokenPath holds the value of the "get_token_path" field. + GetTokenPath string `json:"get_token_path,omitempty"` + // DownloadFileBasePath holds the value of the "download_file_base_path" field. + DownloadFileBasePath string `json:"download_file_base_path,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // LibraryReportSequence holds the value of the "library_report_sequence" field. + LibraryReportSequence int64 `json:"library_report_sequence,omitempty"` + // AppBinaryReportSequence holds the value of the "app_binary_report_sequence" field. + AppBinaryReportSequence int64 `json:"app_binary_report_sequence,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the SentinelInfoQuery when eager-loading is set. + Edges SentinelInfoEdges `json:"edges"` + selectValues sql.SelectValues +} + +// SentinelInfoEdges holds the relations/edges for other nodes in the graph. +type SentinelInfoEdges struct { + // SentinelLibrary holds the value of the sentinel_library edge. + SentinelLibrary []*SentinelLibrary `json:"sentinel_library,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// SentinelLibraryOrErr returns the SentinelLibrary value or an error if the edge +// was not loaded in eager-loading. +func (e SentinelInfoEdges) SentinelLibraryOrErr() ([]*SentinelLibrary, error) { + if e.loadedTypes[0] { + return e.SentinelLibrary, nil + } + return nil, &NotLoadedError{edge: "sentinel_library"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*SentinelInfo) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case sentinelinfo.FieldAlternativeUrls: + values[i] = new([]byte) + case sentinelinfo.FieldID, sentinelinfo.FieldLibraryReportSequence, sentinelinfo.FieldAppBinaryReportSequence: + values[i] = new(sql.NullInt64) + case sentinelinfo.FieldURL, sentinelinfo.FieldGetTokenPath, sentinelinfo.FieldDownloadFileBasePath: + values[i] = new(sql.NullString) + case sentinelinfo.FieldUpdatedAt, sentinelinfo.FieldCreatedAt: + values[i] = new(sql.NullTime) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the SentinelInfo fields. +func (si *SentinelInfo) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case sentinelinfo.FieldID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value.Valid { + si.ID = model.InternalID(value.Int64) + } + case sentinelinfo.FieldURL: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field url", values[i]) + } else if value.Valid { + si.URL = value.String + } + case sentinelinfo.FieldAlternativeUrls: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field alternative_urls", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &si.AlternativeUrls); err != nil { + return fmt.Errorf("unmarshal field alternative_urls: %w", err) + } + } + case sentinelinfo.FieldGetTokenPath: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field get_token_path", values[i]) + } else if value.Valid { + si.GetTokenPath = value.String + } + case sentinelinfo.FieldDownloadFileBasePath: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field download_file_base_path", values[i]) + } else if value.Valid { + si.DownloadFileBasePath = value.String + } + case sentinelinfo.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + si.UpdatedAt = value.Time + } + case sentinelinfo.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + si.CreatedAt = value.Time + } + case sentinelinfo.FieldLibraryReportSequence: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field library_report_sequence", values[i]) + } else if value.Valid { + si.LibraryReportSequence = value.Int64 + } + case sentinelinfo.FieldAppBinaryReportSequence: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field app_binary_report_sequence", values[i]) + } else if value.Valid { + si.AppBinaryReportSequence = value.Int64 + } + default: + si.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the SentinelInfo. +// This includes values selected through modifiers, order, etc. +func (si *SentinelInfo) Value(name string) (ent.Value, error) { + return si.selectValues.Get(name) +} + +// QuerySentinelLibrary queries the "sentinel_library" edge of the SentinelInfo entity. +func (si *SentinelInfo) QuerySentinelLibrary() *SentinelLibraryQuery { + return NewSentinelInfoClient(si.config).QuerySentinelLibrary(si) +} + +// Update returns a builder for updating this SentinelInfo. +// Note that you need to call SentinelInfo.Unwrap() before calling this method if this SentinelInfo +// was returned from a transaction, and the transaction was committed or rolled back. +func (si *SentinelInfo) Update() *SentinelInfoUpdateOne { + return NewSentinelInfoClient(si.config).UpdateOne(si) +} + +// Unwrap unwraps the SentinelInfo entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (si *SentinelInfo) Unwrap() *SentinelInfo { + _tx, ok := si.config.driver.(*txDriver) + if !ok { + panic("ent: SentinelInfo is not a transactional entity") + } + si.config.driver = _tx.drv + return si +} + +// String implements the fmt.Stringer. +func (si *SentinelInfo) String() string { + var builder strings.Builder + builder.WriteString("SentinelInfo(") + builder.WriteString(fmt.Sprintf("id=%v, ", si.ID)) + builder.WriteString("url=") + builder.WriteString(si.URL) + builder.WriteString(", ") + builder.WriteString("alternative_urls=") + builder.WriteString(fmt.Sprintf("%v", si.AlternativeUrls)) + builder.WriteString(", ") + builder.WriteString("get_token_path=") + builder.WriteString(si.GetTokenPath) + builder.WriteString(", ") + builder.WriteString("download_file_base_path=") + builder.WriteString(si.DownloadFileBasePath) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(si.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(si.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("library_report_sequence=") + builder.WriteString(fmt.Sprintf("%v", si.LibraryReportSequence)) + builder.WriteString(", ") + builder.WriteString("app_binary_report_sequence=") + builder.WriteString(fmt.Sprintf("%v", si.AppBinaryReportSequence)) + builder.WriteByte(')') + return builder.String() +} + +// SentinelInfos is a parsable slice of SentinelInfo. +type SentinelInfos []*SentinelInfo diff --git a/internal/data/internal/ent/sentinelinfo/sentinelinfo.go b/internal/data/internal/ent/sentinelinfo/sentinelinfo.go new file mode 100644 index 00000000..275dfb9d --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo/sentinelinfo.go @@ -0,0 +1,140 @@ +// Code generated by ent, DO NOT EDIT. + +package sentinelinfo + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +const ( + // Label holds the string label denoting the sentinelinfo type in the database. + Label = "sentinel_info" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldURL holds the string denoting the url field in the database. + FieldURL = "url" + // FieldAlternativeUrls holds the string denoting the alternative_urls field in the database. + FieldAlternativeUrls = "alternative_urls" + // FieldGetTokenPath holds the string denoting the get_token_path field in the database. + FieldGetTokenPath = "get_token_path" + // FieldDownloadFileBasePath holds the string denoting the download_file_base_path field in the database. + FieldDownloadFileBasePath = "download_file_base_path" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldLibraryReportSequence holds the string denoting the library_report_sequence field in the database. + FieldLibraryReportSequence = "library_report_sequence" + // FieldAppBinaryReportSequence holds the string denoting the app_binary_report_sequence field in the database. + FieldAppBinaryReportSequence = "app_binary_report_sequence" + // EdgeSentinelLibrary holds the string denoting the sentinel_library edge name in mutations. + EdgeSentinelLibrary = "sentinel_library" + // Table holds the table name of the sentinelinfo in the database. + Table = "sentinel_infos" + // SentinelLibraryTable is the table that holds the sentinel_library relation/edge. + SentinelLibraryTable = "sentinel_libraries" + // SentinelLibraryInverseTable is the table name for the SentinelLibrary entity. + // It exists in this package in order to avoid circular dependency with the "sentinellibrary" package. + SentinelLibraryInverseTable = "sentinel_libraries" + // SentinelLibraryColumn is the table column denoting the sentinel_library relation/edge. + SentinelLibraryColumn = "sentinel_info_id" +) + +// Columns holds all SQL columns for sentinelinfo fields. +var Columns = []string{ + FieldID, + FieldURL, + FieldAlternativeUrls, + FieldGetTokenPath, + FieldDownloadFileBasePath, + FieldUpdatedAt, + FieldCreatedAt, + FieldLibraryReportSequence, + FieldAppBinaryReportSequence, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time +) + +// OrderOption defines the ordering options for the SentinelInfo queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByURL orders the results by the url field. +func ByURL(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldURL, opts...).ToFunc() +} + +// ByGetTokenPath orders the results by the get_token_path field. +func ByGetTokenPath(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldGetTokenPath, opts...).ToFunc() +} + +// ByDownloadFileBasePath orders the results by the download_file_base_path field. +func ByDownloadFileBasePath(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDownloadFileBasePath, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByLibraryReportSequence orders the results by the library_report_sequence field. +func ByLibraryReportSequence(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLibraryReportSequence, opts...).ToFunc() +} + +// ByAppBinaryReportSequence orders the results by the app_binary_report_sequence field. +func ByAppBinaryReportSequence(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAppBinaryReportSequence, opts...).ToFunc() +} + +// BySentinelLibraryCount orders the results by sentinel_library count. +func BySentinelLibraryCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newSentinelLibraryStep(), opts...) + } +} + +// BySentinelLibrary orders the results by sentinel_library terms. +func BySentinelLibrary(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSentinelLibraryStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newSentinelLibraryStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SentinelLibraryInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, SentinelLibraryTable, SentinelLibraryColumn), + ) +} diff --git a/internal/data/internal/ent/sentinelinfo/where.go b/internal/data/internal/ent/sentinelinfo/where.go new file mode 100644 index 00000000..6d20c42b --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo/where.go @@ -0,0 +1,505 @@ +// Code generated by ent, DO NOT EDIT. + +package sentinelinfo + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/model" +) + +// ID filters vertices based on their ID field. +func ID(id model.InternalID) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id model.InternalID) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id model.InternalID) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...model.InternalID) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...model.InternalID) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id model.InternalID) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id model.InternalID) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id model.InternalID) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id model.InternalID) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLTE(FieldID, id)) +} + +// URL applies equality check predicate on the "url" field. It's identical to URLEQ. +func URL(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldURL, v)) +} + +// GetTokenPath applies equality check predicate on the "get_token_path" field. It's identical to GetTokenPathEQ. +func GetTokenPath(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldGetTokenPath, v)) +} + +// DownloadFileBasePath applies equality check predicate on the "download_file_base_path" field. It's identical to DownloadFileBasePathEQ. +func DownloadFileBasePath(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldDownloadFileBasePath, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldCreatedAt, v)) +} + +// LibraryReportSequence applies equality check predicate on the "library_report_sequence" field. It's identical to LibraryReportSequenceEQ. +func LibraryReportSequence(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldLibraryReportSequence, v)) +} + +// AppBinaryReportSequence applies equality check predicate on the "app_binary_report_sequence" field. It's identical to AppBinaryReportSequenceEQ. +func AppBinaryReportSequence(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldAppBinaryReportSequence, v)) +} + +// URLEQ applies the EQ predicate on the "url" field. +func URLEQ(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldURL, v)) +} + +// URLNEQ applies the NEQ predicate on the "url" field. +func URLNEQ(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNEQ(FieldURL, v)) +} + +// URLIn applies the In predicate on the "url" field. +func URLIn(vs ...string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldIn(FieldURL, vs...)) +} + +// URLNotIn applies the NotIn predicate on the "url" field. +func URLNotIn(vs ...string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNotIn(FieldURL, vs...)) +} + +// URLGT applies the GT predicate on the "url" field. +func URLGT(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGT(FieldURL, v)) +} + +// URLGTE applies the GTE predicate on the "url" field. +func URLGTE(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGTE(FieldURL, v)) +} + +// URLLT applies the LT predicate on the "url" field. +func URLLT(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLT(FieldURL, v)) +} + +// URLLTE applies the LTE predicate on the "url" field. +func URLLTE(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLTE(FieldURL, v)) +} + +// URLContains applies the Contains predicate on the "url" field. +func URLContains(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldContains(FieldURL, v)) +} + +// URLHasPrefix applies the HasPrefix predicate on the "url" field. +func URLHasPrefix(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldHasPrefix(FieldURL, v)) +} + +// URLHasSuffix applies the HasSuffix predicate on the "url" field. +func URLHasSuffix(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldHasSuffix(FieldURL, v)) +} + +// URLEqualFold applies the EqualFold predicate on the "url" field. +func URLEqualFold(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEqualFold(FieldURL, v)) +} + +// URLContainsFold applies the ContainsFold predicate on the "url" field. +func URLContainsFold(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldContainsFold(FieldURL, v)) +} + +// AlternativeUrlsIsNil applies the IsNil predicate on the "alternative_urls" field. +func AlternativeUrlsIsNil() predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldIsNull(FieldAlternativeUrls)) +} + +// AlternativeUrlsNotNil applies the NotNil predicate on the "alternative_urls" field. +func AlternativeUrlsNotNil() predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNotNull(FieldAlternativeUrls)) +} + +// GetTokenPathEQ applies the EQ predicate on the "get_token_path" field. +func GetTokenPathEQ(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldGetTokenPath, v)) +} + +// GetTokenPathNEQ applies the NEQ predicate on the "get_token_path" field. +func GetTokenPathNEQ(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNEQ(FieldGetTokenPath, v)) +} + +// GetTokenPathIn applies the In predicate on the "get_token_path" field. +func GetTokenPathIn(vs ...string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldIn(FieldGetTokenPath, vs...)) +} + +// GetTokenPathNotIn applies the NotIn predicate on the "get_token_path" field. +func GetTokenPathNotIn(vs ...string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNotIn(FieldGetTokenPath, vs...)) +} + +// GetTokenPathGT applies the GT predicate on the "get_token_path" field. +func GetTokenPathGT(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGT(FieldGetTokenPath, v)) +} + +// GetTokenPathGTE applies the GTE predicate on the "get_token_path" field. +func GetTokenPathGTE(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGTE(FieldGetTokenPath, v)) +} + +// GetTokenPathLT applies the LT predicate on the "get_token_path" field. +func GetTokenPathLT(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLT(FieldGetTokenPath, v)) +} + +// GetTokenPathLTE applies the LTE predicate on the "get_token_path" field. +func GetTokenPathLTE(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLTE(FieldGetTokenPath, v)) +} + +// GetTokenPathContains applies the Contains predicate on the "get_token_path" field. +func GetTokenPathContains(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldContains(FieldGetTokenPath, v)) +} + +// GetTokenPathHasPrefix applies the HasPrefix predicate on the "get_token_path" field. +func GetTokenPathHasPrefix(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldHasPrefix(FieldGetTokenPath, v)) +} + +// GetTokenPathHasSuffix applies the HasSuffix predicate on the "get_token_path" field. +func GetTokenPathHasSuffix(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldHasSuffix(FieldGetTokenPath, v)) +} + +// GetTokenPathIsNil applies the IsNil predicate on the "get_token_path" field. +func GetTokenPathIsNil() predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldIsNull(FieldGetTokenPath)) +} + +// GetTokenPathNotNil applies the NotNil predicate on the "get_token_path" field. +func GetTokenPathNotNil() predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNotNull(FieldGetTokenPath)) +} + +// GetTokenPathEqualFold applies the EqualFold predicate on the "get_token_path" field. +func GetTokenPathEqualFold(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEqualFold(FieldGetTokenPath, v)) +} + +// GetTokenPathContainsFold applies the ContainsFold predicate on the "get_token_path" field. +func GetTokenPathContainsFold(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldContainsFold(FieldGetTokenPath, v)) +} + +// DownloadFileBasePathEQ applies the EQ predicate on the "download_file_base_path" field. +func DownloadFileBasePathEQ(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldDownloadFileBasePath, v)) +} + +// DownloadFileBasePathNEQ applies the NEQ predicate on the "download_file_base_path" field. +func DownloadFileBasePathNEQ(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNEQ(FieldDownloadFileBasePath, v)) +} + +// DownloadFileBasePathIn applies the In predicate on the "download_file_base_path" field. +func DownloadFileBasePathIn(vs ...string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldIn(FieldDownloadFileBasePath, vs...)) +} + +// DownloadFileBasePathNotIn applies the NotIn predicate on the "download_file_base_path" field. +func DownloadFileBasePathNotIn(vs ...string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNotIn(FieldDownloadFileBasePath, vs...)) +} + +// DownloadFileBasePathGT applies the GT predicate on the "download_file_base_path" field. +func DownloadFileBasePathGT(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGT(FieldDownloadFileBasePath, v)) +} + +// DownloadFileBasePathGTE applies the GTE predicate on the "download_file_base_path" field. +func DownloadFileBasePathGTE(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGTE(FieldDownloadFileBasePath, v)) +} + +// DownloadFileBasePathLT applies the LT predicate on the "download_file_base_path" field. +func DownloadFileBasePathLT(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLT(FieldDownloadFileBasePath, v)) +} + +// DownloadFileBasePathLTE applies the LTE predicate on the "download_file_base_path" field. +func DownloadFileBasePathLTE(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLTE(FieldDownloadFileBasePath, v)) +} + +// DownloadFileBasePathContains applies the Contains predicate on the "download_file_base_path" field. +func DownloadFileBasePathContains(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldContains(FieldDownloadFileBasePath, v)) +} + +// DownloadFileBasePathHasPrefix applies the HasPrefix predicate on the "download_file_base_path" field. +func DownloadFileBasePathHasPrefix(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldHasPrefix(FieldDownloadFileBasePath, v)) +} + +// DownloadFileBasePathHasSuffix applies the HasSuffix predicate on the "download_file_base_path" field. +func DownloadFileBasePathHasSuffix(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldHasSuffix(FieldDownloadFileBasePath, v)) +} + +// DownloadFileBasePathEqualFold applies the EqualFold predicate on the "download_file_base_path" field. +func DownloadFileBasePathEqualFold(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEqualFold(FieldDownloadFileBasePath, v)) +} + +// DownloadFileBasePathContainsFold applies the ContainsFold predicate on the "download_file_base_path" field. +func DownloadFileBasePathContainsFold(v string) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldContainsFold(FieldDownloadFileBasePath, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLTE(FieldCreatedAt, v)) +} + +// LibraryReportSequenceEQ applies the EQ predicate on the "library_report_sequence" field. +func LibraryReportSequenceEQ(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldLibraryReportSequence, v)) +} + +// LibraryReportSequenceNEQ applies the NEQ predicate on the "library_report_sequence" field. +func LibraryReportSequenceNEQ(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNEQ(FieldLibraryReportSequence, v)) +} + +// LibraryReportSequenceIn applies the In predicate on the "library_report_sequence" field. +func LibraryReportSequenceIn(vs ...int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldIn(FieldLibraryReportSequence, vs...)) +} + +// LibraryReportSequenceNotIn applies the NotIn predicate on the "library_report_sequence" field. +func LibraryReportSequenceNotIn(vs ...int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNotIn(FieldLibraryReportSequence, vs...)) +} + +// LibraryReportSequenceGT applies the GT predicate on the "library_report_sequence" field. +func LibraryReportSequenceGT(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGT(FieldLibraryReportSequence, v)) +} + +// LibraryReportSequenceGTE applies the GTE predicate on the "library_report_sequence" field. +func LibraryReportSequenceGTE(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGTE(FieldLibraryReportSequence, v)) +} + +// LibraryReportSequenceLT applies the LT predicate on the "library_report_sequence" field. +func LibraryReportSequenceLT(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLT(FieldLibraryReportSequence, v)) +} + +// LibraryReportSequenceLTE applies the LTE predicate on the "library_report_sequence" field. +func LibraryReportSequenceLTE(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLTE(FieldLibraryReportSequence, v)) +} + +// AppBinaryReportSequenceEQ applies the EQ predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceEQ(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceNEQ applies the NEQ predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceNEQ(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNEQ(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceIn applies the In predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceIn(vs ...int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldIn(FieldAppBinaryReportSequence, vs...)) +} + +// AppBinaryReportSequenceNotIn applies the NotIn predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceNotIn(vs ...int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNotIn(FieldAppBinaryReportSequence, vs...)) +} + +// AppBinaryReportSequenceGT applies the GT predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceGT(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGT(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceGTE applies the GTE predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceGTE(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGTE(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceLT applies the LT predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceLT(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLT(FieldAppBinaryReportSequence, v)) +} + +// AppBinaryReportSequenceLTE applies the LTE predicate on the "app_binary_report_sequence" field. +func AppBinaryReportSequenceLTE(v int64) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLTE(FieldAppBinaryReportSequence, v)) +} + +// HasSentinelLibrary applies the HasEdge predicate on the "sentinel_library" edge. +func HasSentinelLibrary() predicate.SentinelInfo { + return predicate.SentinelInfo(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, SentinelLibraryTable, SentinelLibraryColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSentinelLibraryWith applies the HasEdge predicate on the "sentinel_library" edge with a given conditions (other predicates). +func HasSentinelLibraryWith(preds ...predicate.SentinelLibrary) predicate.SentinelInfo { + return predicate.SentinelInfo(func(s *sql.Selector) { + step := newSentinelLibraryStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.SentinelInfo) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.SentinelInfo) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.SentinelInfo) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.NotPredicates(p)) +} diff --git a/internal/data/internal/ent/sentinelinfo_create.go b/internal/data/internal/ent/sentinelinfo_create.go new file mode 100644 index 00000000..3ca77830 --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo_create.go @@ -0,0 +1,1001 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelInfoCreate is the builder for creating a SentinelInfo entity. +type SentinelInfoCreate struct { + config + mutation *SentinelInfoMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetURL sets the "url" field. +func (sic *SentinelInfoCreate) SetURL(s string) *SentinelInfoCreate { + sic.mutation.SetURL(s) + return sic +} + +// SetAlternativeUrls sets the "alternative_urls" field. +func (sic *SentinelInfoCreate) SetAlternativeUrls(s []string) *SentinelInfoCreate { + sic.mutation.SetAlternativeUrls(s) + return sic +} + +// SetGetTokenPath sets the "get_token_path" field. +func (sic *SentinelInfoCreate) SetGetTokenPath(s string) *SentinelInfoCreate { + sic.mutation.SetGetTokenPath(s) + return sic +} + +// SetNillableGetTokenPath sets the "get_token_path" field if the given value is not nil. +func (sic *SentinelInfoCreate) SetNillableGetTokenPath(s *string) *SentinelInfoCreate { + if s != nil { + sic.SetGetTokenPath(*s) + } + return sic +} + +// SetDownloadFileBasePath sets the "download_file_base_path" field. +func (sic *SentinelInfoCreate) SetDownloadFileBasePath(s string) *SentinelInfoCreate { + sic.mutation.SetDownloadFileBasePath(s) + return sic +} + +// SetUpdatedAt sets the "updated_at" field. +func (sic *SentinelInfoCreate) SetUpdatedAt(t time.Time) *SentinelInfoCreate { + sic.mutation.SetUpdatedAt(t) + return sic +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (sic *SentinelInfoCreate) SetNillableUpdatedAt(t *time.Time) *SentinelInfoCreate { + if t != nil { + sic.SetUpdatedAt(*t) + } + return sic +} + +// SetCreatedAt sets the "created_at" field. +func (sic *SentinelInfoCreate) SetCreatedAt(t time.Time) *SentinelInfoCreate { + sic.mutation.SetCreatedAt(t) + return sic +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (sic *SentinelInfoCreate) SetNillableCreatedAt(t *time.Time) *SentinelInfoCreate { + if t != nil { + sic.SetCreatedAt(*t) + } + return sic +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (sic *SentinelInfoCreate) SetLibraryReportSequence(i int64) *SentinelInfoCreate { + sic.mutation.SetLibraryReportSequence(i) + return sic +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (sic *SentinelInfoCreate) SetAppBinaryReportSequence(i int64) *SentinelInfoCreate { + sic.mutation.SetAppBinaryReportSequence(i) + return sic +} + +// SetID sets the "id" field. +func (sic *SentinelInfoCreate) SetID(mi model.InternalID) *SentinelInfoCreate { + sic.mutation.SetID(mi) + return sic +} + +// AddSentinelLibraryIDs adds the "sentinel_library" edge to the SentinelLibrary entity by IDs. +func (sic *SentinelInfoCreate) AddSentinelLibraryIDs(ids ...int) *SentinelInfoCreate { + sic.mutation.AddSentinelLibraryIDs(ids...) + return sic +} + +// AddSentinelLibrary adds the "sentinel_library" edges to the SentinelLibrary entity. +func (sic *SentinelInfoCreate) AddSentinelLibrary(s ...*SentinelLibrary) *SentinelInfoCreate { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return sic.AddSentinelLibraryIDs(ids...) +} + +// Mutation returns the SentinelInfoMutation object of the builder. +func (sic *SentinelInfoCreate) Mutation() *SentinelInfoMutation { + return sic.mutation +} + +// Save creates the SentinelInfo in the database. +func (sic *SentinelInfoCreate) Save(ctx context.Context) (*SentinelInfo, error) { + sic.defaults() + return withHooks(ctx, sic.sqlSave, sic.mutation, sic.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (sic *SentinelInfoCreate) SaveX(ctx context.Context) *SentinelInfo { + v, err := sic.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (sic *SentinelInfoCreate) Exec(ctx context.Context) error { + _, err := sic.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (sic *SentinelInfoCreate) ExecX(ctx context.Context) { + if err := sic.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (sic *SentinelInfoCreate) defaults() { + if _, ok := sic.mutation.UpdatedAt(); !ok { + v := sentinelinfo.DefaultUpdatedAt() + sic.mutation.SetUpdatedAt(v) + } + if _, ok := sic.mutation.CreatedAt(); !ok { + v := sentinelinfo.DefaultCreatedAt() + sic.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (sic *SentinelInfoCreate) check() error { + if _, ok := sic.mutation.URL(); !ok { + return &ValidationError{Name: "url", err: errors.New(`ent: missing required field "SentinelInfo.url"`)} + } + if _, ok := sic.mutation.DownloadFileBasePath(); !ok { + return &ValidationError{Name: "download_file_base_path", err: errors.New(`ent: missing required field "SentinelInfo.download_file_base_path"`)} + } + if _, ok := sic.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SentinelInfo.updated_at"`)} + } + if _, ok := sic.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SentinelInfo.created_at"`)} + } + if _, ok := sic.mutation.LibraryReportSequence(); !ok { + return &ValidationError{Name: "library_report_sequence", err: errors.New(`ent: missing required field "SentinelInfo.library_report_sequence"`)} + } + if _, ok := sic.mutation.AppBinaryReportSequence(); !ok { + return &ValidationError{Name: "app_binary_report_sequence", err: errors.New(`ent: missing required field "SentinelInfo.app_binary_report_sequence"`)} + } + return nil +} + +func (sic *SentinelInfoCreate) sqlSave(ctx context.Context) (*SentinelInfo, error) { + if err := sic.check(); err != nil { + return nil, err + } + _node, _spec := sic.createSpec() + if err := sqlgraph.CreateNode(ctx, sic.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = model.InternalID(id) + } + sic.mutation.id = &_node.ID + sic.mutation.done = true + return _node, nil +} + +func (sic *SentinelInfoCreate) createSpec() (*SentinelInfo, *sqlgraph.CreateSpec) { + var ( + _node = &SentinelInfo{config: sic.config} + _spec = sqlgraph.NewCreateSpec(sentinelinfo.Table, sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64)) + ) + _spec.OnConflict = sic.conflict + if id, ok := sic.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := sic.mutation.URL(); ok { + _spec.SetField(sentinelinfo.FieldURL, field.TypeString, value) + _node.URL = value + } + if value, ok := sic.mutation.AlternativeUrls(); ok { + _spec.SetField(sentinelinfo.FieldAlternativeUrls, field.TypeJSON, value) + _node.AlternativeUrls = value + } + if value, ok := sic.mutation.GetTokenPath(); ok { + _spec.SetField(sentinelinfo.FieldGetTokenPath, field.TypeString, value) + _node.GetTokenPath = value + } + if value, ok := sic.mutation.DownloadFileBasePath(); ok { + _spec.SetField(sentinelinfo.FieldDownloadFileBasePath, field.TypeString, value) + _node.DownloadFileBasePath = value + } + if value, ok := sic.mutation.UpdatedAt(); ok { + _spec.SetField(sentinelinfo.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := sic.mutation.CreatedAt(); ok { + _spec.SetField(sentinelinfo.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := sic.mutation.LibraryReportSequence(); ok { + _spec.SetField(sentinelinfo.FieldLibraryReportSequence, field.TypeInt64, value) + _node.LibraryReportSequence = value + } + if value, ok := sic.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelinfo.FieldAppBinaryReportSequence, field.TypeInt64, value) + _node.AppBinaryReportSequence = value + } + if nodes := sic.mutation.SentinelLibraryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelinfo.SentinelLibraryTable, + Columns: []string{sentinelinfo.SentinelLibraryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.SentinelInfo.Create(). +// SetURL(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.SentinelInfoUpsert) { +// SetURL(v+v). +// }). +// Exec(ctx) +func (sic *SentinelInfoCreate) OnConflict(opts ...sql.ConflictOption) *SentinelInfoUpsertOne { + sic.conflict = opts + return &SentinelInfoUpsertOne{ + create: sic, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.SentinelInfo.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (sic *SentinelInfoCreate) OnConflictColumns(columns ...string) *SentinelInfoUpsertOne { + sic.conflict = append(sic.conflict, sql.ConflictColumns(columns...)) + return &SentinelInfoUpsertOne{ + create: sic, + } +} + +type ( + // SentinelInfoUpsertOne is the builder for "upsert"-ing + // one SentinelInfo node. + SentinelInfoUpsertOne struct { + create *SentinelInfoCreate + } + + // SentinelInfoUpsert is the "OnConflict" setter. + SentinelInfoUpsert struct { + *sql.UpdateSet + } +) + +// SetURL sets the "url" field. +func (u *SentinelInfoUpsert) SetURL(v string) *SentinelInfoUpsert { + u.Set(sentinelinfo.FieldURL, v) + return u +} + +// UpdateURL sets the "url" field to the value that was provided on create. +func (u *SentinelInfoUpsert) UpdateURL() *SentinelInfoUpsert { + u.SetExcluded(sentinelinfo.FieldURL) + return u +} + +// SetAlternativeUrls sets the "alternative_urls" field. +func (u *SentinelInfoUpsert) SetAlternativeUrls(v []string) *SentinelInfoUpsert { + u.Set(sentinelinfo.FieldAlternativeUrls, v) + return u +} + +// UpdateAlternativeUrls sets the "alternative_urls" field to the value that was provided on create. +func (u *SentinelInfoUpsert) UpdateAlternativeUrls() *SentinelInfoUpsert { + u.SetExcluded(sentinelinfo.FieldAlternativeUrls) + return u +} + +// ClearAlternativeUrls clears the value of the "alternative_urls" field. +func (u *SentinelInfoUpsert) ClearAlternativeUrls() *SentinelInfoUpsert { + u.SetNull(sentinelinfo.FieldAlternativeUrls) + return u +} + +// SetGetTokenPath sets the "get_token_path" field. +func (u *SentinelInfoUpsert) SetGetTokenPath(v string) *SentinelInfoUpsert { + u.Set(sentinelinfo.FieldGetTokenPath, v) + return u +} + +// UpdateGetTokenPath sets the "get_token_path" field to the value that was provided on create. +func (u *SentinelInfoUpsert) UpdateGetTokenPath() *SentinelInfoUpsert { + u.SetExcluded(sentinelinfo.FieldGetTokenPath) + return u +} + +// ClearGetTokenPath clears the value of the "get_token_path" field. +func (u *SentinelInfoUpsert) ClearGetTokenPath() *SentinelInfoUpsert { + u.SetNull(sentinelinfo.FieldGetTokenPath) + return u +} + +// SetDownloadFileBasePath sets the "download_file_base_path" field. +func (u *SentinelInfoUpsert) SetDownloadFileBasePath(v string) *SentinelInfoUpsert { + u.Set(sentinelinfo.FieldDownloadFileBasePath, v) + return u +} + +// UpdateDownloadFileBasePath sets the "download_file_base_path" field to the value that was provided on create. +func (u *SentinelInfoUpsert) UpdateDownloadFileBasePath() *SentinelInfoUpsert { + u.SetExcluded(sentinelinfo.FieldDownloadFileBasePath) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelInfoUpsert) SetUpdatedAt(v time.Time) *SentinelInfoUpsert { + u.Set(sentinelinfo.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelInfoUpsert) UpdateUpdatedAt() *SentinelInfoUpsert { + u.SetExcluded(sentinelinfo.FieldUpdatedAt) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelInfoUpsert) SetCreatedAt(v time.Time) *SentinelInfoUpsert { + u.Set(sentinelinfo.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelInfoUpsert) UpdateCreatedAt() *SentinelInfoUpsert { + u.SetExcluded(sentinelinfo.FieldCreatedAt) + return u +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (u *SentinelInfoUpsert) SetLibraryReportSequence(v int64) *SentinelInfoUpsert { + u.Set(sentinelinfo.FieldLibraryReportSequence, v) + return u +} + +// UpdateLibraryReportSequence sets the "library_report_sequence" field to the value that was provided on create. +func (u *SentinelInfoUpsert) UpdateLibraryReportSequence() *SentinelInfoUpsert { + u.SetExcluded(sentinelinfo.FieldLibraryReportSequence) + return u +} + +// AddLibraryReportSequence adds v to the "library_report_sequence" field. +func (u *SentinelInfoUpsert) AddLibraryReportSequence(v int64) *SentinelInfoUpsert { + u.Add(sentinelinfo.FieldLibraryReportSequence, v) + return u +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelInfoUpsert) SetAppBinaryReportSequence(v int64) *SentinelInfoUpsert { + u.Set(sentinelinfo.FieldAppBinaryReportSequence, v) + return u +} + +// UpdateAppBinaryReportSequence sets the "app_binary_report_sequence" field to the value that was provided on create. +func (u *SentinelInfoUpsert) UpdateAppBinaryReportSequence() *SentinelInfoUpsert { + u.SetExcluded(sentinelinfo.FieldAppBinaryReportSequence) + return u +} + +// AddAppBinaryReportSequence adds v to the "app_binary_report_sequence" field. +func (u *SentinelInfoUpsert) AddAppBinaryReportSequence(v int64) *SentinelInfoUpsert { + u.Add(sentinelinfo.FieldAppBinaryReportSequence, v) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. +// Using this option is equivalent to using: +// +// client.SentinelInfo.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(sentinelinfo.FieldID) +// }), +// ). +// Exec(ctx) +func (u *SentinelInfoUpsertOne) UpdateNewValues() *SentinelInfoUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + if _, exists := u.create.mutation.ID(); exists { + s.SetIgnore(sentinelinfo.FieldID) + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.SentinelInfo.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SentinelInfoUpsertOne) Ignore() *SentinelInfoUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *SentinelInfoUpsertOne) DoNothing() *SentinelInfoUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SentinelInfoCreate.OnConflict +// documentation for more info. +func (u *SentinelInfoUpsertOne) Update(set func(*SentinelInfoUpsert)) *SentinelInfoUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SentinelInfoUpsert{UpdateSet: update}) + })) + return u +} + +// SetURL sets the "url" field. +func (u *SentinelInfoUpsertOne) SetURL(v string) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetURL(v) + }) +} + +// UpdateURL sets the "url" field to the value that was provided on create. +func (u *SentinelInfoUpsertOne) UpdateURL() *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateURL() + }) +} + +// SetAlternativeUrls sets the "alternative_urls" field. +func (u *SentinelInfoUpsertOne) SetAlternativeUrls(v []string) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetAlternativeUrls(v) + }) +} + +// UpdateAlternativeUrls sets the "alternative_urls" field to the value that was provided on create. +func (u *SentinelInfoUpsertOne) UpdateAlternativeUrls() *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateAlternativeUrls() + }) +} + +// ClearAlternativeUrls clears the value of the "alternative_urls" field. +func (u *SentinelInfoUpsertOne) ClearAlternativeUrls() *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.ClearAlternativeUrls() + }) +} + +// SetGetTokenPath sets the "get_token_path" field. +func (u *SentinelInfoUpsertOne) SetGetTokenPath(v string) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetGetTokenPath(v) + }) +} + +// UpdateGetTokenPath sets the "get_token_path" field to the value that was provided on create. +func (u *SentinelInfoUpsertOne) UpdateGetTokenPath() *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateGetTokenPath() + }) +} + +// ClearGetTokenPath clears the value of the "get_token_path" field. +func (u *SentinelInfoUpsertOne) ClearGetTokenPath() *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.ClearGetTokenPath() + }) +} + +// SetDownloadFileBasePath sets the "download_file_base_path" field. +func (u *SentinelInfoUpsertOne) SetDownloadFileBasePath(v string) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetDownloadFileBasePath(v) + }) +} + +// UpdateDownloadFileBasePath sets the "download_file_base_path" field to the value that was provided on create. +func (u *SentinelInfoUpsertOne) UpdateDownloadFileBasePath() *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateDownloadFileBasePath() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelInfoUpsertOne) SetUpdatedAt(v time.Time) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelInfoUpsertOne) UpdateUpdatedAt() *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelInfoUpsertOne) SetCreatedAt(v time.Time) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelInfoUpsertOne) UpdateCreatedAt() *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (u *SentinelInfoUpsertOne) SetLibraryReportSequence(v int64) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetLibraryReportSequence(v) + }) +} + +// AddLibraryReportSequence adds v to the "library_report_sequence" field. +func (u *SentinelInfoUpsertOne) AddLibraryReportSequence(v int64) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.AddLibraryReportSequence(v) + }) +} + +// UpdateLibraryReportSequence sets the "library_report_sequence" field to the value that was provided on create. +func (u *SentinelInfoUpsertOne) UpdateLibraryReportSequence() *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateLibraryReportSequence() + }) +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelInfoUpsertOne) SetAppBinaryReportSequence(v int64) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetAppBinaryReportSequence(v) + }) +} + +// AddAppBinaryReportSequence adds v to the "app_binary_report_sequence" field. +func (u *SentinelInfoUpsertOne) AddAppBinaryReportSequence(v int64) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.AddAppBinaryReportSequence(v) + }) +} + +// UpdateAppBinaryReportSequence sets the "app_binary_report_sequence" field to the value that was provided on create. +func (u *SentinelInfoUpsertOne) UpdateAppBinaryReportSequence() *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateAppBinaryReportSequence() + }) +} + +// Exec executes the query. +func (u *SentinelInfoUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for SentinelInfoCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SentinelInfoUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *SentinelInfoUpsertOne) ID(ctx context.Context) (id model.InternalID, err error) { + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *SentinelInfoUpsertOne) IDX(ctx context.Context) model.InternalID { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// SentinelInfoCreateBulk is the builder for creating many SentinelInfo entities in bulk. +type SentinelInfoCreateBulk struct { + config + err error + builders []*SentinelInfoCreate + conflict []sql.ConflictOption +} + +// Save creates the SentinelInfo entities in the database. +func (sicb *SentinelInfoCreateBulk) Save(ctx context.Context) ([]*SentinelInfo, error) { + if sicb.err != nil { + return nil, sicb.err + } + specs := make([]*sqlgraph.CreateSpec, len(sicb.builders)) + nodes := make([]*SentinelInfo, len(sicb.builders)) + mutators := make([]Mutator, len(sicb.builders)) + for i := range sicb.builders { + func(i int, root context.Context) { + builder := sicb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*SentinelInfoMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, sicb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = sicb.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, sicb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + if specs[i].ID.Value != nil && nodes[i].ID == 0 { + id := specs[i].ID.Value.(int64) + nodes[i].ID = model.InternalID(id) + } + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, sicb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (sicb *SentinelInfoCreateBulk) SaveX(ctx context.Context) []*SentinelInfo { + v, err := sicb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (sicb *SentinelInfoCreateBulk) Exec(ctx context.Context) error { + _, err := sicb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (sicb *SentinelInfoCreateBulk) ExecX(ctx context.Context) { + if err := sicb.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.SentinelInfo.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.SentinelInfoUpsert) { +// SetURL(v+v). +// }). +// Exec(ctx) +func (sicb *SentinelInfoCreateBulk) OnConflict(opts ...sql.ConflictOption) *SentinelInfoUpsertBulk { + sicb.conflict = opts + return &SentinelInfoUpsertBulk{ + create: sicb, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.SentinelInfo.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (sicb *SentinelInfoCreateBulk) OnConflictColumns(columns ...string) *SentinelInfoUpsertBulk { + sicb.conflict = append(sicb.conflict, sql.ConflictColumns(columns...)) + return &SentinelInfoUpsertBulk{ + create: sicb, + } +} + +// SentinelInfoUpsertBulk is the builder for "upsert"-ing +// a bulk of SentinelInfo nodes. +type SentinelInfoUpsertBulk struct { + create *SentinelInfoCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.SentinelInfo.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(sentinelinfo.FieldID) +// }), +// ). +// Exec(ctx) +func (u *SentinelInfoUpsertBulk) UpdateNewValues() *SentinelInfoUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { + for _, b := range u.create.builders { + if _, exists := b.mutation.ID(); exists { + s.SetIgnore(sentinelinfo.FieldID) + } + } + })) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.SentinelInfo.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SentinelInfoUpsertBulk) Ignore() *SentinelInfoUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *SentinelInfoUpsertBulk) DoNothing() *SentinelInfoUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SentinelInfoCreateBulk.OnConflict +// documentation for more info. +func (u *SentinelInfoUpsertBulk) Update(set func(*SentinelInfoUpsert)) *SentinelInfoUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SentinelInfoUpsert{UpdateSet: update}) + })) + return u +} + +// SetURL sets the "url" field. +func (u *SentinelInfoUpsertBulk) SetURL(v string) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetURL(v) + }) +} + +// UpdateURL sets the "url" field to the value that was provided on create. +func (u *SentinelInfoUpsertBulk) UpdateURL() *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateURL() + }) +} + +// SetAlternativeUrls sets the "alternative_urls" field. +func (u *SentinelInfoUpsertBulk) SetAlternativeUrls(v []string) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetAlternativeUrls(v) + }) +} + +// UpdateAlternativeUrls sets the "alternative_urls" field to the value that was provided on create. +func (u *SentinelInfoUpsertBulk) UpdateAlternativeUrls() *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateAlternativeUrls() + }) +} + +// ClearAlternativeUrls clears the value of the "alternative_urls" field. +func (u *SentinelInfoUpsertBulk) ClearAlternativeUrls() *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.ClearAlternativeUrls() + }) +} + +// SetGetTokenPath sets the "get_token_path" field. +func (u *SentinelInfoUpsertBulk) SetGetTokenPath(v string) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetGetTokenPath(v) + }) +} + +// UpdateGetTokenPath sets the "get_token_path" field to the value that was provided on create. +func (u *SentinelInfoUpsertBulk) UpdateGetTokenPath() *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateGetTokenPath() + }) +} + +// ClearGetTokenPath clears the value of the "get_token_path" field. +func (u *SentinelInfoUpsertBulk) ClearGetTokenPath() *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.ClearGetTokenPath() + }) +} + +// SetDownloadFileBasePath sets the "download_file_base_path" field. +func (u *SentinelInfoUpsertBulk) SetDownloadFileBasePath(v string) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetDownloadFileBasePath(v) + }) +} + +// UpdateDownloadFileBasePath sets the "download_file_base_path" field to the value that was provided on create. +func (u *SentinelInfoUpsertBulk) UpdateDownloadFileBasePath() *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateDownloadFileBasePath() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelInfoUpsertBulk) SetUpdatedAt(v time.Time) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelInfoUpsertBulk) UpdateUpdatedAt() *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelInfoUpsertBulk) SetCreatedAt(v time.Time) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelInfoUpsertBulk) UpdateCreatedAt() *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (u *SentinelInfoUpsertBulk) SetLibraryReportSequence(v int64) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetLibraryReportSequence(v) + }) +} + +// AddLibraryReportSequence adds v to the "library_report_sequence" field. +func (u *SentinelInfoUpsertBulk) AddLibraryReportSequence(v int64) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.AddLibraryReportSequence(v) + }) +} + +// UpdateLibraryReportSequence sets the "library_report_sequence" field to the value that was provided on create. +func (u *SentinelInfoUpsertBulk) UpdateLibraryReportSequence() *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateLibraryReportSequence() + }) +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelInfoUpsertBulk) SetAppBinaryReportSequence(v int64) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetAppBinaryReportSequence(v) + }) +} + +// AddAppBinaryReportSequence adds v to the "app_binary_report_sequence" field. +func (u *SentinelInfoUpsertBulk) AddAppBinaryReportSequence(v int64) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.AddAppBinaryReportSequence(v) + }) +} + +// UpdateAppBinaryReportSequence sets the "app_binary_report_sequence" field to the value that was provided on create. +func (u *SentinelInfoUpsertBulk) UpdateAppBinaryReportSequence() *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateAppBinaryReportSequence() + }) +} + +// Exec executes the query. +func (u *SentinelInfoUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the SentinelInfoCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for SentinelInfoCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SentinelInfoUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/data/internal/ent/sentinelinfo_delete.go b/internal/data/internal/ent/sentinelinfo_delete.go new file mode 100644 index 00000000..7c1be856 --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" +) + +// SentinelInfoDelete is the builder for deleting a SentinelInfo entity. +type SentinelInfoDelete struct { + config + hooks []Hook + mutation *SentinelInfoMutation +} + +// Where appends a list predicates to the SentinelInfoDelete builder. +func (sid *SentinelInfoDelete) Where(ps ...predicate.SentinelInfo) *SentinelInfoDelete { + sid.mutation.Where(ps...) + return sid +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (sid *SentinelInfoDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, sid.sqlExec, sid.mutation, sid.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (sid *SentinelInfoDelete) ExecX(ctx context.Context) int { + n, err := sid.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (sid *SentinelInfoDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(sentinelinfo.Table, sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64)) + if ps := sid.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, sid.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + sid.mutation.done = true + return affected, err +} + +// SentinelInfoDeleteOne is the builder for deleting a single SentinelInfo entity. +type SentinelInfoDeleteOne struct { + sid *SentinelInfoDelete +} + +// Where appends a list predicates to the SentinelInfoDelete builder. +func (sido *SentinelInfoDeleteOne) Where(ps ...predicate.SentinelInfo) *SentinelInfoDeleteOne { + sido.sid.mutation.Where(ps...) + return sido +} + +// Exec executes the deletion query. +func (sido *SentinelInfoDeleteOne) Exec(ctx context.Context) error { + n, err := sido.sid.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{sentinelinfo.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (sido *SentinelInfoDeleteOne) ExecX(ctx context.Context) { + if err := sido.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/data/internal/ent/sentinelinfo_query.go b/internal/data/internal/ent/sentinelinfo_query.go new file mode 100644 index 00000000..6355b011 --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo_query.go @@ -0,0 +1,609 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelInfoQuery is the builder for querying SentinelInfo entities. +type SentinelInfoQuery struct { + config + ctx *QueryContext + order []sentinelinfo.OrderOption + inters []Interceptor + predicates []predicate.SentinelInfo + withSentinelLibrary *SentinelLibraryQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the SentinelInfoQuery builder. +func (siq *SentinelInfoQuery) Where(ps ...predicate.SentinelInfo) *SentinelInfoQuery { + siq.predicates = append(siq.predicates, ps...) + return siq +} + +// Limit the number of records to be returned by this query. +func (siq *SentinelInfoQuery) Limit(limit int) *SentinelInfoQuery { + siq.ctx.Limit = &limit + return siq +} + +// Offset to start from. +func (siq *SentinelInfoQuery) Offset(offset int) *SentinelInfoQuery { + siq.ctx.Offset = &offset + return siq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (siq *SentinelInfoQuery) Unique(unique bool) *SentinelInfoQuery { + siq.ctx.Unique = &unique + return siq +} + +// Order specifies how the records should be ordered. +func (siq *SentinelInfoQuery) Order(o ...sentinelinfo.OrderOption) *SentinelInfoQuery { + siq.order = append(siq.order, o...) + return siq +} + +// QuerySentinelLibrary chains the current query on the "sentinel_library" edge. +func (siq *SentinelInfoQuery) QuerySentinelLibrary() *SentinelLibraryQuery { + query := (&SentinelLibraryClient{config: siq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := siq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := siq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(sentinelinfo.Table, sentinelinfo.FieldID, selector), + sqlgraph.To(sentinellibrary.Table, sentinellibrary.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, sentinelinfo.SentinelLibraryTable, sentinelinfo.SentinelLibraryColumn), + ) + fromU = sqlgraph.SetNeighbors(siq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first SentinelInfo entity from the query. +// Returns a *NotFoundError when no SentinelInfo was found. +func (siq *SentinelInfoQuery) First(ctx context.Context) (*SentinelInfo, error) { + nodes, err := siq.Limit(1).All(setContextOp(ctx, siq.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{sentinelinfo.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (siq *SentinelInfoQuery) FirstX(ctx context.Context) *SentinelInfo { + node, err := siq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first SentinelInfo ID from the query. +// Returns a *NotFoundError when no SentinelInfo ID was found. +func (siq *SentinelInfoQuery) FirstID(ctx context.Context) (id model.InternalID, err error) { + var ids []model.InternalID + if ids, err = siq.Limit(1).IDs(setContextOp(ctx, siq.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{sentinelinfo.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (siq *SentinelInfoQuery) FirstIDX(ctx context.Context) model.InternalID { + id, err := siq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single SentinelInfo entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one SentinelInfo entity is found. +// Returns a *NotFoundError when no SentinelInfo entities are found. +func (siq *SentinelInfoQuery) Only(ctx context.Context) (*SentinelInfo, error) { + nodes, err := siq.Limit(2).All(setContextOp(ctx, siq.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{sentinelinfo.Label} + default: + return nil, &NotSingularError{sentinelinfo.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (siq *SentinelInfoQuery) OnlyX(ctx context.Context) *SentinelInfo { + node, err := siq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only SentinelInfo ID in the query. +// Returns a *NotSingularError when more than one SentinelInfo ID is found. +// Returns a *NotFoundError when no entities are found. +func (siq *SentinelInfoQuery) OnlyID(ctx context.Context) (id model.InternalID, err error) { + var ids []model.InternalID + if ids, err = siq.Limit(2).IDs(setContextOp(ctx, siq.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{sentinelinfo.Label} + default: + err = &NotSingularError{sentinelinfo.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (siq *SentinelInfoQuery) OnlyIDX(ctx context.Context) model.InternalID { + id, err := siq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of SentinelInfos. +func (siq *SentinelInfoQuery) All(ctx context.Context) ([]*SentinelInfo, error) { + ctx = setContextOp(ctx, siq.ctx, ent.OpQueryAll) + if err := siq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*SentinelInfo, *SentinelInfoQuery]() + return withInterceptors[[]*SentinelInfo](ctx, siq, qr, siq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (siq *SentinelInfoQuery) AllX(ctx context.Context) []*SentinelInfo { + nodes, err := siq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of SentinelInfo IDs. +func (siq *SentinelInfoQuery) IDs(ctx context.Context) (ids []model.InternalID, err error) { + if siq.ctx.Unique == nil && siq.path != nil { + siq.Unique(true) + } + ctx = setContextOp(ctx, siq.ctx, ent.OpQueryIDs) + if err = siq.Select(sentinelinfo.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (siq *SentinelInfoQuery) IDsX(ctx context.Context) []model.InternalID { + ids, err := siq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (siq *SentinelInfoQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, siq.ctx, ent.OpQueryCount) + if err := siq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, siq, querierCount[*SentinelInfoQuery](), siq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (siq *SentinelInfoQuery) CountX(ctx context.Context) int { + count, err := siq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (siq *SentinelInfoQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, siq.ctx, ent.OpQueryExist) + switch _, err := siq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (siq *SentinelInfoQuery) ExistX(ctx context.Context) bool { + exist, err := siq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the SentinelInfoQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (siq *SentinelInfoQuery) Clone() *SentinelInfoQuery { + if siq == nil { + return nil + } + return &SentinelInfoQuery{ + config: siq.config, + ctx: siq.ctx.Clone(), + order: append([]sentinelinfo.OrderOption{}, siq.order...), + inters: append([]Interceptor{}, siq.inters...), + predicates: append([]predicate.SentinelInfo{}, siq.predicates...), + withSentinelLibrary: siq.withSentinelLibrary.Clone(), + // clone intermediate query. + sql: siq.sql.Clone(), + path: siq.path, + } +} + +// WithSentinelLibrary tells the query-builder to eager-load the nodes that are connected to +// the "sentinel_library" edge. The optional arguments are used to configure the query builder of the edge. +func (siq *SentinelInfoQuery) WithSentinelLibrary(opts ...func(*SentinelLibraryQuery)) *SentinelInfoQuery { + query := (&SentinelLibraryClient{config: siq.config}).Query() + for _, opt := range opts { + opt(query) + } + siq.withSentinelLibrary = query + return siq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// URL string `json:"url,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.SentinelInfo.Query(). +// GroupBy(sentinelinfo.FieldURL). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (siq *SentinelInfoQuery) GroupBy(field string, fields ...string) *SentinelInfoGroupBy { + siq.ctx.Fields = append([]string{field}, fields...) + grbuild := &SentinelInfoGroupBy{build: siq} + grbuild.flds = &siq.ctx.Fields + grbuild.label = sentinelinfo.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// URL string `json:"url,omitempty"` +// } +// +// client.SentinelInfo.Query(). +// Select(sentinelinfo.FieldURL). +// Scan(ctx, &v) +func (siq *SentinelInfoQuery) Select(fields ...string) *SentinelInfoSelect { + siq.ctx.Fields = append(siq.ctx.Fields, fields...) + sbuild := &SentinelInfoSelect{SentinelInfoQuery: siq} + sbuild.label = sentinelinfo.Label + sbuild.flds, sbuild.scan = &siq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a SentinelInfoSelect configured with the given aggregations. +func (siq *SentinelInfoQuery) Aggregate(fns ...AggregateFunc) *SentinelInfoSelect { + return siq.Select().Aggregate(fns...) +} + +func (siq *SentinelInfoQuery) prepareQuery(ctx context.Context) error { + for _, inter := range siq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, siq); err != nil { + return err + } + } + } + for _, f := range siq.ctx.Fields { + if !sentinelinfo.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if siq.path != nil { + prev, err := siq.path(ctx) + if err != nil { + return err + } + siq.sql = prev + } + return nil +} + +func (siq *SentinelInfoQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SentinelInfo, error) { + var ( + nodes = []*SentinelInfo{} + _spec = siq.querySpec() + loadedTypes = [1]bool{ + siq.withSentinelLibrary != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*SentinelInfo).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &SentinelInfo{config: siq.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, siq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := siq.withSentinelLibrary; query != nil { + if err := siq.loadSentinelLibrary(ctx, query, nodes, + func(n *SentinelInfo) { n.Edges.SentinelLibrary = []*SentinelLibrary{} }, + func(n *SentinelInfo, e *SentinelLibrary) { + n.Edges.SentinelLibrary = append(n.Edges.SentinelLibrary, e) + }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (siq *SentinelInfoQuery) loadSentinelLibrary(ctx context.Context, query *SentinelLibraryQuery, nodes []*SentinelInfo, init func(*SentinelInfo), assign func(*SentinelInfo, *SentinelLibrary)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[model.InternalID]*SentinelInfo) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + if init != nil { + init(nodes[i]) + } + } + if len(query.ctx.Fields) > 0 { + query.ctx.AppendFieldOnce(sentinellibrary.FieldSentinelInfoID) + } + query.Where(predicate.SentinelLibrary(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(sentinelinfo.SentinelLibraryColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.SentinelInfoID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "sentinel_info_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return nil +} + +func (siq *SentinelInfoQuery) sqlCount(ctx context.Context) (int, error) { + _spec := siq.querySpec() + _spec.Node.Columns = siq.ctx.Fields + if len(siq.ctx.Fields) > 0 { + _spec.Unique = siq.ctx.Unique != nil && *siq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, siq.driver, _spec) +} + +func (siq *SentinelInfoQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(sentinelinfo.Table, sentinelinfo.Columns, sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64)) + _spec.From = siq.sql + if unique := siq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if siq.path != nil { + _spec.Unique = true + } + if fields := siq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, sentinelinfo.FieldID) + for i := range fields { + if fields[i] != sentinelinfo.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := siq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := siq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := siq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := siq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (siq *SentinelInfoQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(siq.driver.Dialect()) + t1 := builder.Table(sentinelinfo.Table) + columns := siq.ctx.Fields + if len(columns) == 0 { + columns = sentinelinfo.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if siq.sql != nil { + selector = siq.sql + selector.Select(selector.Columns(columns...)...) + } + if siq.ctx.Unique != nil && *siq.ctx.Unique { + selector.Distinct() + } + for _, p := range siq.predicates { + p(selector) + } + for _, p := range siq.order { + p(selector) + } + if offset := siq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := siq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// SentinelInfoGroupBy is the group-by builder for SentinelInfo entities. +type SentinelInfoGroupBy struct { + selector + build *SentinelInfoQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (sigb *SentinelInfoGroupBy) Aggregate(fns ...AggregateFunc) *SentinelInfoGroupBy { + sigb.fns = append(sigb.fns, fns...) + return sigb +} + +// Scan applies the selector query and scans the result into the given value. +func (sigb *SentinelInfoGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, sigb.build.ctx, ent.OpQueryGroupBy) + if err := sigb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*SentinelInfoQuery, *SentinelInfoGroupBy](ctx, sigb.build, sigb, sigb.build.inters, v) +} + +func (sigb *SentinelInfoGroupBy) sqlScan(ctx context.Context, root *SentinelInfoQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(sigb.fns)) + for _, fn := range sigb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*sigb.flds)+len(sigb.fns)) + for _, f := range *sigb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*sigb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := sigb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// SentinelInfoSelect is the builder for selecting fields of SentinelInfo entities. +type SentinelInfoSelect struct { + *SentinelInfoQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (sis *SentinelInfoSelect) Aggregate(fns ...AggregateFunc) *SentinelInfoSelect { + sis.fns = append(sis.fns, fns...) + return sis +} + +// Scan applies the selector query and scans the result into the given value. +func (sis *SentinelInfoSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, sis.ctx, ent.OpQuerySelect) + if err := sis.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*SentinelInfoQuery, *SentinelInfoSelect](ctx, sis.SentinelInfoQuery, sis, sis.inters, v) +} + +func (sis *SentinelInfoSelect) sqlScan(ctx context.Context, root *SentinelInfoQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(sis.fns)) + for _, fn := range sis.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*sis.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := sis.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/internal/data/internal/ent/sentinelinfo_update.go b/internal/data/internal/ent/sentinelinfo_update.go new file mode 100644 index 00000000..738ebd85 --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo_update.go @@ -0,0 +1,696 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" +) + +// SentinelInfoUpdate is the builder for updating SentinelInfo entities. +type SentinelInfoUpdate struct { + config + hooks []Hook + mutation *SentinelInfoMutation +} + +// Where appends a list predicates to the SentinelInfoUpdate builder. +func (siu *SentinelInfoUpdate) Where(ps ...predicate.SentinelInfo) *SentinelInfoUpdate { + siu.mutation.Where(ps...) + return siu +} + +// SetURL sets the "url" field. +func (siu *SentinelInfoUpdate) SetURL(s string) *SentinelInfoUpdate { + siu.mutation.SetURL(s) + return siu +} + +// SetNillableURL sets the "url" field if the given value is not nil. +func (siu *SentinelInfoUpdate) SetNillableURL(s *string) *SentinelInfoUpdate { + if s != nil { + siu.SetURL(*s) + } + return siu +} + +// SetAlternativeUrls sets the "alternative_urls" field. +func (siu *SentinelInfoUpdate) SetAlternativeUrls(s []string) *SentinelInfoUpdate { + siu.mutation.SetAlternativeUrls(s) + return siu +} + +// AppendAlternativeUrls appends s to the "alternative_urls" field. +func (siu *SentinelInfoUpdate) AppendAlternativeUrls(s []string) *SentinelInfoUpdate { + siu.mutation.AppendAlternativeUrls(s) + return siu +} + +// ClearAlternativeUrls clears the value of the "alternative_urls" field. +func (siu *SentinelInfoUpdate) ClearAlternativeUrls() *SentinelInfoUpdate { + siu.mutation.ClearAlternativeUrls() + return siu +} + +// SetGetTokenPath sets the "get_token_path" field. +func (siu *SentinelInfoUpdate) SetGetTokenPath(s string) *SentinelInfoUpdate { + siu.mutation.SetGetTokenPath(s) + return siu +} + +// SetNillableGetTokenPath sets the "get_token_path" field if the given value is not nil. +func (siu *SentinelInfoUpdate) SetNillableGetTokenPath(s *string) *SentinelInfoUpdate { + if s != nil { + siu.SetGetTokenPath(*s) + } + return siu +} + +// ClearGetTokenPath clears the value of the "get_token_path" field. +func (siu *SentinelInfoUpdate) ClearGetTokenPath() *SentinelInfoUpdate { + siu.mutation.ClearGetTokenPath() + return siu +} + +// SetDownloadFileBasePath sets the "download_file_base_path" field. +func (siu *SentinelInfoUpdate) SetDownloadFileBasePath(s string) *SentinelInfoUpdate { + siu.mutation.SetDownloadFileBasePath(s) + return siu +} + +// SetNillableDownloadFileBasePath sets the "download_file_base_path" field if the given value is not nil. +func (siu *SentinelInfoUpdate) SetNillableDownloadFileBasePath(s *string) *SentinelInfoUpdate { + if s != nil { + siu.SetDownloadFileBasePath(*s) + } + return siu +} + +// SetUpdatedAt sets the "updated_at" field. +func (siu *SentinelInfoUpdate) SetUpdatedAt(t time.Time) *SentinelInfoUpdate { + siu.mutation.SetUpdatedAt(t) + return siu +} + +// SetCreatedAt sets the "created_at" field. +func (siu *SentinelInfoUpdate) SetCreatedAt(t time.Time) *SentinelInfoUpdate { + siu.mutation.SetCreatedAt(t) + return siu +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (siu *SentinelInfoUpdate) SetNillableCreatedAt(t *time.Time) *SentinelInfoUpdate { + if t != nil { + siu.SetCreatedAt(*t) + } + return siu +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (siu *SentinelInfoUpdate) SetLibraryReportSequence(i int64) *SentinelInfoUpdate { + siu.mutation.ResetLibraryReportSequence() + siu.mutation.SetLibraryReportSequence(i) + return siu +} + +// SetNillableLibraryReportSequence sets the "library_report_sequence" field if the given value is not nil. +func (siu *SentinelInfoUpdate) SetNillableLibraryReportSequence(i *int64) *SentinelInfoUpdate { + if i != nil { + siu.SetLibraryReportSequence(*i) + } + return siu +} + +// AddLibraryReportSequence adds i to the "library_report_sequence" field. +func (siu *SentinelInfoUpdate) AddLibraryReportSequence(i int64) *SentinelInfoUpdate { + siu.mutation.AddLibraryReportSequence(i) + return siu +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (siu *SentinelInfoUpdate) SetAppBinaryReportSequence(i int64) *SentinelInfoUpdate { + siu.mutation.ResetAppBinaryReportSequence() + siu.mutation.SetAppBinaryReportSequence(i) + return siu +} + +// SetNillableAppBinaryReportSequence sets the "app_binary_report_sequence" field if the given value is not nil. +func (siu *SentinelInfoUpdate) SetNillableAppBinaryReportSequence(i *int64) *SentinelInfoUpdate { + if i != nil { + siu.SetAppBinaryReportSequence(*i) + } + return siu +} + +// AddAppBinaryReportSequence adds i to the "app_binary_report_sequence" field. +func (siu *SentinelInfoUpdate) AddAppBinaryReportSequence(i int64) *SentinelInfoUpdate { + siu.mutation.AddAppBinaryReportSequence(i) + return siu +} + +// AddSentinelLibraryIDs adds the "sentinel_library" edge to the SentinelLibrary entity by IDs. +func (siu *SentinelInfoUpdate) AddSentinelLibraryIDs(ids ...int) *SentinelInfoUpdate { + siu.mutation.AddSentinelLibraryIDs(ids...) + return siu +} + +// AddSentinelLibrary adds the "sentinel_library" edges to the SentinelLibrary entity. +func (siu *SentinelInfoUpdate) AddSentinelLibrary(s ...*SentinelLibrary) *SentinelInfoUpdate { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return siu.AddSentinelLibraryIDs(ids...) +} + +// Mutation returns the SentinelInfoMutation object of the builder. +func (siu *SentinelInfoUpdate) Mutation() *SentinelInfoMutation { + return siu.mutation +} + +// ClearSentinelLibrary clears all "sentinel_library" edges to the SentinelLibrary entity. +func (siu *SentinelInfoUpdate) ClearSentinelLibrary() *SentinelInfoUpdate { + siu.mutation.ClearSentinelLibrary() + return siu +} + +// RemoveSentinelLibraryIDs removes the "sentinel_library" edge to SentinelLibrary entities by IDs. +func (siu *SentinelInfoUpdate) RemoveSentinelLibraryIDs(ids ...int) *SentinelInfoUpdate { + siu.mutation.RemoveSentinelLibraryIDs(ids...) + return siu +} + +// RemoveSentinelLibrary removes "sentinel_library" edges to SentinelLibrary entities. +func (siu *SentinelInfoUpdate) RemoveSentinelLibrary(s ...*SentinelLibrary) *SentinelInfoUpdate { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return siu.RemoveSentinelLibraryIDs(ids...) +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (siu *SentinelInfoUpdate) Save(ctx context.Context) (int, error) { + siu.defaults() + return withHooks(ctx, siu.sqlSave, siu.mutation, siu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (siu *SentinelInfoUpdate) SaveX(ctx context.Context) int { + affected, err := siu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (siu *SentinelInfoUpdate) Exec(ctx context.Context) error { + _, err := siu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (siu *SentinelInfoUpdate) ExecX(ctx context.Context) { + if err := siu.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (siu *SentinelInfoUpdate) defaults() { + if _, ok := siu.mutation.UpdatedAt(); !ok { + v := sentinelinfo.UpdateDefaultUpdatedAt() + siu.mutation.SetUpdatedAt(v) + } +} + +func (siu *SentinelInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := sqlgraph.NewUpdateSpec(sentinelinfo.Table, sentinelinfo.Columns, sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64)) + if ps := siu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := siu.mutation.URL(); ok { + _spec.SetField(sentinelinfo.FieldURL, field.TypeString, value) + } + if value, ok := siu.mutation.AlternativeUrls(); ok { + _spec.SetField(sentinelinfo.FieldAlternativeUrls, field.TypeJSON, value) + } + if value, ok := siu.mutation.AppendedAlternativeUrls(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, sentinelinfo.FieldAlternativeUrls, value) + }) + } + if siu.mutation.AlternativeUrlsCleared() { + _spec.ClearField(sentinelinfo.FieldAlternativeUrls, field.TypeJSON) + } + if value, ok := siu.mutation.GetTokenPath(); ok { + _spec.SetField(sentinelinfo.FieldGetTokenPath, field.TypeString, value) + } + if siu.mutation.GetTokenPathCleared() { + _spec.ClearField(sentinelinfo.FieldGetTokenPath, field.TypeString) + } + if value, ok := siu.mutation.DownloadFileBasePath(); ok { + _spec.SetField(sentinelinfo.FieldDownloadFileBasePath, field.TypeString, value) + } + if value, ok := siu.mutation.UpdatedAt(); ok { + _spec.SetField(sentinelinfo.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := siu.mutation.CreatedAt(); ok { + _spec.SetField(sentinelinfo.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := siu.mutation.LibraryReportSequence(); ok { + _spec.SetField(sentinelinfo.FieldLibraryReportSequence, field.TypeInt64, value) + } + if value, ok := siu.mutation.AddedLibraryReportSequence(); ok { + _spec.AddField(sentinelinfo.FieldLibraryReportSequence, field.TypeInt64, value) + } + if value, ok := siu.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelinfo.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + if value, ok := siu.mutation.AddedAppBinaryReportSequence(); ok { + _spec.AddField(sentinelinfo.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + if siu.mutation.SentinelLibraryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelinfo.SentinelLibraryTable, + Columns: []string{sentinelinfo.SentinelLibraryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := siu.mutation.RemovedSentinelLibraryIDs(); len(nodes) > 0 && !siu.mutation.SentinelLibraryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelinfo.SentinelLibraryTable, + Columns: []string{sentinelinfo.SentinelLibraryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := siu.mutation.SentinelLibraryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelinfo.SentinelLibraryTable, + Columns: []string{sentinelinfo.SentinelLibraryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, siu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{sentinelinfo.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + siu.mutation.done = true + return n, nil +} + +// SentinelInfoUpdateOne is the builder for updating a single SentinelInfo entity. +type SentinelInfoUpdateOne struct { + config + fields []string + hooks []Hook + mutation *SentinelInfoMutation +} + +// SetURL sets the "url" field. +func (siuo *SentinelInfoUpdateOne) SetURL(s string) *SentinelInfoUpdateOne { + siuo.mutation.SetURL(s) + return siuo +} + +// SetNillableURL sets the "url" field if the given value is not nil. +func (siuo *SentinelInfoUpdateOne) SetNillableURL(s *string) *SentinelInfoUpdateOne { + if s != nil { + siuo.SetURL(*s) + } + return siuo +} + +// SetAlternativeUrls sets the "alternative_urls" field. +func (siuo *SentinelInfoUpdateOne) SetAlternativeUrls(s []string) *SentinelInfoUpdateOne { + siuo.mutation.SetAlternativeUrls(s) + return siuo +} + +// AppendAlternativeUrls appends s to the "alternative_urls" field. +func (siuo *SentinelInfoUpdateOne) AppendAlternativeUrls(s []string) *SentinelInfoUpdateOne { + siuo.mutation.AppendAlternativeUrls(s) + return siuo +} + +// ClearAlternativeUrls clears the value of the "alternative_urls" field. +func (siuo *SentinelInfoUpdateOne) ClearAlternativeUrls() *SentinelInfoUpdateOne { + siuo.mutation.ClearAlternativeUrls() + return siuo +} + +// SetGetTokenPath sets the "get_token_path" field. +func (siuo *SentinelInfoUpdateOne) SetGetTokenPath(s string) *SentinelInfoUpdateOne { + siuo.mutation.SetGetTokenPath(s) + return siuo +} + +// SetNillableGetTokenPath sets the "get_token_path" field if the given value is not nil. +func (siuo *SentinelInfoUpdateOne) SetNillableGetTokenPath(s *string) *SentinelInfoUpdateOne { + if s != nil { + siuo.SetGetTokenPath(*s) + } + return siuo +} + +// ClearGetTokenPath clears the value of the "get_token_path" field. +func (siuo *SentinelInfoUpdateOne) ClearGetTokenPath() *SentinelInfoUpdateOne { + siuo.mutation.ClearGetTokenPath() + return siuo +} + +// SetDownloadFileBasePath sets the "download_file_base_path" field. +func (siuo *SentinelInfoUpdateOne) SetDownloadFileBasePath(s string) *SentinelInfoUpdateOne { + siuo.mutation.SetDownloadFileBasePath(s) + return siuo +} + +// SetNillableDownloadFileBasePath sets the "download_file_base_path" field if the given value is not nil. +func (siuo *SentinelInfoUpdateOne) SetNillableDownloadFileBasePath(s *string) *SentinelInfoUpdateOne { + if s != nil { + siuo.SetDownloadFileBasePath(*s) + } + return siuo +} + +// SetUpdatedAt sets the "updated_at" field. +func (siuo *SentinelInfoUpdateOne) SetUpdatedAt(t time.Time) *SentinelInfoUpdateOne { + siuo.mutation.SetUpdatedAt(t) + return siuo +} + +// SetCreatedAt sets the "created_at" field. +func (siuo *SentinelInfoUpdateOne) SetCreatedAt(t time.Time) *SentinelInfoUpdateOne { + siuo.mutation.SetCreatedAt(t) + return siuo +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (siuo *SentinelInfoUpdateOne) SetNillableCreatedAt(t *time.Time) *SentinelInfoUpdateOne { + if t != nil { + siuo.SetCreatedAt(*t) + } + return siuo +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (siuo *SentinelInfoUpdateOne) SetLibraryReportSequence(i int64) *SentinelInfoUpdateOne { + siuo.mutation.ResetLibraryReportSequence() + siuo.mutation.SetLibraryReportSequence(i) + return siuo +} + +// SetNillableLibraryReportSequence sets the "library_report_sequence" field if the given value is not nil. +func (siuo *SentinelInfoUpdateOne) SetNillableLibraryReportSequence(i *int64) *SentinelInfoUpdateOne { + if i != nil { + siuo.SetLibraryReportSequence(*i) + } + return siuo +} + +// AddLibraryReportSequence adds i to the "library_report_sequence" field. +func (siuo *SentinelInfoUpdateOne) AddLibraryReportSequence(i int64) *SentinelInfoUpdateOne { + siuo.mutation.AddLibraryReportSequence(i) + return siuo +} + +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (siuo *SentinelInfoUpdateOne) SetAppBinaryReportSequence(i int64) *SentinelInfoUpdateOne { + siuo.mutation.ResetAppBinaryReportSequence() + siuo.mutation.SetAppBinaryReportSequence(i) + return siuo +} + +// SetNillableAppBinaryReportSequence sets the "app_binary_report_sequence" field if the given value is not nil. +func (siuo *SentinelInfoUpdateOne) SetNillableAppBinaryReportSequence(i *int64) *SentinelInfoUpdateOne { + if i != nil { + siuo.SetAppBinaryReportSequence(*i) + } + return siuo +} + +// AddAppBinaryReportSequence adds i to the "app_binary_report_sequence" field. +func (siuo *SentinelInfoUpdateOne) AddAppBinaryReportSequence(i int64) *SentinelInfoUpdateOne { + siuo.mutation.AddAppBinaryReportSequence(i) + return siuo +} + +// AddSentinelLibraryIDs adds the "sentinel_library" edge to the SentinelLibrary entity by IDs. +func (siuo *SentinelInfoUpdateOne) AddSentinelLibraryIDs(ids ...int) *SentinelInfoUpdateOne { + siuo.mutation.AddSentinelLibraryIDs(ids...) + return siuo +} + +// AddSentinelLibrary adds the "sentinel_library" edges to the SentinelLibrary entity. +func (siuo *SentinelInfoUpdateOne) AddSentinelLibrary(s ...*SentinelLibrary) *SentinelInfoUpdateOne { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return siuo.AddSentinelLibraryIDs(ids...) +} + +// Mutation returns the SentinelInfoMutation object of the builder. +func (siuo *SentinelInfoUpdateOne) Mutation() *SentinelInfoMutation { + return siuo.mutation +} + +// ClearSentinelLibrary clears all "sentinel_library" edges to the SentinelLibrary entity. +func (siuo *SentinelInfoUpdateOne) ClearSentinelLibrary() *SentinelInfoUpdateOne { + siuo.mutation.ClearSentinelLibrary() + return siuo +} + +// RemoveSentinelLibraryIDs removes the "sentinel_library" edge to SentinelLibrary entities by IDs. +func (siuo *SentinelInfoUpdateOne) RemoveSentinelLibraryIDs(ids ...int) *SentinelInfoUpdateOne { + siuo.mutation.RemoveSentinelLibraryIDs(ids...) + return siuo +} + +// RemoveSentinelLibrary removes "sentinel_library" edges to SentinelLibrary entities. +func (siuo *SentinelInfoUpdateOne) RemoveSentinelLibrary(s ...*SentinelLibrary) *SentinelInfoUpdateOne { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return siuo.RemoveSentinelLibraryIDs(ids...) +} + +// Where appends a list predicates to the SentinelInfoUpdate builder. +func (siuo *SentinelInfoUpdateOne) Where(ps ...predicate.SentinelInfo) *SentinelInfoUpdateOne { + siuo.mutation.Where(ps...) + return siuo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (siuo *SentinelInfoUpdateOne) Select(field string, fields ...string) *SentinelInfoUpdateOne { + siuo.fields = append([]string{field}, fields...) + return siuo +} + +// Save executes the query and returns the updated SentinelInfo entity. +func (siuo *SentinelInfoUpdateOne) Save(ctx context.Context) (*SentinelInfo, error) { + siuo.defaults() + return withHooks(ctx, siuo.sqlSave, siuo.mutation, siuo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (siuo *SentinelInfoUpdateOne) SaveX(ctx context.Context) *SentinelInfo { + node, err := siuo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (siuo *SentinelInfoUpdateOne) Exec(ctx context.Context) error { + _, err := siuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (siuo *SentinelInfoUpdateOne) ExecX(ctx context.Context) { + if err := siuo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (siuo *SentinelInfoUpdateOne) defaults() { + if _, ok := siuo.mutation.UpdatedAt(); !ok { + v := sentinelinfo.UpdateDefaultUpdatedAt() + siuo.mutation.SetUpdatedAt(v) + } +} + +func (siuo *SentinelInfoUpdateOne) sqlSave(ctx context.Context) (_node *SentinelInfo, err error) { + _spec := sqlgraph.NewUpdateSpec(sentinelinfo.Table, sentinelinfo.Columns, sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64)) + id, ok := siuo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SentinelInfo.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := siuo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, sentinelinfo.FieldID) + for _, f := range fields { + if !sentinelinfo.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != sentinelinfo.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := siuo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := siuo.mutation.URL(); ok { + _spec.SetField(sentinelinfo.FieldURL, field.TypeString, value) + } + if value, ok := siuo.mutation.AlternativeUrls(); ok { + _spec.SetField(sentinelinfo.FieldAlternativeUrls, field.TypeJSON, value) + } + if value, ok := siuo.mutation.AppendedAlternativeUrls(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, sentinelinfo.FieldAlternativeUrls, value) + }) + } + if siuo.mutation.AlternativeUrlsCleared() { + _spec.ClearField(sentinelinfo.FieldAlternativeUrls, field.TypeJSON) + } + if value, ok := siuo.mutation.GetTokenPath(); ok { + _spec.SetField(sentinelinfo.FieldGetTokenPath, field.TypeString, value) + } + if siuo.mutation.GetTokenPathCleared() { + _spec.ClearField(sentinelinfo.FieldGetTokenPath, field.TypeString) + } + if value, ok := siuo.mutation.DownloadFileBasePath(); ok { + _spec.SetField(sentinelinfo.FieldDownloadFileBasePath, field.TypeString, value) + } + if value, ok := siuo.mutation.UpdatedAt(); ok { + _spec.SetField(sentinelinfo.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := siuo.mutation.CreatedAt(); ok { + _spec.SetField(sentinelinfo.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := siuo.mutation.LibraryReportSequence(); ok { + _spec.SetField(sentinelinfo.FieldLibraryReportSequence, field.TypeInt64, value) + } + if value, ok := siuo.mutation.AddedLibraryReportSequence(); ok { + _spec.AddField(sentinelinfo.FieldLibraryReportSequence, field.TypeInt64, value) + } + if value, ok := siuo.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelinfo.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + if value, ok := siuo.mutation.AddedAppBinaryReportSequence(); ok { + _spec.AddField(sentinelinfo.FieldAppBinaryReportSequence, field.TypeInt64, value) + } + if siuo.mutation.SentinelLibraryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelinfo.SentinelLibraryTable, + Columns: []string{sentinelinfo.SentinelLibraryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := siuo.mutation.RemovedSentinelLibraryIDs(); len(nodes) > 0 && !siuo.mutation.SentinelLibraryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelinfo.SentinelLibraryTable, + Columns: []string{sentinelinfo.SentinelLibraryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := siuo.mutation.SentinelLibraryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelinfo.SentinelLibraryTable, + Columns: []string{sentinelinfo.SentinelLibraryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &SentinelInfo{config: siuo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, siuo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{sentinelinfo.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + siuo.mutation.done = true + return _node, nil +} diff --git a/internal/data/internal/ent/sentinellibrary.go b/internal/data/internal/ent/sentinellibrary.go new file mode 100644 index 00000000..dcc47bed --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary.go @@ -0,0 +1,191 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelLibrary is the model entity for the SentinelLibrary schema. +type SentinelLibrary struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // SentinelInfoID holds the value of the "sentinel_info_id" field. + SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` + // ReportedID holds the value of the "reported_id" field. + ReportedID int64 `json:"reported_id,omitempty"` + // DownloadBasePath holds the value of the "download_base_path" field. + DownloadBasePath string `json:"download_base_path,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // LibraryReportSequence holds the value of the "library_report_sequence" field. + LibraryReportSequence int64 `json:"library_report_sequence,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the SentinelLibraryQuery when eager-loading is set. + Edges SentinelLibraryEdges `json:"edges"` + selectValues sql.SelectValues +} + +// SentinelLibraryEdges holds the relations/edges for other nodes in the graph. +type SentinelLibraryEdges struct { + // SentinelInfo holds the value of the sentinel_info edge. + SentinelInfo *SentinelInfo `json:"sentinel_info,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// SentinelInfoOrErr returns the SentinelInfo value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e SentinelLibraryEdges) SentinelInfoOrErr() (*SentinelInfo, error) { + if e.SentinelInfo != nil { + return e.SentinelInfo, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: sentinelinfo.Label} + } + return nil, &NotLoadedError{edge: "sentinel_info"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*SentinelLibrary) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case sentinellibrary.FieldID, sentinellibrary.FieldSentinelInfoID, sentinellibrary.FieldReportedID, sentinellibrary.FieldLibraryReportSequence: + values[i] = new(sql.NullInt64) + case sentinellibrary.FieldDownloadBasePath: + values[i] = new(sql.NullString) + case sentinellibrary.FieldUpdatedAt, sentinellibrary.FieldCreatedAt: + values[i] = new(sql.NullTime) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the SentinelLibrary fields. +func (sl *SentinelLibrary) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case sentinellibrary.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + sl.ID = int(value.Int64) + case sentinellibrary.FieldSentinelInfoID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field sentinel_info_id", values[i]) + } else if value.Valid { + sl.SentinelInfoID = model.InternalID(value.Int64) + } + case sentinellibrary.FieldReportedID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field reported_id", values[i]) + } else if value.Valid { + sl.ReportedID = value.Int64 + } + case sentinellibrary.FieldDownloadBasePath: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field download_base_path", values[i]) + } else if value.Valid { + sl.DownloadBasePath = value.String + } + case sentinellibrary.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + sl.UpdatedAt = value.Time + } + case sentinellibrary.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + sl.CreatedAt = value.Time + } + case sentinellibrary.FieldLibraryReportSequence: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field library_report_sequence", values[i]) + } else if value.Valid { + sl.LibraryReportSequence = value.Int64 + } + default: + sl.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the SentinelLibrary. +// This includes values selected through modifiers, order, etc. +func (sl *SentinelLibrary) Value(name string) (ent.Value, error) { + return sl.selectValues.Get(name) +} + +// QuerySentinelInfo queries the "sentinel_info" edge of the SentinelLibrary entity. +func (sl *SentinelLibrary) QuerySentinelInfo() *SentinelInfoQuery { + return NewSentinelLibraryClient(sl.config).QuerySentinelInfo(sl) +} + +// Update returns a builder for updating this SentinelLibrary. +// Note that you need to call SentinelLibrary.Unwrap() before calling this method if this SentinelLibrary +// was returned from a transaction, and the transaction was committed or rolled back. +func (sl *SentinelLibrary) Update() *SentinelLibraryUpdateOne { + return NewSentinelLibraryClient(sl.config).UpdateOne(sl) +} + +// Unwrap unwraps the SentinelLibrary entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (sl *SentinelLibrary) Unwrap() *SentinelLibrary { + _tx, ok := sl.config.driver.(*txDriver) + if !ok { + panic("ent: SentinelLibrary is not a transactional entity") + } + sl.config.driver = _tx.drv + return sl +} + +// String implements the fmt.Stringer. +func (sl *SentinelLibrary) String() string { + var builder strings.Builder + builder.WriteString("SentinelLibrary(") + builder.WriteString(fmt.Sprintf("id=%v, ", sl.ID)) + builder.WriteString("sentinel_info_id=") + builder.WriteString(fmt.Sprintf("%v", sl.SentinelInfoID)) + builder.WriteString(", ") + builder.WriteString("reported_id=") + builder.WriteString(fmt.Sprintf("%v", sl.ReportedID)) + builder.WriteString(", ") + builder.WriteString("download_base_path=") + builder.WriteString(sl.DownloadBasePath) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(sl.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(sl.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("library_report_sequence=") + builder.WriteString(fmt.Sprintf("%v", sl.LibraryReportSequence)) + builder.WriteByte(')') + return builder.String() +} + +// SentinelLibraries is a parsable slice of SentinelLibrary. +type SentinelLibraries []*SentinelLibrary diff --git a/internal/data/internal/ent/sentinellibrary/sentinellibrary.go b/internal/data/internal/ent/sentinellibrary/sentinellibrary.go new file mode 100644 index 00000000..336036d7 --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary/sentinellibrary.go @@ -0,0 +1,122 @@ +// Code generated by ent, DO NOT EDIT. + +package sentinellibrary + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +const ( + // Label holds the string label denoting the sentinellibrary type in the database. + Label = "sentinel_library" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldSentinelInfoID holds the string denoting the sentinel_info_id field in the database. + FieldSentinelInfoID = "sentinel_info_id" + // FieldReportedID holds the string denoting the reported_id field in the database. + FieldReportedID = "reported_id" + // FieldDownloadBasePath holds the string denoting the download_base_path field in the database. + FieldDownloadBasePath = "download_base_path" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldLibraryReportSequence holds the string denoting the library_report_sequence field in the database. + FieldLibraryReportSequence = "library_report_sequence" + // EdgeSentinelInfo holds the string denoting the sentinel_info edge name in mutations. + EdgeSentinelInfo = "sentinel_info" + // Table holds the table name of the sentinellibrary in the database. + Table = "sentinel_libraries" + // SentinelInfoTable is the table that holds the sentinel_info relation/edge. + SentinelInfoTable = "sentinel_libraries" + // SentinelInfoInverseTable is the table name for the SentinelInfo entity. + // It exists in this package in order to avoid circular dependency with the "sentinelinfo" package. + SentinelInfoInverseTable = "sentinel_infos" + // SentinelInfoColumn is the table column denoting the sentinel_info relation/edge. + SentinelInfoColumn = "sentinel_info_id" +) + +// Columns holds all SQL columns for sentinellibrary fields. +var Columns = []string{ + FieldID, + FieldSentinelInfoID, + FieldReportedID, + FieldDownloadBasePath, + FieldUpdatedAt, + FieldCreatedAt, + FieldLibraryReportSequence, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. + UpdateDefaultUpdatedAt func() time.Time + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time +) + +// OrderOption defines the ordering options for the SentinelLibrary queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// BySentinelInfoID orders the results by the sentinel_info_id field. +func BySentinelInfoID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSentinelInfoID, opts...).ToFunc() +} + +// ByReportedID orders the results by the reported_id field. +func ByReportedID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldReportedID, opts...).ToFunc() +} + +// ByDownloadBasePath orders the results by the download_base_path field. +func ByDownloadBasePath(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDownloadBasePath, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByLibraryReportSequence orders the results by the library_report_sequence field. +func ByLibraryReportSequence(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLibraryReportSequence, opts...).ToFunc() +} + +// BySentinelInfoField orders the results by sentinel_info field. +func BySentinelInfoField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSentinelInfoStep(), sql.OrderByField(field, opts...)) + } +} +func newSentinelInfoStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SentinelInfoInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, SentinelInfoTable, SentinelInfoColumn), + ) +} diff --git a/internal/data/internal/ent/sentinellibrary/where.go b/internal/data/internal/ent/sentinellibrary/where.go new file mode 100644 index 00000000..637c8728 --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary/where.go @@ -0,0 +1,381 @@ +// Code generated by ent, DO NOT EDIT. + +package sentinellibrary + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/model" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLTE(FieldID, id)) +} + +// SentinelInfoID applies equality check predicate on the "sentinel_info_id" field. It's identical to SentinelInfoIDEQ. +func SentinelInfoID(v model.InternalID) predicate.SentinelLibrary { + vc := int64(v) + return predicate.SentinelLibrary(sql.FieldEQ(FieldSentinelInfoID, vc)) +} + +// ReportedID applies equality check predicate on the "reported_id" field. It's identical to ReportedIDEQ. +func ReportedID(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldReportedID, v)) +} + +// DownloadBasePath applies equality check predicate on the "download_base_path" field. It's identical to DownloadBasePathEQ. +func DownloadBasePath(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldDownloadBasePath, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldCreatedAt, v)) +} + +// LibraryReportSequence applies equality check predicate on the "library_report_sequence" field. It's identical to LibraryReportSequenceEQ. +func LibraryReportSequence(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldLibraryReportSequence, v)) +} + +// SentinelInfoIDEQ applies the EQ predicate on the "sentinel_info_id" field. +func SentinelInfoIDEQ(v model.InternalID) predicate.SentinelLibrary { + vc := int64(v) + return predicate.SentinelLibrary(sql.FieldEQ(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDNEQ applies the NEQ predicate on the "sentinel_info_id" field. +func SentinelInfoIDNEQ(v model.InternalID) predicate.SentinelLibrary { + vc := int64(v) + return predicate.SentinelLibrary(sql.FieldNEQ(FieldSentinelInfoID, vc)) +} + +// SentinelInfoIDIn applies the In predicate on the "sentinel_info_id" field. +func SentinelInfoIDIn(vs ...model.InternalID) predicate.SentinelLibrary { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelLibrary(sql.FieldIn(FieldSentinelInfoID, v...)) +} + +// SentinelInfoIDNotIn applies the NotIn predicate on the "sentinel_info_id" field. +func SentinelInfoIDNotIn(vs ...model.InternalID) predicate.SentinelLibrary { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelLibrary(sql.FieldNotIn(FieldSentinelInfoID, v...)) +} + +// ReportedIDEQ applies the EQ predicate on the "reported_id" field. +func ReportedIDEQ(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldReportedID, v)) +} + +// ReportedIDNEQ applies the NEQ predicate on the "reported_id" field. +func ReportedIDNEQ(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNEQ(FieldReportedID, v)) +} + +// ReportedIDIn applies the In predicate on the "reported_id" field. +func ReportedIDIn(vs ...int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldIn(FieldReportedID, vs...)) +} + +// ReportedIDNotIn applies the NotIn predicate on the "reported_id" field. +func ReportedIDNotIn(vs ...int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNotIn(FieldReportedID, vs...)) +} + +// ReportedIDGT applies the GT predicate on the "reported_id" field. +func ReportedIDGT(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGT(FieldReportedID, v)) +} + +// ReportedIDGTE applies the GTE predicate on the "reported_id" field. +func ReportedIDGTE(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGTE(FieldReportedID, v)) +} + +// ReportedIDLT applies the LT predicate on the "reported_id" field. +func ReportedIDLT(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLT(FieldReportedID, v)) +} + +// ReportedIDLTE applies the LTE predicate on the "reported_id" field. +func ReportedIDLTE(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLTE(FieldReportedID, v)) +} + +// DownloadBasePathEQ applies the EQ predicate on the "download_base_path" field. +func DownloadBasePathEQ(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldDownloadBasePath, v)) +} + +// DownloadBasePathNEQ applies the NEQ predicate on the "download_base_path" field. +func DownloadBasePathNEQ(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNEQ(FieldDownloadBasePath, v)) +} + +// DownloadBasePathIn applies the In predicate on the "download_base_path" field. +func DownloadBasePathIn(vs ...string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldIn(FieldDownloadBasePath, vs...)) +} + +// DownloadBasePathNotIn applies the NotIn predicate on the "download_base_path" field. +func DownloadBasePathNotIn(vs ...string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNotIn(FieldDownloadBasePath, vs...)) +} + +// DownloadBasePathGT applies the GT predicate on the "download_base_path" field. +func DownloadBasePathGT(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGT(FieldDownloadBasePath, v)) +} + +// DownloadBasePathGTE applies the GTE predicate on the "download_base_path" field. +func DownloadBasePathGTE(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGTE(FieldDownloadBasePath, v)) +} + +// DownloadBasePathLT applies the LT predicate on the "download_base_path" field. +func DownloadBasePathLT(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLT(FieldDownloadBasePath, v)) +} + +// DownloadBasePathLTE applies the LTE predicate on the "download_base_path" field. +func DownloadBasePathLTE(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLTE(FieldDownloadBasePath, v)) +} + +// DownloadBasePathContains applies the Contains predicate on the "download_base_path" field. +func DownloadBasePathContains(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldContains(FieldDownloadBasePath, v)) +} + +// DownloadBasePathHasPrefix applies the HasPrefix predicate on the "download_base_path" field. +func DownloadBasePathHasPrefix(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldHasPrefix(FieldDownloadBasePath, v)) +} + +// DownloadBasePathHasSuffix applies the HasSuffix predicate on the "download_base_path" field. +func DownloadBasePathHasSuffix(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldHasSuffix(FieldDownloadBasePath, v)) +} + +// DownloadBasePathEqualFold applies the EqualFold predicate on the "download_base_path" field. +func DownloadBasePathEqualFold(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEqualFold(FieldDownloadBasePath, v)) +} + +// DownloadBasePathContainsFold applies the ContainsFold predicate on the "download_base_path" field. +func DownloadBasePathContainsFold(v string) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldContainsFold(FieldDownloadBasePath, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLTE(FieldCreatedAt, v)) +} + +// LibraryReportSequenceEQ applies the EQ predicate on the "library_report_sequence" field. +func LibraryReportSequenceEQ(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldLibraryReportSequence, v)) +} + +// LibraryReportSequenceNEQ applies the NEQ predicate on the "library_report_sequence" field. +func LibraryReportSequenceNEQ(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNEQ(FieldLibraryReportSequence, v)) +} + +// LibraryReportSequenceIn applies the In predicate on the "library_report_sequence" field. +func LibraryReportSequenceIn(vs ...int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldIn(FieldLibraryReportSequence, vs...)) +} + +// LibraryReportSequenceNotIn applies the NotIn predicate on the "library_report_sequence" field. +func LibraryReportSequenceNotIn(vs ...int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNotIn(FieldLibraryReportSequence, vs...)) +} + +// LibraryReportSequenceGT applies the GT predicate on the "library_report_sequence" field. +func LibraryReportSequenceGT(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGT(FieldLibraryReportSequence, v)) +} + +// LibraryReportSequenceGTE applies the GTE predicate on the "library_report_sequence" field. +func LibraryReportSequenceGTE(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGTE(FieldLibraryReportSequence, v)) +} + +// LibraryReportSequenceLT applies the LT predicate on the "library_report_sequence" field. +func LibraryReportSequenceLT(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLT(FieldLibraryReportSequence, v)) +} + +// LibraryReportSequenceLTE applies the LTE predicate on the "library_report_sequence" field. +func LibraryReportSequenceLTE(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLTE(FieldLibraryReportSequence, v)) +} + +// HasSentinelInfo applies the HasEdge predicate on the "sentinel_info" edge. +func HasSentinelInfo() predicate.SentinelLibrary { + return predicate.SentinelLibrary(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, SentinelInfoTable, SentinelInfoColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSentinelInfoWith applies the HasEdge predicate on the "sentinel_info" edge with a given conditions (other predicates). +func HasSentinelInfoWith(preds ...predicate.SentinelInfo) predicate.SentinelLibrary { + return predicate.SentinelLibrary(func(s *sql.Selector) { + step := newSentinelInfoStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.SentinelLibrary) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.SentinelLibrary) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.SentinelLibrary) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.NotPredicates(p)) +} diff --git a/internal/data/internal/ent/sentinellibrary_create.go b/internal/data/internal/ent/sentinellibrary_create.go new file mode 100644 index 00000000..e3cf2537 --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary_create.go @@ -0,0 +1,813 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelLibraryCreate is the builder for creating a SentinelLibrary entity. +type SentinelLibraryCreate struct { + config + mutation *SentinelLibraryMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (slc *SentinelLibraryCreate) SetSentinelInfoID(mi model.InternalID) *SentinelLibraryCreate { + slc.mutation.SetSentinelInfoID(mi) + return slc +} + +// SetReportedID sets the "reported_id" field. +func (slc *SentinelLibraryCreate) SetReportedID(i int64) *SentinelLibraryCreate { + slc.mutation.SetReportedID(i) + return slc +} + +// SetDownloadBasePath sets the "download_base_path" field. +func (slc *SentinelLibraryCreate) SetDownloadBasePath(s string) *SentinelLibraryCreate { + slc.mutation.SetDownloadBasePath(s) + return slc +} + +// SetUpdatedAt sets the "updated_at" field. +func (slc *SentinelLibraryCreate) SetUpdatedAt(t time.Time) *SentinelLibraryCreate { + slc.mutation.SetUpdatedAt(t) + return slc +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (slc *SentinelLibraryCreate) SetNillableUpdatedAt(t *time.Time) *SentinelLibraryCreate { + if t != nil { + slc.SetUpdatedAt(*t) + } + return slc +} + +// SetCreatedAt sets the "created_at" field. +func (slc *SentinelLibraryCreate) SetCreatedAt(t time.Time) *SentinelLibraryCreate { + slc.mutation.SetCreatedAt(t) + return slc +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (slc *SentinelLibraryCreate) SetNillableCreatedAt(t *time.Time) *SentinelLibraryCreate { + if t != nil { + slc.SetCreatedAt(*t) + } + return slc +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (slc *SentinelLibraryCreate) SetLibraryReportSequence(i int64) *SentinelLibraryCreate { + slc.mutation.SetLibraryReportSequence(i) + return slc +} + +// SetSentinelInfo sets the "sentinel_info" edge to the SentinelInfo entity. +func (slc *SentinelLibraryCreate) SetSentinelInfo(s *SentinelInfo) *SentinelLibraryCreate { + return slc.SetSentinelInfoID(s.ID) +} + +// Mutation returns the SentinelLibraryMutation object of the builder. +func (slc *SentinelLibraryCreate) Mutation() *SentinelLibraryMutation { + return slc.mutation +} + +// Save creates the SentinelLibrary in the database. +func (slc *SentinelLibraryCreate) Save(ctx context.Context) (*SentinelLibrary, error) { + slc.defaults() + return withHooks(ctx, slc.sqlSave, slc.mutation, slc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (slc *SentinelLibraryCreate) SaveX(ctx context.Context) *SentinelLibrary { + v, err := slc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (slc *SentinelLibraryCreate) Exec(ctx context.Context) error { + _, err := slc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (slc *SentinelLibraryCreate) ExecX(ctx context.Context) { + if err := slc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (slc *SentinelLibraryCreate) defaults() { + if _, ok := slc.mutation.UpdatedAt(); !ok { + v := sentinellibrary.DefaultUpdatedAt() + slc.mutation.SetUpdatedAt(v) + } + if _, ok := slc.mutation.CreatedAt(); !ok { + v := sentinellibrary.DefaultCreatedAt() + slc.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (slc *SentinelLibraryCreate) check() error { + if _, ok := slc.mutation.SentinelInfoID(); !ok { + return &ValidationError{Name: "sentinel_info_id", err: errors.New(`ent: missing required field "SentinelLibrary.sentinel_info_id"`)} + } + if _, ok := slc.mutation.ReportedID(); !ok { + return &ValidationError{Name: "reported_id", err: errors.New(`ent: missing required field "SentinelLibrary.reported_id"`)} + } + if _, ok := slc.mutation.DownloadBasePath(); !ok { + return &ValidationError{Name: "download_base_path", err: errors.New(`ent: missing required field "SentinelLibrary.download_base_path"`)} + } + if _, ok := slc.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "SentinelLibrary.updated_at"`)} + } + if _, ok := slc.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SentinelLibrary.created_at"`)} + } + if _, ok := slc.mutation.LibraryReportSequence(); !ok { + return &ValidationError{Name: "library_report_sequence", err: errors.New(`ent: missing required field "SentinelLibrary.library_report_sequence"`)} + } + if len(slc.mutation.SentinelInfoIDs()) == 0 { + return &ValidationError{Name: "sentinel_info", err: errors.New(`ent: missing required edge "SentinelLibrary.sentinel_info"`)} + } + return nil +} + +func (slc *SentinelLibraryCreate) sqlSave(ctx context.Context) (*SentinelLibrary, error) { + if err := slc.check(); err != nil { + return nil, err + } + _node, _spec := slc.createSpec() + if err := sqlgraph.CreateNode(ctx, slc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + slc.mutation.id = &_node.ID + slc.mutation.done = true + return _node, nil +} + +func (slc *SentinelLibraryCreate) createSpec() (*SentinelLibrary, *sqlgraph.CreateSpec) { + var ( + _node = &SentinelLibrary{config: slc.config} + _spec = sqlgraph.NewCreateSpec(sentinellibrary.Table, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt)) + ) + _spec.OnConflict = slc.conflict + if value, ok := slc.mutation.ReportedID(); ok { + _spec.SetField(sentinellibrary.FieldReportedID, field.TypeInt64, value) + _node.ReportedID = value + } + if value, ok := slc.mutation.DownloadBasePath(); ok { + _spec.SetField(sentinellibrary.FieldDownloadBasePath, field.TypeString, value) + _node.DownloadBasePath = value + } + if value, ok := slc.mutation.UpdatedAt(); ok { + _spec.SetField(sentinellibrary.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := slc.mutation.CreatedAt(); ok { + _spec.SetField(sentinellibrary.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := slc.mutation.LibraryReportSequence(); ok { + _spec.SetField(sentinellibrary.FieldLibraryReportSequence, field.TypeInt64, value) + _node.LibraryReportSequence = value + } + if nodes := slc.mutation.SentinelInfoIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinellibrary.SentinelInfoTable, + Columns: []string{sentinellibrary.SentinelInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.SentinelInfoID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.SentinelLibrary.Create(). +// SetSentinelInfoID(v). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.SentinelLibraryUpsert) { +// SetSentinelInfoID(v+v). +// }). +// Exec(ctx) +func (slc *SentinelLibraryCreate) OnConflict(opts ...sql.ConflictOption) *SentinelLibraryUpsertOne { + slc.conflict = opts + return &SentinelLibraryUpsertOne{ + create: slc, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.SentinelLibrary.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (slc *SentinelLibraryCreate) OnConflictColumns(columns ...string) *SentinelLibraryUpsertOne { + slc.conflict = append(slc.conflict, sql.ConflictColumns(columns...)) + return &SentinelLibraryUpsertOne{ + create: slc, + } +} + +type ( + // SentinelLibraryUpsertOne is the builder for "upsert"-ing + // one SentinelLibrary node. + SentinelLibraryUpsertOne struct { + create *SentinelLibraryCreate + } + + // SentinelLibraryUpsert is the "OnConflict" setter. + SentinelLibraryUpsert struct { + *sql.UpdateSet + } +) + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (u *SentinelLibraryUpsert) SetSentinelInfoID(v model.InternalID) *SentinelLibraryUpsert { + u.Set(sentinellibrary.FieldSentinelInfoID, v) + return u +} + +// UpdateSentinelInfoID sets the "sentinel_info_id" field to the value that was provided on create. +func (u *SentinelLibraryUpsert) UpdateSentinelInfoID() *SentinelLibraryUpsert { + u.SetExcluded(sentinellibrary.FieldSentinelInfoID) + return u +} + +// SetReportedID sets the "reported_id" field. +func (u *SentinelLibraryUpsert) SetReportedID(v int64) *SentinelLibraryUpsert { + u.Set(sentinellibrary.FieldReportedID, v) + return u +} + +// UpdateReportedID sets the "reported_id" field to the value that was provided on create. +func (u *SentinelLibraryUpsert) UpdateReportedID() *SentinelLibraryUpsert { + u.SetExcluded(sentinellibrary.FieldReportedID) + return u +} + +// AddReportedID adds v to the "reported_id" field. +func (u *SentinelLibraryUpsert) AddReportedID(v int64) *SentinelLibraryUpsert { + u.Add(sentinellibrary.FieldReportedID, v) + return u +} + +// SetDownloadBasePath sets the "download_base_path" field. +func (u *SentinelLibraryUpsert) SetDownloadBasePath(v string) *SentinelLibraryUpsert { + u.Set(sentinellibrary.FieldDownloadBasePath, v) + return u +} + +// UpdateDownloadBasePath sets the "download_base_path" field to the value that was provided on create. +func (u *SentinelLibraryUpsert) UpdateDownloadBasePath() *SentinelLibraryUpsert { + u.SetExcluded(sentinellibrary.FieldDownloadBasePath) + return u +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelLibraryUpsert) SetUpdatedAt(v time.Time) *SentinelLibraryUpsert { + u.Set(sentinellibrary.FieldUpdatedAt, v) + return u +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelLibraryUpsert) UpdateUpdatedAt() *SentinelLibraryUpsert { + u.SetExcluded(sentinellibrary.FieldUpdatedAt) + return u +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelLibraryUpsert) SetCreatedAt(v time.Time) *SentinelLibraryUpsert { + u.Set(sentinellibrary.FieldCreatedAt, v) + return u +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelLibraryUpsert) UpdateCreatedAt() *SentinelLibraryUpsert { + u.SetExcluded(sentinellibrary.FieldCreatedAt) + return u +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (u *SentinelLibraryUpsert) SetLibraryReportSequence(v int64) *SentinelLibraryUpsert { + u.Set(sentinellibrary.FieldLibraryReportSequence, v) + return u +} + +// UpdateLibraryReportSequence sets the "library_report_sequence" field to the value that was provided on create. +func (u *SentinelLibraryUpsert) UpdateLibraryReportSequence() *SentinelLibraryUpsert { + u.SetExcluded(sentinellibrary.FieldLibraryReportSequence) + return u +} + +// AddLibraryReportSequence adds v to the "library_report_sequence" field. +func (u *SentinelLibraryUpsert) AddLibraryReportSequence(v int64) *SentinelLibraryUpsert { + u.Add(sentinellibrary.FieldLibraryReportSequence, v) + return u +} + +// UpdateNewValues updates the mutable fields using the new values that were set on create. +// Using this option is equivalent to using: +// +// client.SentinelLibrary.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *SentinelLibraryUpsertOne) UpdateNewValues() *SentinelLibraryUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.SentinelLibrary.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SentinelLibraryUpsertOne) Ignore() *SentinelLibraryUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *SentinelLibraryUpsertOne) DoNothing() *SentinelLibraryUpsertOne { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SentinelLibraryCreate.OnConflict +// documentation for more info. +func (u *SentinelLibraryUpsertOne) Update(set func(*SentinelLibraryUpsert)) *SentinelLibraryUpsertOne { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SentinelLibraryUpsert{UpdateSet: update}) + })) + return u +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (u *SentinelLibraryUpsertOne) SetSentinelInfoID(v model.InternalID) *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetSentinelInfoID(v) + }) +} + +// UpdateSentinelInfoID sets the "sentinel_info_id" field to the value that was provided on create. +func (u *SentinelLibraryUpsertOne) UpdateSentinelInfoID() *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateSentinelInfoID() + }) +} + +// SetReportedID sets the "reported_id" field. +func (u *SentinelLibraryUpsertOne) SetReportedID(v int64) *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetReportedID(v) + }) +} + +// AddReportedID adds v to the "reported_id" field. +func (u *SentinelLibraryUpsertOne) AddReportedID(v int64) *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.AddReportedID(v) + }) +} + +// UpdateReportedID sets the "reported_id" field to the value that was provided on create. +func (u *SentinelLibraryUpsertOne) UpdateReportedID() *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateReportedID() + }) +} + +// SetDownloadBasePath sets the "download_base_path" field. +func (u *SentinelLibraryUpsertOne) SetDownloadBasePath(v string) *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetDownloadBasePath(v) + }) +} + +// UpdateDownloadBasePath sets the "download_base_path" field to the value that was provided on create. +func (u *SentinelLibraryUpsertOne) UpdateDownloadBasePath() *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateDownloadBasePath() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelLibraryUpsertOne) SetUpdatedAt(v time.Time) *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelLibraryUpsertOne) UpdateUpdatedAt() *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelLibraryUpsertOne) SetCreatedAt(v time.Time) *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelLibraryUpsertOne) UpdateCreatedAt() *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (u *SentinelLibraryUpsertOne) SetLibraryReportSequence(v int64) *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetLibraryReportSequence(v) + }) +} + +// AddLibraryReportSequence adds v to the "library_report_sequence" field. +func (u *SentinelLibraryUpsertOne) AddLibraryReportSequence(v int64) *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.AddLibraryReportSequence(v) + }) +} + +// UpdateLibraryReportSequence sets the "library_report_sequence" field to the value that was provided on create. +func (u *SentinelLibraryUpsertOne) UpdateLibraryReportSequence() *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateLibraryReportSequence() + }) +} + +// Exec executes the query. +func (u *SentinelLibraryUpsertOne) Exec(ctx context.Context) error { + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for SentinelLibraryCreate.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SentinelLibraryUpsertOne) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} + +// Exec executes the UPSERT query and returns the inserted/updated ID. +func (u *SentinelLibraryUpsertOne) ID(ctx context.Context) (id int, err error) { + node, err := u.create.Save(ctx) + if err != nil { + return id, err + } + return node.ID, nil +} + +// IDX is like ID, but panics if an error occurs. +func (u *SentinelLibraryUpsertOne) IDX(ctx context.Context) int { + id, err := u.ID(ctx) + if err != nil { + panic(err) + } + return id +} + +// SentinelLibraryCreateBulk is the builder for creating many SentinelLibrary entities in bulk. +type SentinelLibraryCreateBulk struct { + config + err error + builders []*SentinelLibraryCreate + conflict []sql.ConflictOption +} + +// Save creates the SentinelLibrary entities in the database. +func (slcb *SentinelLibraryCreateBulk) Save(ctx context.Context) ([]*SentinelLibrary, error) { + if slcb.err != nil { + return nil, slcb.err + } + specs := make([]*sqlgraph.CreateSpec, len(slcb.builders)) + nodes := make([]*SentinelLibrary, len(slcb.builders)) + mutators := make([]Mutator, len(slcb.builders)) + for i := range slcb.builders { + func(i int, root context.Context) { + builder := slcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*SentinelLibraryMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, slcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + spec.OnConflict = slcb.conflict + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, slcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + if specs[i].ID.Value != nil { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(id) + } + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, slcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (slcb *SentinelLibraryCreateBulk) SaveX(ctx context.Context) []*SentinelLibrary { + v, err := slcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (slcb *SentinelLibraryCreateBulk) Exec(ctx context.Context) error { + _, err := slcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (slcb *SentinelLibraryCreateBulk) ExecX(ctx context.Context) { + if err := slcb.Exec(ctx); err != nil { + panic(err) + } +} + +// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause +// of the `INSERT` statement. For example: +// +// client.SentinelLibrary.CreateBulk(builders...). +// OnConflict( +// // Update the row with the new values +// // the was proposed for insertion. +// sql.ResolveWithNewValues(), +// ). +// // Override some of the fields with custom +// // update values. +// Update(func(u *ent.SentinelLibraryUpsert) { +// SetSentinelInfoID(v+v). +// }). +// Exec(ctx) +func (slcb *SentinelLibraryCreateBulk) OnConflict(opts ...sql.ConflictOption) *SentinelLibraryUpsertBulk { + slcb.conflict = opts + return &SentinelLibraryUpsertBulk{ + create: slcb, + } +} + +// OnConflictColumns calls `OnConflict` and configures the columns +// as conflict target. Using this option is equivalent to using: +// +// client.SentinelLibrary.Create(). +// OnConflict(sql.ConflictColumns(columns...)). +// Exec(ctx) +func (slcb *SentinelLibraryCreateBulk) OnConflictColumns(columns ...string) *SentinelLibraryUpsertBulk { + slcb.conflict = append(slcb.conflict, sql.ConflictColumns(columns...)) + return &SentinelLibraryUpsertBulk{ + create: slcb, + } +} + +// SentinelLibraryUpsertBulk is the builder for "upsert"-ing +// a bulk of SentinelLibrary nodes. +type SentinelLibraryUpsertBulk struct { + create *SentinelLibraryCreateBulk +} + +// UpdateNewValues updates the mutable fields using the new values that +// were set on create. Using this option is equivalent to using: +// +// client.SentinelLibrary.Create(). +// OnConflict( +// sql.ResolveWithNewValues(), +// ). +// Exec(ctx) +func (u *SentinelLibraryUpsertBulk) UpdateNewValues() *SentinelLibraryUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) + return u +} + +// Ignore sets each column to itself in case of conflict. +// Using this option is equivalent to using: +// +// client.SentinelLibrary.Create(). +// OnConflict(sql.ResolveWithIgnore()). +// Exec(ctx) +func (u *SentinelLibraryUpsertBulk) Ignore() *SentinelLibraryUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) + return u +} + +// DoNothing configures the conflict_action to `DO NOTHING`. +// Supported only by SQLite and PostgreSQL. +func (u *SentinelLibraryUpsertBulk) DoNothing() *SentinelLibraryUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.DoNothing()) + return u +} + +// Update allows overriding fields `UPDATE` values. See the SentinelLibraryCreateBulk.OnConflict +// documentation for more info. +func (u *SentinelLibraryUpsertBulk) Update(set func(*SentinelLibraryUpsert)) *SentinelLibraryUpsertBulk { + u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { + set(&SentinelLibraryUpsert{UpdateSet: update}) + })) + return u +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (u *SentinelLibraryUpsertBulk) SetSentinelInfoID(v model.InternalID) *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetSentinelInfoID(v) + }) +} + +// UpdateSentinelInfoID sets the "sentinel_info_id" field to the value that was provided on create. +func (u *SentinelLibraryUpsertBulk) UpdateSentinelInfoID() *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateSentinelInfoID() + }) +} + +// SetReportedID sets the "reported_id" field. +func (u *SentinelLibraryUpsertBulk) SetReportedID(v int64) *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetReportedID(v) + }) +} + +// AddReportedID adds v to the "reported_id" field. +func (u *SentinelLibraryUpsertBulk) AddReportedID(v int64) *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.AddReportedID(v) + }) +} + +// UpdateReportedID sets the "reported_id" field to the value that was provided on create. +func (u *SentinelLibraryUpsertBulk) UpdateReportedID() *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateReportedID() + }) +} + +// SetDownloadBasePath sets the "download_base_path" field. +func (u *SentinelLibraryUpsertBulk) SetDownloadBasePath(v string) *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetDownloadBasePath(v) + }) +} + +// UpdateDownloadBasePath sets the "download_base_path" field to the value that was provided on create. +func (u *SentinelLibraryUpsertBulk) UpdateDownloadBasePath() *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateDownloadBasePath() + }) +} + +// SetUpdatedAt sets the "updated_at" field. +func (u *SentinelLibraryUpsertBulk) SetUpdatedAt(v time.Time) *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetUpdatedAt(v) + }) +} + +// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create. +func (u *SentinelLibraryUpsertBulk) UpdateUpdatedAt() *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateUpdatedAt() + }) +} + +// SetCreatedAt sets the "created_at" field. +func (u *SentinelLibraryUpsertBulk) SetCreatedAt(v time.Time) *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetCreatedAt(v) + }) +} + +// UpdateCreatedAt sets the "created_at" field to the value that was provided on create. +func (u *SentinelLibraryUpsertBulk) UpdateCreatedAt() *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateCreatedAt() + }) +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (u *SentinelLibraryUpsertBulk) SetLibraryReportSequence(v int64) *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetLibraryReportSequence(v) + }) +} + +// AddLibraryReportSequence adds v to the "library_report_sequence" field. +func (u *SentinelLibraryUpsertBulk) AddLibraryReportSequence(v int64) *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.AddLibraryReportSequence(v) + }) +} + +// UpdateLibraryReportSequence sets the "library_report_sequence" field to the value that was provided on create. +func (u *SentinelLibraryUpsertBulk) UpdateLibraryReportSequence() *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateLibraryReportSequence() + }) +} + +// Exec executes the query. +func (u *SentinelLibraryUpsertBulk) Exec(ctx context.Context) error { + if u.create.err != nil { + return u.create.err + } + for i, b := range u.create.builders { + if len(b.conflict) != 0 { + return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the SentinelLibraryCreateBulk instead", i) + } + } + if len(u.create.conflict) == 0 { + return errors.New("ent: missing options for SentinelLibraryCreateBulk.OnConflict") + } + return u.create.Exec(ctx) +} + +// ExecX is like Exec, but panics if an error occurs. +func (u *SentinelLibraryUpsertBulk) ExecX(ctx context.Context) { + if err := u.create.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/data/internal/ent/sentinellibrary_delete.go b/internal/data/internal/ent/sentinellibrary_delete.go new file mode 100644 index 00000000..bf19e24f --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" +) + +// SentinelLibraryDelete is the builder for deleting a SentinelLibrary entity. +type SentinelLibraryDelete struct { + config + hooks []Hook + mutation *SentinelLibraryMutation +} + +// Where appends a list predicates to the SentinelLibraryDelete builder. +func (sld *SentinelLibraryDelete) Where(ps ...predicate.SentinelLibrary) *SentinelLibraryDelete { + sld.mutation.Where(ps...) + return sld +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (sld *SentinelLibraryDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, sld.sqlExec, sld.mutation, sld.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (sld *SentinelLibraryDelete) ExecX(ctx context.Context) int { + n, err := sld.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (sld *SentinelLibraryDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(sentinellibrary.Table, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt)) + if ps := sld.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, sld.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + sld.mutation.done = true + return affected, err +} + +// SentinelLibraryDeleteOne is the builder for deleting a single SentinelLibrary entity. +type SentinelLibraryDeleteOne struct { + sld *SentinelLibraryDelete +} + +// Where appends a list predicates to the SentinelLibraryDelete builder. +func (sldo *SentinelLibraryDeleteOne) Where(ps ...predicate.SentinelLibrary) *SentinelLibraryDeleteOne { + sldo.sld.mutation.Where(ps...) + return sldo +} + +// Exec executes the deletion query. +func (sldo *SentinelLibraryDeleteOne) Exec(ctx context.Context) error { + n, err := sldo.sld.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{sentinellibrary.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (sldo *SentinelLibraryDeleteOne) ExecX(ctx context.Context) { + if err := sldo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/internal/data/internal/ent/sentinellibrary_query.go b/internal/data/internal/ent/sentinellibrary_query.go new file mode 100644 index 00000000..a93ad0a5 --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary_query.go @@ -0,0 +1,607 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelLibraryQuery is the builder for querying SentinelLibrary entities. +type SentinelLibraryQuery struct { + config + ctx *QueryContext + order []sentinellibrary.OrderOption + inters []Interceptor + predicates []predicate.SentinelLibrary + withSentinelInfo *SentinelInfoQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the SentinelLibraryQuery builder. +func (slq *SentinelLibraryQuery) Where(ps ...predicate.SentinelLibrary) *SentinelLibraryQuery { + slq.predicates = append(slq.predicates, ps...) + return slq +} + +// Limit the number of records to be returned by this query. +func (slq *SentinelLibraryQuery) Limit(limit int) *SentinelLibraryQuery { + slq.ctx.Limit = &limit + return slq +} + +// Offset to start from. +func (slq *SentinelLibraryQuery) Offset(offset int) *SentinelLibraryQuery { + slq.ctx.Offset = &offset + return slq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (slq *SentinelLibraryQuery) Unique(unique bool) *SentinelLibraryQuery { + slq.ctx.Unique = &unique + return slq +} + +// Order specifies how the records should be ordered. +func (slq *SentinelLibraryQuery) Order(o ...sentinellibrary.OrderOption) *SentinelLibraryQuery { + slq.order = append(slq.order, o...) + return slq +} + +// QuerySentinelInfo chains the current query on the "sentinel_info" edge. +func (slq *SentinelLibraryQuery) QuerySentinelInfo() *SentinelInfoQuery { + query := (&SentinelInfoClient{config: slq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := slq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := slq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(sentinellibrary.Table, sentinellibrary.FieldID, selector), + sqlgraph.To(sentinelinfo.Table, sentinelinfo.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, sentinellibrary.SentinelInfoTable, sentinellibrary.SentinelInfoColumn), + ) + fromU = sqlgraph.SetNeighbors(slq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first SentinelLibrary entity from the query. +// Returns a *NotFoundError when no SentinelLibrary was found. +func (slq *SentinelLibraryQuery) First(ctx context.Context) (*SentinelLibrary, error) { + nodes, err := slq.Limit(1).All(setContextOp(ctx, slq.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{sentinellibrary.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (slq *SentinelLibraryQuery) FirstX(ctx context.Context) *SentinelLibrary { + node, err := slq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first SentinelLibrary ID from the query. +// Returns a *NotFoundError when no SentinelLibrary ID was found. +func (slq *SentinelLibraryQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = slq.Limit(1).IDs(setContextOp(ctx, slq.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{sentinellibrary.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (slq *SentinelLibraryQuery) FirstIDX(ctx context.Context) int { + id, err := slq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single SentinelLibrary entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one SentinelLibrary entity is found. +// Returns a *NotFoundError when no SentinelLibrary entities are found. +func (slq *SentinelLibraryQuery) Only(ctx context.Context) (*SentinelLibrary, error) { + nodes, err := slq.Limit(2).All(setContextOp(ctx, slq.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{sentinellibrary.Label} + default: + return nil, &NotSingularError{sentinellibrary.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (slq *SentinelLibraryQuery) OnlyX(ctx context.Context) *SentinelLibrary { + node, err := slq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only SentinelLibrary ID in the query. +// Returns a *NotSingularError when more than one SentinelLibrary ID is found. +// Returns a *NotFoundError when no entities are found. +func (slq *SentinelLibraryQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = slq.Limit(2).IDs(setContextOp(ctx, slq.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{sentinellibrary.Label} + default: + err = &NotSingularError{sentinellibrary.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (slq *SentinelLibraryQuery) OnlyIDX(ctx context.Context) int { + id, err := slq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of SentinelLibraries. +func (slq *SentinelLibraryQuery) All(ctx context.Context) ([]*SentinelLibrary, error) { + ctx = setContextOp(ctx, slq.ctx, ent.OpQueryAll) + if err := slq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*SentinelLibrary, *SentinelLibraryQuery]() + return withInterceptors[[]*SentinelLibrary](ctx, slq, qr, slq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (slq *SentinelLibraryQuery) AllX(ctx context.Context) []*SentinelLibrary { + nodes, err := slq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of SentinelLibrary IDs. +func (slq *SentinelLibraryQuery) IDs(ctx context.Context) (ids []int, err error) { + if slq.ctx.Unique == nil && slq.path != nil { + slq.Unique(true) + } + ctx = setContextOp(ctx, slq.ctx, ent.OpQueryIDs) + if err = slq.Select(sentinellibrary.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (slq *SentinelLibraryQuery) IDsX(ctx context.Context) []int { + ids, err := slq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (slq *SentinelLibraryQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, slq.ctx, ent.OpQueryCount) + if err := slq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, slq, querierCount[*SentinelLibraryQuery](), slq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (slq *SentinelLibraryQuery) CountX(ctx context.Context) int { + count, err := slq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (slq *SentinelLibraryQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, slq.ctx, ent.OpQueryExist) + switch _, err := slq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (slq *SentinelLibraryQuery) ExistX(ctx context.Context) bool { + exist, err := slq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the SentinelLibraryQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (slq *SentinelLibraryQuery) Clone() *SentinelLibraryQuery { + if slq == nil { + return nil + } + return &SentinelLibraryQuery{ + config: slq.config, + ctx: slq.ctx.Clone(), + order: append([]sentinellibrary.OrderOption{}, slq.order...), + inters: append([]Interceptor{}, slq.inters...), + predicates: append([]predicate.SentinelLibrary{}, slq.predicates...), + withSentinelInfo: slq.withSentinelInfo.Clone(), + // clone intermediate query. + sql: slq.sql.Clone(), + path: slq.path, + } +} + +// WithSentinelInfo tells the query-builder to eager-load the nodes that are connected to +// the "sentinel_info" edge. The optional arguments are used to configure the query builder of the edge. +func (slq *SentinelLibraryQuery) WithSentinelInfo(opts ...func(*SentinelInfoQuery)) *SentinelLibraryQuery { + query := (&SentinelInfoClient{config: slq.config}).Query() + for _, opt := range opts { + opt(query) + } + slq.withSentinelInfo = query + return slq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.SentinelLibrary.Query(). +// GroupBy(sentinellibrary.FieldSentinelInfoID). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (slq *SentinelLibraryQuery) GroupBy(field string, fields ...string) *SentinelLibraryGroupBy { + slq.ctx.Fields = append([]string{field}, fields...) + grbuild := &SentinelLibraryGroupBy{build: slq} + grbuild.flds = &slq.ctx.Fields + grbuild.label = sentinellibrary.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` +// } +// +// client.SentinelLibrary.Query(). +// Select(sentinellibrary.FieldSentinelInfoID). +// Scan(ctx, &v) +func (slq *SentinelLibraryQuery) Select(fields ...string) *SentinelLibrarySelect { + slq.ctx.Fields = append(slq.ctx.Fields, fields...) + sbuild := &SentinelLibrarySelect{SentinelLibraryQuery: slq} + sbuild.label = sentinellibrary.Label + sbuild.flds, sbuild.scan = &slq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a SentinelLibrarySelect configured with the given aggregations. +func (slq *SentinelLibraryQuery) Aggregate(fns ...AggregateFunc) *SentinelLibrarySelect { + return slq.Select().Aggregate(fns...) +} + +func (slq *SentinelLibraryQuery) prepareQuery(ctx context.Context) error { + for _, inter := range slq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, slq); err != nil { + return err + } + } + } + for _, f := range slq.ctx.Fields { + if !sentinellibrary.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if slq.path != nil { + prev, err := slq.path(ctx) + if err != nil { + return err + } + slq.sql = prev + } + return nil +} + +func (slq *SentinelLibraryQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SentinelLibrary, error) { + var ( + nodes = []*SentinelLibrary{} + _spec = slq.querySpec() + loadedTypes = [1]bool{ + slq.withSentinelInfo != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*SentinelLibrary).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &SentinelLibrary{config: slq.config} + nodes = append(nodes, node) + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, slq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + if query := slq.withSentinelInfo; query != nil { + if err := slq.loadSentinelInfo(ctx, query, nodes, nil, + func(n *SentinelLibrary, e *SentinelInfo) { n.Edges.SentinelInfo = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (slq *SentinelLibraryQuery) loadSentinelInfo(ctx context.Context, query *SentinelInfoQuery, nodes []*SentinelLibrary, init func(*SentinelLibrary), assign func(*SentinelLibrary, *SentinelInfo)) error { + ids := make([]model.InternalID, 0, len(nodes)) + nodeids := make(map[model.InternalID][]*SentinelLibrary) + for i := range nodes { + fk := nodes[i].SentinelInfoID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(sentinelinfo.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return fmt.Errorf(`unexpected foreign-key "sentinel_info_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} + +func (slq *SentinelLibraryQuery) sqlCount(ctx context.Context) (int, error) { + _spec := slq.querySpec() + _spec.Node.Columns = slq.ctx.Fields + if len(slq.ctx.Fields) > 0 { + _spec.Unique = slq.ctx.Unique != nil && *slq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, slq.driver, _spec) +} + +func (slq *SentinelLibraryQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(sentinellibrary.Table, sentinellibrary.Columns, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt)) + _spec.From = slq.sql + if unique := slq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if slq.path != nil { + _spec.Unique = true + } + if fields := slq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, sentinellibrary.FieldID) + for i := range fields { + if fields[i] != sentinellibrary.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + if slq.withSentinelInfo != nil { + _spec.Node.AddColumnOnce(sentinellibrary.FieldSentinelInfoID) + } + } + if ps := slq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := slq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := slq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := slq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (slq *SentinelLibraryQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(slq.driver.Dialect()) + t1 := builder.Table(sentinellibrary.Table) + columns := slq.ctx.Fields + if len(columns) == 0 { + columns = sentinellibrary.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if slq.sql != nil { + selector = slq.sql + selector.Select(selector.Columns(columns...)...) + } + if slq.ctx.Unique != nil && *slq.ctx.Unique { + selector.Distinct() + } + for _, p := range slq.predicates { + p(selector) + } + for _, p := range slq.order { + p(selector) + } + if offset := slq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := slq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// SentinelLibraryGroupBy is the group-by builder for SentinelLibrary entities. +type SentinelLibraryGroupBy struct { + selector + build *SentinelLibraryQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (slgb *SentinelLibraryGroupBy) Aggregate(fns ...AggregateFunc) *SentinelLibraryGroupBy { + slgb.fns = append(slgb.fns, fns...) + return slgb +} + +// Scan applies the selector query and scans the result into the given value. +func (slgb *SentinelLibraryGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, slgb.build.ctx, ent.OpQueryGroupBy) + if err := slgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*SentinelLibraryQuery, *SentinelLibraryGroupBy](ctx, slgb.build, slgb, slgb.build.inters, v) +} + +func (slgb *SentinelLibraryGroupBy) sqlScan(ctx context.Context, root *SentinelLibraryQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(slgb.fns)) + for _, fn := range slgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*slgb.flds)+len(slgb.fns)) + for _, f := range *slgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*slgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := slgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// SentinelLibrarySelect is the builder for selecting fields of SentinelLibrary entities. +type SentinelLibrarySelect struct { + *SentinelLibraryQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (sls *SentinelLibrarySelect) Aggregate(fns ...AggregateFunc) *SentinelLibrarySelect { + sls.fns = append(sls.fns, fns...) + return sls +} + +// Scan applies the selector query and scans the result into the given value. +func (sls *SentinelLibrarySelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, sls.ctx, ent.OpQuerySelect) + if err := sls.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*SentinelLibraryQuery, *SentinelLibrarySelect](ctx, sls.SentinelLibraryQuery, sls, sls.inters, v) +} + +func (sls *SentinelLibrarySelect) sqlScan(ctx context.Context, root *SentinelLibraryQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(sls.fns)) + for _, fn := range sls.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*sls.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := sls.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/internal/data/internal/ent/sentinellibrary_update.go b/internal/data/internal/ent/sentinellibrary_update.go new file mode 100644 index 00000000..fecd6d81 --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary_update.go @@ -0,0 +1,520 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" + "github.com/tuihub/librarian/internal/model" +) + +// SentinelLibraryUpdate is the builder for updating SentinelLibrary entities. +type SentinelLibraryUpdate struct { + config + hooks []Hook + mutation *SentinelLibraryMutation +} + +// Where appends a list predicates to the SentinelLibraryUpdate builder. +func (slu *SentinelLibraryUpdate) Where(ps ...predicate.SentinelLibrary) *SentinelLibraryUpdate { + slu.mutation.Where(ps...) + return slu +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (slu *SentinelLibraryUpdate) SetSentinelInfoID(mi model.InternalID) *SentinelLibraryUpdate { + slu.mutation.SetSentinelInfoID(mi) + return slu +} + +// SetNillableSentinelInfoID sets the "sentinel_info_id" field if the given value is not nil. +func (slu *SentinelLibraryUpdate) SetNillableSentinelInfoID(mi *model.InternalID) *SentinelLibraryUpdate { + if mi != nil { + slu.SetSentinelInfoID(*mi) + } + return slu +} + +// SetReportedID sets the "reported_id" field. +func (slu *SentinelLibraryUpdate) SetReportedID(i int64) *SentinelLibraryUpdate { + slu.mutation.ResetReportedID() + slu.mutation.SetReportedID(i) + return slu +} + +// SetNillableReportedID sets the "reported_id" field if the given value is not nil. +func (slu *SentinelLibraryUpdate) SetNillableReportedID(i *int64) *SentinelLibraryUpdate { + if i != nil { + slu.SetReportedID(*i) + } + return slu +} + +// AddReportedID adds i to the "reported_id" field. +func (slu *SentinelLibraryUpdate) AddReportedID(i int64) *SentinelLibraryUpdate { + slu.mutation.AddReportedID(i) + return slu +} + +// SetDownloadBasePath sets the "download_base_path" field. +func (slu *SentinelLibraryUpdate) SetDownloadBasePath(s string) *SentinelLibraryUpdate { + slu.mutation.SetDownloadBasePath(s) + return slu +} + +// SetNillableDownloadBasePath sets the "download_base_path" field if the given value is not nil. +func (slu *SentinelLibraryUpdate) SetNillableDownloadBasePath(s *string) *SentinelLibraryUpdate { + if s != nil { + slu.SetDownloadBasePath(*s) + } + return slu +} + +// SetUpdatedAt sets the "updated_at" field. +func (slu *SentinelLibraryUpdate) SetUpdatedAt(t time.Time) *SentinelLibraryUpdate { + slu.mutation.SetUpdatedAt(t) + return slu +} + +// SetCreatedAt sets the "created_at" field. +func (slu *SentinelLibraryUpdate) SetCreatedAt(t time.Time) *SentinelLibraryUpdate { + slu.mutation.SetCreatedAt(t) + return slu +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (slu *SentinelLibraryUpdate) SetNillableCreatedAt(t *time.Time) *SentinelLibraryUpdate { + if t != nil { + slu.SetCreatedAt(*t) + } + return slu +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (slu *SentinelLibraryUpdate) SetLibraryReportSequence(i int64) *SentinelLibraryUpdate { + slu.mutation.ResetLibraryReportSequence() + slu.mutation.SetLibraryReportSequence(i) + return slu +} + +// SetNillableLibraryReportSequence sets the "library_report_sequence" field if the given value is not nil. +func (slu *SentinelLibraryUpdate) SetNillableLibraryReportSequence(i *int64) *SentinelLibraryUpdate { + if i != nil { + slu.SetLibraryReportSequence(*i) + } + return slu +} + +// AddLibraryReportSequence adds i to the "library_report_sequence" field. +func (slu *SentinelLibraryUpdate) AddLibraryReportSequence(i int64) *SentinelLibraryUpdate { + slu.mutation.AddLibraryReportSequence(i) + return slu +} + +// SetSentinelInfo sets the "sentinel_info" edge to the SentinelInfo entity. +func (slu *SentinelLibraryUpdate) SetSentinelInfo(s *SentinelInfo) *SentinelLibraryUpdate { + return slu.SetSentinelInfoID(s.ID) +} + +// Mutation returns the SentinelLibraryMutation object of the builder. +func (slu *SentinelLibraryUpdate) Mutation() *SentinelLibraryMutation { + return slu.mutation +} + +// ClearSentinelInfo clears the "sentinel_info" edge to the SentinelInfo entity. +func (slu *SentinelLibraryUpdate) ClearSentinelInfo() *SentinelLibraryUpdate { + slu.mutation.ClearSentinelInfo() + return slu +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (slu *SentinelLibraryUpdate) Save(ctx context.Context) (int, error) { + slu.defaults() + return withHooks(ctx, slu.sqlSave, slu.mutation, slu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (slu *SentinelLibraryUpdate) SaveX(ctx context.Context) int { + affected, err := slu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (slu *SentinelLibraryUpdate) Exec(ctx context.Context) error { + _, err := slu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (slu *SentinelLibraryUpdate) ExecX(ctx context.Context) { + if err := slu.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (slu *SentinelLibraryUpdate) defaults() { + if _, ok := slu.mutation.UpdatedAt(); !ok { + v := sentinellibrary.UpdateDefaultUpdatedAt() + slu.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (slu *SentinelLibraryUpdate) check() error { + if slu.mutation.SentinelInfoCleared() && len(slu.mutation.SentinelInfoIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "SentinelLibrary.sentinel_info"`) + } + return nil +} + +func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := slu.check(); err != nil { + return n, err + } + _spec := sqlgraph.NewUpdateSpec(sentinellibrary.Table, sentinellibrary.Columns, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt)) + if ps := slu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := slu.mutation.ReportedID(); ok { + _spec.SetField(sentinellibrary.FieldReportedID, field.TypeInt64, value) + } + if value, ok := slu.mutation.AddedReportedID(); ok { + _spec.AddField(sentinellibrary.FieldReportedID, field.TypeInt64, value) + } + if value, ok := slu.mutation.DownloadBasePath(); ok { + _spec.SetField(sentinellibrary.FieldDownloadBasePath, field.TypeString, value) + } + if value, ok := slu.mutation.UpdatedAt(); ok { + _spec.SetField(sentinellibrary.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := slu.mutation.CreatedAt(); ok { + _spec.SetField(sentinellibrary.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := slu.mutation.LibraryReportSequence(); ok { + _spec.SetField(sentinellibrary.FieldLibraryReportSequence, field.TypeInt64, value) + } + if value, ok := slu.mutation.AddedLibraryReportSequence(); ok { + _spec.AddField(sentinellibrary.FieldLibraryReportSequence, field.TypeInt64, value) + } + if slu.mutation.SentinelInfoCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinellibrary.SentinelInfoTable, + Columns: []string{sentinellibrary.SentinelInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := slu.mutation.SentinelInfoIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinellibrary.SentinelInfoTable, + Columns: []string{sentinellibrary.SentinelInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, slu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{sentinellibrary.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + slu.mutation.done = true + return n, nil +} + +// SentinelLibraryUpdateOne is the builder for updating a single SentinelLibrary entity. +type SentinelLibraryUpdateOne struct { + config + fields []string + hooks []Hook + mutation *SentinelLibraryMutation +} + +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (sluo *SentinelLibraryUpdateOne) SetSentinelInfoID(mi model.InternalID) *SentinelLibraryUpdateOne { + sluo.mutation.SetSentinelInfoID(mi) + return sluo +} + +// SetNillableSentinelInfoID sets the "sentinel_info_id" field if the given value is not nil. +func (sluo *SentinelLibraryUpdateOne) SetNillableSentinelInfoID(mi *model.InternalID) *SentinelLibraryUpdateOne { + if mi != nil { + sluo.SetSentinelInfoID(*mi) + } + return sluo +} + +// SetReportedID sets the "reported_id" field. +func (sluo *SentinelLibraryUpdateOne) SetReportedID(i int64) *SentinelLibraryUpdateOne { + sluo.mutation.ResetReportedID() + sluo.mutation.SetReportedID(i) + return sluo +} + +// SetNillableReportedID sets the "reported_id" field if the given value is not nil. +func (sluo *SentinelLibraryUpdateOne) SetNillableReportedID(i *int64) *SentinelLibraryUpdateOne { + if i != nil { + sluo.SetReportedID(*i) + } + return sluo +} + +// AddReportedID adds i to the "reported_id" field. +func (sluo *SentinelLibraryUpdateOne) AddReportedID(i int64) *SentinelLibraryUpdateOne { + sluo.mutation.AddReportedID(i) + return sluo +} + +// SetDownloadBasePath sets the "download_base_path" field. +func (sluo *SentinelLibraryUpdateOne) SetDownloadBasePath(s string) *SentinelLibraryUpdateOne { + sluo.mutation.SetDownloadBasePath(s) + return sluo +} + +// SetNillableDownloadBasePath sets the "download_base_path" field if the given value is not nil. +func (sluo *SentinelLibraryUpdateOne) SetNillableDownloadBasePath(s *string) *SentinelLibraryUpdateOne { + if s != nil { + sluo.SetDownloadBasePath(*s) + } + return sluo +} + +// SetUpdatedAt sets the "updated_at" field. +func (sluo *SentinelLibraryUpdateOne) SetUpdatedAt(t time.Time) *SentinelLibraryUpdateOne { + sluo.mutation.SetUpdatedAt(t) + return sluo +} + +// SetCreatedAt sets the "created_at" field. +func (sluo *SentinelLibraryUpdateOne) SetCreatedAt(t time.Time) *SentinelLibraryUpdateOne { + sluo.mutation.SetCreatedAt(t) + return sluo +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (sluo *SentinelLibraryUpdateOne) SetNillableCreatedAt(t *time.Time) *SentinelLibraryUpdateOne { + if t != nil { + sluo.SetCreatedAt(*t) + } + return sluo +} + +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (sluo *SentinelLibraryUpdateOne) SetLibraryReportSequence(i int64) *SentinelLibraryUpdateOne { + sluo.mutation.ResetLibraryReportSequence() + sluo.mutation.SetLibraryReportSequence(i) + return sluo +} + +// SetNillableLibraryReportSequence sets the "library_report_sequence" field if the given value is not nil. +func (sluo *SentinelLibraryUpdateOne) SetNillableLibraryReportSequence(i *int64) *SentinelLibraryUpdateOne { + if i != nil { + sluo.SetLibraryReportSequence(*i) + } + return sluo +} + +// AddLibraryReportSequence adds i to the "library_report_sequence" field. +func (sluo *SentinelLibraryUpdateOne) AddLibraryReportSequence(i int64) *SentinelLibraryUpdateOne { + sluo.mutation.AddLibraryReportSequence(i) + return sluo +} + +// SetSentinelInfo sets the "sentinel_info" edge to the SentinelInfo entity. +func (sluo *SentinelLibraryUpdateOne) SetSentinelInfo(s *SentinelInfo) *SentinelLibraryUpdateOne { + return sluo.SetSentinelInfoID(s.ID) +} + +// Mutation returns the SentinelLibraryMutation object of the builder. +func (sluo *SentinelLibraryUpdateOne) Mutation() *SentinelLibraryMutation { + return sluo.mutation +} + +// ClearSentinelInfo clears the "sentinel_info" edge to the SentinelInfo entity. +func (sluo *SentinelLibraryUpdateOne) ClearSentinelInfo() *SentinelLibraryUpdateOne { + sluo.mutation.ClearSentinelInfo() + return sluo +} + +// Where appends a list predicates to the SentinelLibraryUpdate builder. +func (sluo *SentinelLibraryUpdateOne) Where(ps ...predicate.SentinelLibrary) *SentinelLibraryUpdateOne { + sluo.mutation.Where(ps...) + return sluo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (sluo *SentinelLibraryUpdateOne) Select(field string, fields ...string) *SentinelLibraryUpdateOne { + sluo.fields = append([]string{field}, fields...) + return sluo +} + +// Save executes the query and returns the updated SentinelLibrary entity. +func (sluo *SentinelLibraryUpdateOne) Save(ctx context.Context) (*SentinelLibrary, error) { + sluo.defaults() + return withHooks(ctx, sluo.sqlSave, sluo.mutation, sluo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (sluo *SentinelLibraryUpdateOne) SaveX(ctx context.Context) *SentinelLibrary { + node, err := sluo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (sluo *SentinelLibraryUpdateOne) Exec(ctx context.Context) error { + _, err := sluo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (sluo *SentinelLibraryUpdateOne) ExecX(ctx context.Context) { + if err := sluo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (sluo *SentinelLibraryUpdateOne) defaults() { + if _, ok := sluo.mutation.UpdatedAt(); !ok { + v := sentinellibrary.UpdateDefaultUpdatedAt() + sluo.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (sluo *SentinelLibraryUpdateOne) check() error { + if sluo.mutation.SentinelInfoCleared() && len(sluo.mutation.SentinelInfoIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "SentinelLibrary.sentinel_info"`) + } + return nil +} + +func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *SentinelLibrary, err error) { + if err := sluo.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(sentinellibrary.Table, sentinellibrary.Columns, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt)) + id, ok := sluo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SentinelLibrary.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := sluo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, sentinellibrary.FieldID) + for _, f := range fields { + if !sentinellibrary.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != sentinellibrary.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := sluo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := sluo.mutation.ReportedID(); ok { + _spec.SetField(sentinellibrary.FieldReportedID, field.TypeInt64, value) + } + if value, ok := sluo.mutation.AddedReportedID(); ok { + _spec.AddField(sentinellibrary.FieldReportedID, field.TypeInt64, value) + } + if value, ok := sluo.mutation.DownloadBasePath(); ok { + _spec.SetField(sentinellibrary.FieldDownloadBasePath, field.TypeString, value) + } + if value, ok := sluo.mutation.UpdatedAt(); ok { + _spec.SetField(sentinellibrary.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := sluo.mutation.CreatedAt(); ok { + _spec.SetField(sentinellibrary.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := sluo.mutation.LibraryReportSequence(); ok { + _spec.SetField(sentinellibrary.FieldLibraryReportSequence, field.TypeInt64, value) + } + if value, ok := sluo.mutation.AddedLibraryReportSequence(); ok { + _spec.AddField(sentinellibrary.FieldLibraryReportSequence, field.TypeInt64, value) + } + if sluo.mutation.SentinelInfoCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinellibrary.SentinelInfoTable, + Columns: []string{sentinellibrary.SentinelInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := sluo.mutation.SentinelInfoIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinellibrary.SentinelInfoTable, + Columns: []string{sentinellibrary.SentinelInfoColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &SentinelLibrary{config: sluo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, sluo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{sentinellibrary.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + sluo.mutation.done = true + return _node, nil +} diff --git a/internal/data/internal/ent/tx.go b/internal/data/internal/ent/tx.go index 5bcb4822..a541760d 100644 --- a/internal/data/internal/ent/tx.go +++ b/internal/data/internal/ent/tx.go @@ -56,6 +56,14 @@ type Tx struct { PorterContext *PorterContextClient // PorterInstance is the client for interacting with the PorterInstance builders. PorterInstance *PorterInstanceClient + // SentinelAppBinary is the client for interacting with the SentinelAppBinary builders. + SentinelAppBinary *SentinelAppBinaryClient + // SentinelAppBinaryFile is the client for interacting with the SentinelAppBinaryFile builders. + SentinelAppBinaryFile *SentinelAppBinaryFileClient + // SentinelInfo is the client for interacting with the SentinelInfo builders. + SentinelInfo *SentinelInfoClient + // SentinelLibrary is the client for interacting with the SentinelLibrary builders. + SentinelLibrary *SentinelLibraryClient // Session is the client for interacting with the Session builders. Session *SessionClient // StoreApp is the client for interacting with the StoreApp builders. @@ -221,6 +229,10 @@ func (tx *Tx) init() { tx.NotifyTarget = NewNotifyTargetClient(tx.config) tx.PorterContext = NewPorterContextClient(tx.config) tx.PorterInstance = NewPorterInstanceClient(tx.config) + tx.SentinelAppBinary = NewSentinelAppBinaryClient(tx.config) + tx.SentinelAppBinaryFile = NewSentinelAppBinaryFileClient(tx.config) + tx.SentinelInfo = NewSentinelInfoClient(tx.config) + tx.SentinelLibrary = NewSentinelLibraryClient(tx.config) tx.Session = NewSessionClient(tx.config) tx.StoreApp = NewStoreAppClient(tx.config) tx.StoreAppBinary = NewStoreAppBinaryClient(tx.config) diff --git a/internal/lib/libtime/time.go b/internal/lib/libtime/time.go index 3e6217bf..ac64c099 100644 --- a/internal/lib/libtime/time.go +++ b/internal/lib/libtime/time.go @@ -3,15 +3,16 @@ package libtime import "time" const ( - Second = time.Second - Minute = time.Minute - Hour = time.Hour - HalfDay = Hour * 12 - Day = Hour * 24 - TwoDays = Day * 2 - ThreeDays = Day * 3 - FourDays = Day * 4 - FiveDays = Day * 5 - SevenDays = Day * 7 - ThirtyDays = Day * 30 + Second = time.Second + Minute = time.Minute + Hour = time.Hour + HalfDay = Hour * 12 + Day = Hour * 24 + TwoDays = Day * 2 + ThreeDays = Day * 3 + FourDays = Day * 4 + FiveDays = Day * 5 + SevenDays = Day * 7 + TwentyTwoDays = Day * 22 + ThirtyDays = Day * 30 ) diff --git a/internal/model/modelgebura/modelgebura.go b/internal/model/modelgebura/modelgebura.go index d65b866f..41b5a026 100644 --- a/internal/model/modelgebura/modelgebura.go +++ b/internal/model/modelgebura/modelgebura.go @@ -107,3 +107,39 @@ type AppCategory struct { Name string AppIDs []model.InternalID } + +//nolint:stylecheck // no check for Url +type SentinelInfo struct { + ID model.InternalID + Url string + AlternativeUrls []string + GetTokenPath string + DownloadFileBasePath string + Libraries []*SentinelLibrary +} + +type SentinelLibrary struct { + ReportedID int64 + DownloadBasePath string + AppBinaries []*SentinelAppBinary +} + +type SentinelAppBinary struct { + SentinelLibraryID int64 + GeneratedID string + SizeBytes int64 + NeedToken bool + Files []*SentinelAppBinaryFile + Name string + Version string + Developer string + Publisher string +} + +type SentinelAppBinaryFile struct { + Name string + SizeBytes int64 + Sha256 []byte + ServerFilePath string + ChunksInfo string +} diff --git a/internal/server/grpc.go b/internal/server/grpc.go index 2616e342..060a8ce8 100644 --- a/internal/server/grpc.go +++ b/internal/server/grpc.go @@ -6,6 +6,7 @@ import ( "github.com/tuihub/librarian/internal/lib/libauth" "github.com/tuihub/librarian/internal/lib/libobserve" "github.com/tuihub/librarian/internal/lib/libsentry" + sentinelpb "github.com/tuihub/protos/pkg/librarian/sephirah/v1/sentinel" pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1/sephirah" "github.com/go-kratos/kratos/v2/middleware" @@ -23,6 +24,7 @@ func NewGRPCServer( c *conf.SephirahServer, auth *libauth.Auth, greeter pb.LibrarianSephirahServiceServer, + sentinelserver sentinelpb.LibrarianSentinelServiceServer, app *libapp.Settings, observer *libobserve.BuiltInObserver, ) (*grpc.Server, error) { @@ -74,5 +76,6 @@ func NewGRPCServer( } srv := grpc.NewServer(opts...) pb.RegisterLibrarianSephirahServiceServer(srv, greeter) + sentinelpb.RegisterLibrarianSentinelServiceServer(srv, sentinelserver) return srv, nil } diff --git a/internal/server/token_matcher.go b/internal/server/token_matcher.go index 836040bc..0e6a3936 100644 --- a/internal/server/token_matcher.go +++ b/internal/server/token_matcher.go @@ -79,6 +79,7 @@ func login() map[string]bool { func refreshTokenProtected() map[string]bool { return map[string]bool{ "/librarian.sephirah.v1.sephirah.LibrarianSephirahService/RefreshToken": true, + "/librarian.sephirah.v1.sentinel.LibrarianSentinelService/RefreshToken": true, } } diff --git a/internal/service/sentinel/converter/converter.go b/internal/service/sentinel/converter/converter.go new file mode 100644 index 00000000..464dd31b --- /dev/null +++ b/internal/service/sentinel/converter/converter.go @@ -0,0 +1,5 @@ +//go:build !goverter + +package converter + +//go:generate go run github.com/jmattheis/goverter/cmd/goverter gen . diff --git a/internal/service/sentinel/converter/generated.go b/internal/service/sentinel/converter/generated.go new file mode 100644 index 00000000..a4fb4009 --- /dev/null +++ b/internal/service/sentinel/converter/generated.go @@ -0,0 +1,93 @@ +// Code generated by github.com/jmattheis/goverter, DO NOT EDIT. +//go:build !goverter + +package converter + +import ( + modelgebura "github.com/tuihub/librarian/internal/model/modelgebura" + sentinel "github.com/tuihub/protos/pkg/librarian/sephirah/v1/sentinel" +) + +func ToBizSentinelAppBinary(source *sentinel.SentinelLibraryAppBinary) *modelgebura.SentinelAppBinary { + var pModelgeburaSentinelAppBinary *modelgebura.SentinelAppBinary + if source != nil { + var modelgeburaSentinelAppBinary modelgebura.SentinelAppBinary + modelgeburaSentinelAppBinary.SentinelLibraryID = (*source).SentinelLibraryId + modelgeburaSentinelAppBinary.GeneratedID = (*source).SentinelGeneratedId + modelgeburaSentinelAppBinary.SizeBytes = (*source).SizeBytes + modelgeburaSentinelAppBinary.NeedToken = (*source).NeedToken + if (*source).Files != nil { + modelgeburaSentinelAppBinary.Files = make([]*modelgebura.SentinelAppBinaryFile, len((*source).Files)) + for i := 0; i < len((*source).Files); i++ { + modelgeburaSentinelAppBinary.Files[i] = ToBizSentinelAppBinaryFile((*source).Files[i]) + } + } + modelgeburaSentinelAppBinary.Name = (*source).Name + modelgeburaSentinelAppBinary.Version = (*source).Version + modelgeburaSentinelAppBinary.Developer = (*source).Developer + modelgeburaSentinelAppBinary.Publisher = (*source).Publisher + pModelgeburaSentinelAppBinary = &modelgeburaSentinelAppBinary + } + return pModelgeburaSentinelAppBinary +} +func ToBizSentinelAppBinaryFile(source *sentinel.SentinelLibraryAppBinaryFile) *modelgebura.SentinelAppBinaryFile { + var pModelgeburaSentinelAppBinaryFile *modelgebura.SentinelAppBinaryFile + if source != nil { + var modelgeburaSentinelAppBinaryFile modelgebura.SentinelAppBinaryFile + modelgeburaSentinelAppBinaryFile.Name = (*source).Name + modelgeburaSentinelAppBinaryFile.SizeBytes = (*source).SizeBytes + if (*source).Sha256 != nil { + modelgeburaSentinelAppBinaryFile.Sha256 = make([]uint8, len((*source).Sha256)) + for i := 0; i < len((*source).Sha256); i++ { + modelgeburaSentinelAppBinaryFile.Sha256[i] = (*source).Sha256[i] + } + } + modelgeburaSentinelAppBinaryFile.ServerFilePath = (*source).ServerFilePath + modelgeburaSentinelAppBinaryFile.ChunksInfo = PtrToString((*source).ChunksInfo) + pModelgeburaSentinelAppBinaryFile = &modelgeburaSentinelAppBinaryFile + } + return pModelgeburaSentinelAppBinaryFile +} +func ToBizSentinelAppBinaryList(source []*sentinel.SentinelLibraryAppBinary) []*modelgebura.SentinelAppBinary { + var pModelgeburaSentinelAppBinaryList []*modelgebura.SentinelAppBinary + if source != nil { + pModelgeburaSentinelAppBinaryList = make([]*modelgebura.SentinelAppBinary, len(source)) + for i := 0; i < len(source); i++ { + pModelgeburaSentinelAppBinaryList[i] = ToBizSentinelAppBinary(source[i]) + } + } + return pModelgeburaSentinelAppBinaryList +} +func ToBizSentinelInfo(source *sentinel.ReportSentinelInformationRequest) *modelgebura.SentinelInfo { + var pModelgeburaSentinelInfo *modelgebura.SentinelInfo + if source != nil { + var modelgeburaSentinelInfo modelgebura.SentinelInfo + modelgeburaSentinelInfo.Url = (*source).Url + if (*source).UrlAlternatives != nil { + modelgeburaSentinelInfo.AlternativeUrls = make([]string, len((*source).UrlAlternatives)) + for i := 0; i < len((*source).UrlAlternatives); i++ { + modelgeburaSentinelInfo.AlternativeUrls[i] = (*source).UrlAlternatives[i] + } + } + modelgeburaSentinelInfo.GetTokenPath = (*source).GetTokenPath + modelgeburaSentinelInfo.DownloadFileBasePath = (*source).DownloadFileBasePath + if (*source).Libraries != nil { + modelgeburaSentinelInfo.Libraries = make([]*modelgebura.SentinelLibrary, len((*source).Libraries)) + for j := 0; j < len((*source).Libraries); j++ { + modelgeburaSentinelInfo.Libraries[j] = ToBizSentinelLibrary((*source).Libraries[j]) + } + } + pModelgeburaSentinelInfo = &modelgeburaSentinelInfo + } + return pModelgeburaSentinelInfo +} +func ToBizSentinelLibrary(source *sentinel.SentinelLibrary) *modelgebura.SentinelLibrary { + var pModelgeburaSentinelLibrary *modelgebura.SentinelLibrary + if source != nil { + var modelgeburaSentinelLibrary modelgebura.SentinelLibrary + modelgeburaSentinelLibrary.ReportedID = (*source).Id + modelgeburaSentinelLibrary.DownloadBasePath = (*source).DownloadBasePath + pModelgeburaSentinelLibrary = &modelgeburaSentinelLibrary + } + return pModelgeburaSentinelLibrary +} diff --git a/internal/service/sentinel/converter/pb_to_biz.go b/internal/service/sentinel/converter/pb_to_biz.go new file mode 100644 index 00000000..ce2f5f7b --- /dev/null +++ b/internal/service/sentinel/converter/pb_to_biz.go @@ -0,0 +1,33 @@ +package converter + +import ( + "github.com/tuihub/librarian/internal/model/modelgebura" + sentinel "github.com/tuihub/protos/pkg/librarian/sephirah/v1/sentinel" +) + +// goverter:converter +// goverter:output:format function +// goverter:output:file ./generated.go +// goverter:output:package github.com/tuihub/librarian/internal/service/sentinel/converter +// goverter:matchIgnoreCase +// goverter:ignoreUnexported +// goverter:extend PtrToString +type toBizConverter interface { //nolint:unused // used by generator + // goverter:ignore ID + // goverter:map UrlAlternatives AlternativeUrls + ToBizSentinelInfo(*sentinel.ReportSentinelInformationRequest) *modelgebura.SentinelInfo + // goverter:map Id ReportedID + // goverter:ignore AppBinaries + ToBizSentinelLibrary(*sentinel.SentinelLibrary) *modelgebura.SentinelLibrary + // goverter:map SentinelGeneratedId GeneratedID + ToBizSentinelAppBinary(*sentinel.SentinelLibraryAppBinary) *modelgebura.SentinelAppBinary + ToBizSentinelAppBinaryList([]*sentinel.SentinelLibraryAppBinary) []*modelgebura.SentinelAppBinary + ToBizSentinelAppBinaryFile(*sentinel.SentinelLibraryAppBinaryFile) *modelgebura.SentinelAppBinaryFile +} + +func PtrToString(u *string) string { + if u == nil { + return "" + } + return *u +} diff --git a/internal/service/sentinel/gebura.go b/internal/service/sentinel/gebura.go new file mode 100644 index 00000000..c939868a --- /dev/null +++ b/internal/service/sentinel/gebura.go @@ -0,0 +1,28 @@ +package sentinel + +import ( + "context" + + "github.com/tuihub/librarian/internal/service/sentinel/converter" + pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1/sentinel" +) + +func (s *LibrarianSentinelService) ReportSentinelInformation( + ctx context.Context, req *pb.ReportSentinelInformationRequest, +) (*pb.ReportSentinelInformationResponse, error) { + err := s.g.UpsertSentinelInfo(ctx, converter.ToBizSentinelInfo(req)) + if err != nil { + return nil, err + } + return &pb.ReportSentinelInformationResponse{}, nil +} + +func (s *LibrarianSentinelService) ReportAppBinaries( + ctx context.Context, req *pb.ReportAppBinariesRequest, +) (*pb.ReportAppBinariesResponse, error) { + err := s.g.UpsertAppBinaries(ctx, converter.ToBizSentinelAppBinaryList(req.GetAppBinaries())) + if err != nil { + return nil, err + } + return &pb.ReportAppBinariesResponse{}, nil +} diff --git a/internal/service/sentinel/librariansentinelservice.go b/internal/service/sentinel/librariansentinelservice.go new file mode 100644 index 00000000..e20b4f8d --- /dev/null +++ b/internal/service/sentinel/librariansentinelservice.go @@ -0,0 +1,29 @@ +package sentinel + +import ( + "github.com/tuihub/librarian/internal/biz/bizgebura" + "github.com/tuihub/librarian/internal/biz/biztiphereth" + pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1/sentinel" + + "github.com/google/wire" +) + +var ProviderSet = wire.NewSet(NewLibrarianSentinelService) + +type LibrarianSentinelService struct { + pb.UnimplementedLibrarianSentinelServiceServer + + t *biztiphereth.Tiphereth + g *bizgebura.Gebura +} + +func NewLibrarianSentinelService( + t *biztiphereth.Tiphereth, + g *bizgebura.Gebura, +) pb.LibrarianSentinelServiceServer { + return &LibrarianSentinelService{ + UnimplementedLibrarianSentinelServiceServer: pb.UnimplementedLibrarianSentinelServiceServer{}, + t: t, + g: g, + } +} diff --git a/internal/service/sentinel/tiphereth.go b/internal/service/sentinel/tiphereth.go new file mode 100644 index 00000000..e1c0a24e --- /dev/null +++ b/internal/service/sentinel/tiphereth.go @@ -0,0 +1,22 @@ +package sentinel + +import ( + "context" + + "github.com/tuihub/librarian/internal/lib/logger" + pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1/sentinel" +) + +func (s *LibrarianSentinelService) RefreshToken(ctx context.Context, req *pb.RefreshTokenRequest) ( + *pb.RefreshTokenResponse, error, +) { + accessToken, refreshToken, err := s.t.SentinelRefreshToken(ctx) + if err != nil { + logger.Infof("GetToken failed: %s", err.Error()) + return nil, err + } + return &pb.RefreshTokenResponse{ + AccessToken: string(accessToken), + RefreshToken: string(refreshToken), + }, nil +} diff --git a/internal/service/sephirah/converter/biz_to_pb.go b/internal/service/sephirah/converter/biz_to_pb.go index fc29fd21..5602c60b 100644 --- a/internal/service/sephirah/converter/biz_to_pb.go +++ b/internal/service/sephirah/converter/biz_to_pb.go @@ -104,7 +104,7 @@ type toPBConverter interface { //nolint:unused // used by generator ToPBPorterDigest(*modelsupervisor.PorterDigest) *sephirah.PorterDigest ToPBPorterDigestList([]*modelsupervisor.PorterDigest) []*sephirah.PorterDigest - // goverter:map AlternativeNames AltNames + // goverter:map AlternativeNames NameAlternatives ToPBAppInfo(*modelgebura.AppInfo) *sephirah.AppInfo ToPBAppInfoList([]*modelgebura.AppInfo) []*sephirah.AppInfo // goverter:enum:unknown AppType_APP_TYPE_UNSPECIFIED @@ -112,7 +112,7 @@ type toPBConverter interface { //nolint:unused // used by generator // goverter:enum:map AppTypeGame AppType_APP_TYPE_GAME ToPBAppType(modelgebura.AppType) sephirah.AppType - // goverter:map AlternativeNames AltNames + // goverter:map AlternativeNames NameAlternatives ToPBApp(*modelgebura.App) *sephirah.App ToPBAppList([]*modelgebura.App) []*sephirah.App diff --git a/internal/service/sephirah/converter/generated.go b/internal/service/sephirah/converter/generated.go index 0fd00443..ea0dbd5e 100644 --- a/internal/service/sephirah/converter/generated.go +++ b/internal/service/sephirah/converter/generated.go @@ -54,10 +54,10 @@ func ToBizApp(source *sephirah.App) *modelgebura.App { modelgeburaApp.Tags[i] = (*source).Tags[i] } } - if (*source).AltNames != nil { - modelgeburaApp.AlternativeNames = make([]string, len((*source).AltNames)) - for j := 0; j < len((*source).AltNames); j++ { - modelgeburaApp.AlternativeNames[j] = (*source).AltNames[j] + if (*source).NameAlternatives != nil { + modelgeburaApp.AlternativeNames = make([]string, len((*source).NameAlternatives)) + for j := 0; j < len((*source).NameAlternatives); j++ { + modelgeburaApp.AlternativeNames[j] = (*source).NameAlternatives[j] } } pModelgeburaApp = &modelgeburaApp @@ -101,10 +101,10 @@ func ToBizAppInfo(source *sephirah.AppInfo) *modelgebura.AppInfo { modelgeburaAppInfo.Tags[i] = (*source).Tags[i] } } - if (*source).AltNames != nil { - modelgeburaAppInfo.AlternativeNames = make([]string, len((*source).AltNames)) - for j := 0; j < len((*source).AltNames); j++ { - modelgeburaAppInfo.AlternativeNames[j] = (*source).AltNames[j] + if (*source).NameAlternatives != nil { + modelgeburaAppInfo.AlternativeNames = make([]string, len((*source).NameAlternatives)) + for j := 0; j < len((*source).NameAlternatives); j++ { + modelgeburaAppInfo.AlternativeNames[j] = (*source).NameAlternatives[j] } } pModelgeburaAppInfo = &modelgeburaAppInfo @@ -862,9 +862,9 @@ func ToPBApp(source *modelgebura.App) *sephirah.App { } } if (*source).AlternativeNames != nil { - v1App.AltNames = make([]string, len((*source).AlternativeNames)) + v1App.NameAlternatives = make([]string, len((*source).AlternativeNames)) for j := 0; j < len((*source).AlternativeNames); j++ { - v1App.AltNames[j] = (*source).AlternativeNames[j] + v1App.NameAlternatives[j] = (*source).AlternativeNames[j] } } v1App.Developer = (*source).Developer @@ -920,9 +920,9 @@ func ToPBAppInfo(source *modelgebura.AppInfo) *sephirah.AppInfo { } } if (*source).AlternativeNames != nil { - v1AppInfo.AltNames = make([]string, len((*source).AlternativeNames)) + v1AppInfo.NameAlternatives = make([]string, len((*source).AlternativeNames)) for j := 0; j < len((*source).AlternativeNames); j++ { - v1AppInfo.AltNames[j] = (*source).AlternativeNames[j] + v1AppInfo.NameAlternatives[j] = (*source).AlternativeNames[j] } } v1AppInfo.Developer = (*source).Developer diff --git a/internal/service/sephirah/converter/pb_to_biz.go b/internal/service/sephirah/converter/pb_to_biz.go index 8948b6db..cd58bbab 100644 --- a/internal/service/sephirah/converter/pb_to_biz.go +++ b/internal/service/sephirah/converter/pb_to_biz.go @@ -82,7 +82,7 @@ type toBizConverter interface { //nolint:unused // used by generator // goverter:ignore ID // goverter:ignore ShortDescription // goverter:ignore ReleaseDate - // goverter:map AltNames AlternativeNames + // goverter:map NameAlternatives AlternativeNames // goverter:ignore RawData // goverter:ignore UpdatedAt ToBizAppInfo(*sephirah.AppInfo) *modelgebura.AppInfo @@ -91,7 +91,7 @@ type toBizConverter interface { //nolint:unused // used by generator // goverter:ignore ShortDescription // goverter:ignore ReleaseDate - // goverter:map AltNames AlternativeNames + // goverter:map NameAlternatives AlternativeNames ToBizApp(*sephirah.App) *modelgebura.App // goverter:enum:unknown AppTypeUnspecified // goverter:enum:map AppType_APP_TYPE_UNSPECIFIED AppTypeUnspecified diff --git a/wire.go b/wire.go index 42edb48f..7b76f1e9 100644 --- a/wire.go +++ b/wire.go @@ -23,6 +23,7 @@ import ( "github.com/tuihub/librarian/internal/model" "github.com/tuihub/librarian/internal/server" "github.com/tuihub/librarian/internal/service/angelaweb" + "github.com/tuihub/librarian/internal/service/sentinel" "github.com/tuihub/librarian/internal/service/sephirah" "github.com/tuihub/librarian/internal/service/supervisor" @@ -54,6 +55,7 @@ func wireApp( biz.ProviderSet, client.ProviderSet, supervisor.ProviderSet, + sentinel.ProviderSet, sephirah.ProviderSet, server.ProviderSet, inprocgrpc.ProviderSet, diff --git a/wire_gen.go b/wire_gen.go index e53ee44c..bd0caeb0 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -32,6 +32,7 @@ import ( "github.com/tuihub/librarian/internal/model" "github.com/tuihub/librarian/internal/server" "github.com/tuihub/librarian/internal/service/angelaweb" + "github.com/tuihub/librarian/internal/service/sentinel" "github.com/tuihub/librarian/internal/service/sephirah" "github.com/tuihub/librarian/internal/service/supervisor" ) @@ -181,7 +182,8 @@ func wireApp(arg []*model.ConfigDigest, librarian_EnableServiceDiscovery *conf.L return nil, nil, err } librarianSephirahServiceServer := sephirah.NewLibrarianSephirahService(kether, tiphereth, gebura, binah, yesod, netzach, chesed, supervisorSupervisor, settings, libauthAuth, sephirahServer) - grpcServer, err := server.NewGRPCServer(sephirahServer, libauthAuth, librarianSephirahServiceServer, settings, builtInObserver) + librarianSentinelServiceServer := sentinel.NewLibrarianSentinelService(tiphereth, gebura) + grpcServer, err := server.NewGRPCServer(sephirahServer, libauthAuth, librarianSephirahServiceServer, librarianSentinelServiceServer, settings, builtInObserver) if err != nil { cleanup3() cleanup2()