From 0b9841a9e66afd271bcfcd52f17531812383df38 Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Mon, 7 Apr 2025 10:52:08 +0800 Subject: [PATCH 01/16] feat(sentinel): add sentinel service to app --- internal/server/grpc.go | 3 ++ .../sentinel/librariansentinelservice.go | 28 +++++++++++++++++++ wire.go | 2 ++ wire_gen.go | 4 ++- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 internal/service/sentinel/librariansentinelservice.go 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/service/sentinel/librariansentinelservice.go b/internal/service/sentinel/librariansentinelservice.go new file mode 100644 index 00000000..866f03cc --- /dev/null +++ b/internal/service/sentinel/librariansentinelservice.go @@ -0,0 +1,28 @@ +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{ + t: t, + g: g, + } +} 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() From c14521b49643e82febc1da56c825248223d51aef Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Mon, 7 Apr 2025 12:08:19 +0800 Subject: [PATCH 02/16] feat(sentinel): impl RefreshToken --- internal/biz/biztiphereth/token.go | 47 ++++++++++++++++++++++++++ internal/lib/libtime/time.go | 23 +++++++------ internal/service/sentinel/tiphereth.go | 21 ++++++++++++ 3 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 internal/service/sentinel/tiphereth.go diff --git a/internal/biz/biztiphereth/token.go b/internal/biz/biztiphereth/token.go index afcce8cc..d80db94d 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( //nolint:gocognit // TODO + 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/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/service/sentinel/tiphereth.go b/internal/service/sentinel/tiphereth.go new file mode 100644 index 00000000..9ca860bd --- /dev/null +++ b/internal/service/sentinel/tiphereth.go @@ -0,0 +1,21 @@ +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 +} From 25b18d09a4c252439faea190f370a8a3b169fa5f Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Tue, 8 Apr 2025 12:15:38 +0800 Subject: [PATCH 03/16] fix(sentinel): add UnimplementedServer --- internal/service/sentinel/librariansentinelservice.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/service/sentinel/librariansentinelservice.go b/internal/service/sentinel/librariansentinelservice.go index 866f03cc..e20b4f8d 100644 --- a/internal/service/sentinel/librariansentinelservice.go +++ b/internal/service/sentinel/librariansentinelservice.go @@ -22,6 +22,7 @@ func NewLibrarianSentinelService( g *bizgebura.Gebura, ) pb.LibrarianSentinelServiceServer { return &LibrarianSentinelService{ + UnimplementedLibrarianSentinelServiceServer: pb.UnimplementedLibrarianSentinelServiceServer{}, t: t, g: g, } From ceb0947781c65c05a86a62e1bacb8729b769e490 Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Tue, 8 Apr 2025 12:16:47 +0800 Subject: [PATCH 04/16] feat(sentinel): add models, rebase, remove unused --- internal/biz/biztiphereth/token.go | 2 +- internal/data/gebura.go | 12 +- internal/data/internal/ent/client.go | 800 +++- internal/data/internal/ent/ent.go | 64 +- internal/data/internal/ent/hook/hook.go | 48 + internal/data/internal/ent/migrate/schema.go | 129 + internal/data/internal/ent/mutation.go | 3500 ++++++++++++++++- .../data/internal/ent/predicate/predicate.go | 12 + internal/data/internal/ent/runtime.go | 52 + .../ent/schema/sentinel_app_binary.go | 48 + .../ent/schema/sentinel_app_binary_file.go | 44 + .../data/internal/ent/schema/sentinel_info.go | 43 + .../internal/ent/schema/sentinel_library.go | 42 + .../data/internal/ent/sentinelappbinary.go | 252 ++ .../sentinelappbinary/sentinelappbinary.go | 184 + .../internal/ent/sentinelappbinary/where.go | 682 ++++ .../internal/ent/sentinelappbinary_create.go | 1136 ++++++ .../internal/ent/sentinelappbinary_delete.go | 88 + .../internal/ent/sentinelappbinary_query.go | 683 ++++ .../internal/ent/sentinelappbinary_update.go | 870 ++++ .../internal/ent/sentinelappbinaryfile.go | 214 + .../sentinelappbinaryfile.go | 133 + .../ent/sentinelappbinaryfile/where.go | 519 +++ .../ent/sentinelappbinaryfile_create.go | 923 +++++ .../ent/sentinelappbinaryfile_delete.go | 88 + .../ent/sentinelappbinaryfile_query.go | 606 +++ .../ent/sentinelappbinaryfile_update.go | 569 +++ internal/data/internal/ent/sentinelinfo.go | 204 + .../internal/ent/sentinelinfo/sentinelinfo.go | 132 + .../data/internal/ent/sentinelinfo/where.go | 475 +++ .../data/internal/ent/sentinelinfo_create.go | 898 +++++ .../data/internal/ent/sentinelinfo_delete.go | 88 + .../data/internal/ent/sentinelinfo_query.go | 608 +++ .../data/internal/ent/sentinelinfo_update.go | 643 +++ internal/data/internal/ent/sentinellibrary.go | 195 + .../ent/sentinellibrary/sentinellibrary.go | 144 + .../internal/ent/sentinellibrary/where.go | 347 ++ .../internal/ent/sentinellibrary_create.go | 771 ++++ .../internal/ent/sentinellibrary_delete.go | 88 + .../internal/ent/sentinellibrary_query.go | 683 ++++ .../internal/ent/sentinellibrary_update.go | 628 +++ internal/data/internal/ent/tx.go | 12 + internal/model/modelgebura/modelgebura.go | 35 + internal/service/sentinel/tiphereth.go | 1 + 44 files changed, 17561 insertions(+), 134 deletions(-) create mode 100644 internal/data/internal/ent/schema/sentinel_app_binary.go create mode 100644 internal/data/internal/ent/schema/sentinel_app_binary_file.go create mode 100644 internal/data/internal/ent/schema/sentinel_info.go create mode 100644 internal/data/internal/ent/schema/sentinel_library.go create mode 100644 internal/data/internal/ent/sentinelappbinary.go create mode 100644 internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go create mode 100644 internal/data/internal/ent/sentinelappbinary/where.go create mode 100644 internal/data/internal/ent/sentinelappbinary_create.go create mode 100644 internal/data/internal/ent/sentinelappbinary_delete.go create mode 100644 internal/data/internal/ent/sentinelappbinary_query.go create mode 100644 internal/data/internal/ent/sentinelappbinary_update.go create mode 100644 internal/data/internal/ent/sentinelappbinaryfile.go create mode 100644 internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go create mode 100644 internal/data/internal/ent/sentinelappbinaryfile/where.go create mode 100644 internal/data/internal/ent/sentinelappbinaryfile_create.go create mode 100644 internal/data/internal/ent/sentinelappbinaryfile_delete.go create mode 100644 internal/data/internal/ent/sentinelappbinaryfile_query.go create mode 100644 internal/data/internal/ent/sentinelappbinaryfile_update.go create mode 100644 internal/data/internal/ent/sentinelinfo.go create mode 100644 internal/data/internal/ent/sentinelinfo/sentinelinfo.go create mode 100644 internal/data/internal/ent/sentinelinfo/where.go create mode 100644 internal/data/internal/ent/sentinelinfo_create.go create mode 100644 internal/data/internal/ent/sentinelinfo_delete.go create mode 100644 internal/data/internal/ent/sentinelinfo_query.go create mode 100644 internal/data/internal/ent/sentinelinfo_update.go create mode 100644 internal/data/internal/ent/sentinellibrary.go create mode 100644 internal/data/internal/ent/sentinellibrary/sentinellibrary.go create mode 100644 internal/data/internal/ent/sentinellibrary/where.go create mode 100644 internal/data/internal/ent/sentinellibrary_create.go create mode 100644 internal/data/internal/ent/sentinellibrary_delete.go create mode 100644 internal/data/internal/ent/sentinellibrary_query.go create mode 100644 internal/data/internal/ent/sentinellibrary_update.go diff --git a/internal/biz/biztiphereth/token.go b/internal/biz/biztiphereth/token.go index d80db94d..e1ec371c 100644 --- a/internal/biz/biztiphereth/token.go +++ b/internal/biz/biztiphereth/token.go @@ -171,7 +171,7 @@ func (t *Tiphereth) RefreshToken( //nolint:gocognit // TODO return model.AccessToken(accessToken), model.RefreshToken(refreshToken), nil } -func (t *Tiphereth) SentinelRefreshToken( //nolint:gocognit // TODO +func (t *Tiphereth) SentinelRefreshToken( ctx context.Context, ) (model.AccessToken, model.RefreshToken, *errors.Error) { claims := libauth.FromContextAssertUserType(ctx, model.UserTypeSentinel) diff --git a/internal/data/gebura.go b/internal/data/gebura.go index 0b03f49f..2ee20ea9 100644 --- a/internal/data/gebura.go +++ b/internal/data/gebura.go @@ -534,15 +534,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 +549,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 +587,7 @@ func (g *GeburaRepo) UpdateAppCategory( return q.Exec(ctx) }) } + func (g *GeburaRepo) DeleteAppCategory( ctx context.Context, userID model.InternalID, diff --git a/internal/data/internal/ent/client.go b/internal/data/internal/ent/client.go index d2657bca..dfce893e 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,634 @@ 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 +} + +// QuerySentinelLibrary queries the sentinel_library edge of a SentinelAppBinary. +func (c *SentinelAppBinaryClient) QuerySentinelLibrary(sab *SentinelAppBinary) *SentinelLibraryQuery { + query := (&SentinelLibraryClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := sab.ID + step := sqlgraph.NewStep( + sqlgraph.From(sentinelappbinary.Table, sentinelappbinary.FieldID, id), + sqlgraph.To(sentinellibrary.Table, sentinellibrary.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, sentinelappbinary.SentinelLibraryTable, sentinelappbinary.SentinelLibraryColumn), + ) + fromV = sqlgraph.Neighbors(sab.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QuerySentinelAppBinaryFile queries the sentinel_app_binary_file edge of a SentinelAppBinary. +func (c *SentinelAppBinaryClient) QuerySentinelAppBinaryFile(sab *SentinelAppBinary) *SentinelAppBinaryFileQuery { + query := (&SentinelAppBinaryFileClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := sab.ID + step := sqlgraph.NewStep( + sqlgraph.From(sentinelappbinary.Table, sentinelappbinary.FieldID, id), + sqlgraph.To(sentinelappbinaryfile.Table, sentinelappbinaryfile.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, sentinelappbinary.SentinelAppBinaryFileTable, sentinelappbinary.SentinelAppBinaryFileColumn), + ) + fromV = sqlgraph.Neighbors(sab.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// 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 +} + +// QuerySentinelAppBinary queries the sentinel_app_binary edge of a SentinelAppBinaryFile. +func (c *SentinelAppBinaryFileClient) QuerySentinelAppBinary(sabf *SentinelAppBinaryFile) *SentinelAppBinaryQuery { + query := (&SentinelAppBinaryClient{config: c.config}).Query() + query.path = func(context.Context) (fromV *sql.Selector, _ error) { + id := sabf.ID + step := sqlgraph.NewStep( + sqlgraph.From(sentinelappbinaryfile.Table, sentinelappbinaryfile.FieldID, id), + sqlgraph.To(sentinelappbinary.Table, sentinelappbinary.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, sentinelappbinaryfile.SentinelAppBinaryTable, sentinelappbinaryfile.SentinelAppBinaryColumn), + ) + fromV = sqlgraph.Neighbors(sabf.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// 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 int) *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 int) *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 int) (*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 int) *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 +} + +// QuerySentinelAppBinary queries the sentinel_app_binary edge of a SentinelLibrary. +func (c *SentinelLibraryClient) QuerySentinelAppBinary(sl *SentinelLibrary) *SentinelAppBinaryQuery { + query := (&SentinelAppBinaryClient{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(sentinelappbinary.Table, sentinelappbinary.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, sentinellibrary.SentinelAppBinaryTable, sentinellibrary.SentinelAppBinaryColumn), + ) + 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 +5928,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..1c1faa32 100644 --- a/internal/data/internal/ent/migrate/schema.go +++ b/internal/data/internal/ent/migrate/schema.go @@ -737,6 +737,128 @@ var ( }, }, } + // SentinelAppBinariesColumns holds the columns for the "sentinel_app_binaries" table. + SentinelAppBinariesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {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: "sentinel_library_id", Type: field.TypeInt}, + } + // 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]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "sentinel_app_binaries_sentinel_libraries_sentinel_library", + Columns: []*schema.Column{SentinelAppBinariesColumns[10]}, + RefColumns: []*schema.Column{SentinelLibrariesColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + Indexes: []*schema.Index{ + { + Name: "sentinelappbinary_sentinel_library_id_generated_id", + Unique: false, + Columns: []*schema.Column{SentinelAppBinariesColumns[10], SentinelAppBinariesColumns[1]}, + }, + }, + } + // SentinelAppBinaryFilesColumns holds the columns for the "sentinel_app_binary_files" table. + SentinelAppBinaryFilesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {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: "sentinel_app_binary_id", Type: field.TypeInt}, + } + // 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]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "sentinel_app_binary_files_sentinel_app_binaries_sentinel_app_binary", + Columns: []*schema.Column{SentinelAppBinaryFilesColumns[8]}, + RefColumns: []*schema.Column{SentinelAppBinariesColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + Indexes: []*schema.Index{ + { + Name: "sentinelappbinaryfile_sentinel_app_binary_id_name", + Unique: false, + Columns: []*schema.Column{SentinelAppBinaryFilesColumns[8], SentinelAppBinaryFilesColumns[1]}, + }, + }, + } + // SentinelInfosColumns holds the columns for the "sentinel_infos" table. + SentinelInfosColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "user_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}, + } + // SentinelInfosTable holds the schema information for the "sentinel_infos" table. + SentinelInfosTable = &schema.Table{ + Name: "sentinel_infos", + Columns: SentinelInfosColumns, + PrimaryKey: []*schema.Column{SentinelInfosColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "sentinelinfo_user_id", + Unique: false, + Columns: []*schema.Column{SentinelInfosColumns[1]}, + }, + }, + } + // 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: "sentinel_info_id", Type: field.TypeInt}, + } + // 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[5]}, + RefColumns: []*schema.Column{SentinelInfosColumns[0]}, + OnDelete: schema.NoAction, + }, + }, + Indexes: []*schema.Index{ + { + Name: "sentinellibrary_sentinel_info_id_reported_id", + Unique: false, + Columns: []*schema.Column{SentinelLibrariesColumns[5], SentinelLibrariesColumns[1]}, + }, + }, + } // SessionsColumns holds the columns for the "sessions" table. SessionsColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64}, @@ -931,6 +1053,10 @@ var ( NotifyTargetsTable, PorterContextsTable, PorterInstancesTable, + SentinelAppBinariesTable, + SentinelAppBinaryFilesTable, + SentinelInfosTable, + SentinelLibrariesTable, SessionsTable, StoreAppsTable, StoreAppBinariesTable, @@ -968,6 +1094,9 @@ func init() { NotifySourcesTable.ForeignKeys[2].RefTable = UsersTable NotifyTargetsTable.ForeignKeys[0].RefTable = UsersTable PorterContextsTable.ForeignKeys[0].RefTable = UsersTable + SentinelAppBinariesTable.ForeignKeys[0].RefTable = SentinelLibrariesTable + SentinelAppBinaryFilesTable.ForeignKeys[0].RefTable = SentinelAppBinariesTable + 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..55425e6d 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,3442 @@ 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 + 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 + clearedFields map[string]struct{} + sentinel_library *int + clearedsentinel_library bool + sentinel_app_binary_file map[int]struct{} + removedsentinel_app_binary_file map[int]struct{} + clearedsentinel_app_binary_file bool + 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) + } +} + +// SetSentinelLibraryID sets the "sentinel_library_id" field. +func (m *SentinelAppBinaryMutation) SetSentinelLibraryID(i int) { + m.sentinel_library = &i +} + +// SentinelLibraryID returns the value of the "sentinel_library_id" field in the mutation. +func (m *SentinelAppBinaryMutation) SentinelLibraryID() (r int, exists bool) { + v := m.sentinel_library + if v == nil { + return + } + return *v, true +} + +// OldSentinelLibraryID returns the old "sentinel_library_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) OldSentinelLibraryID(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSentinelLibraryID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSentinelLibraryID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSentinelLibraryID: %w", err) + } + return oldValue.SentinelLibraryID, nil +} + +// ResetSentinelLibraryID resets all changes to the "sentinel_library_id" field. +func (m *SentinelAppBinaryMutation) ResetSentinelLibraryID() { + m.sentinel_library = 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 +} + +// ClearSentinelLibrary clears the "sentinel_library" edge to the SentinelLibrary entity. +func (m *SentinelAppBinaryMutation) ClearSentinelLibrary() { + m.clearedsentinel_library = true + m.clearedFields[sentinelappbinary.FieldSentinelLibraryID] = struct{}{} +} + +// SentinelLibraryCleared reports if the "sentinel_library" edge to the SentinelLibrary entity was cleared. +func (m *SentinelAppBinaryMutation) SentinelLibraryCleared() bool { + return m.clearedsentinel_library +} + +// SentinelLibraryIDs returns the "sentinel_library" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// SentinelLibraryID instead. It exists only for internal usage by the builders. +func (m *SentinelAppBinaryMutation) SentinelLibraryIDs() (ids []int) { + if id := m.sentinel_library; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetSentinelLibrary resets all changes to the "sentinel_library" edge. +func (m *SentinelAppBinaryMutation) ResetSentinelLibrary() { + m.sentinel_library = nil + m.clearedsentinel_library = false +} + +// AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by ids. +func (m *SentinelAppBinaryMutation) AddSentinelAppBinaryFileIDs(ids ...int) { + if m.sentinel_app_binary_file == nil { + m.sentinel_app_binary_file = make(map[int]struct{}) + } + for i := range ids { + m.sentinel_app_binary_file[ids[i]] = struct{}{} + } +} + +// ClearSentinelAppBinaryFile clears the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity. +func (m *SentinelAppBinaryMutation) ClearSentinelAppBinaryFile() { + m.clearedsentinel_app_binary_file = true +} + +// SentinelAppBinaryFileCleared reports if the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity was cleared. +func (m *SentinelAppBinaryMutation) SentinelAppBinaryFileCleared() bool { + return m.clearedsentinel_app_binary_file +} + +// RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. +func (m *SentinelAppBinaryMutation) RemoveSentinelAppBinaryFileIDs(ids ...int) { + if m.removedsentinel_app_binary_file == nil { + m.removedsentinel_app_binary_file = make(map[int]struct{}) + } + for i := range ids { + delete(m.sentinel_app_binary_file, ids[i]) + m.removedsentinel_app_binary_file[ids[i]] = struct{}{} + } +} + +// RemovedSentinelAppBinaryFile returns the removed IDs of the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity. +func (m *SentinelAppBinaryMutation) RemovedSentinelAppBinaryFileIDs() (ids []int) { + for id := range m.removedsentinel_app_binary_file { + ids = append(ids, id) + } + return +} + +// SentinelAppBinaryFileIDs returns the "sentinel_app_binary_file" edge IDs in the mutation. +func (m *SentinelAppBinaryMutation) SentinelAppBinaryFileIDs() (ids []int) { + for id := range m.sentinel_app_binary_file { + ids = append(ids, id) + } + return +} + +// ResetSentinelAppBinaryFile resets all changes to the "sentinel_app_binary_file" edge. +func (m *SentinelAppBinaryMutation) ResetSentinelAppBinaryFile() { + m.sentinel_app_binary_file = nil + m.clearedsentinel_app_binary_file = false + m.removedsentinel_app_binary_file = 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, 10) + if m.sentinel_library != nil { + fields = append(fields, sentinelappbinary.FieldSentinelLibraryID) + } + 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) + } + 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.FieldSentinelLibraryID: + return m.SentinelLibraryID() + 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() + } + 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.FieldSentinelLibraryID: + return m.OldSentinelLibraryID(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) + } + 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.FieldSentinelLibraryID: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSentinelLibraryID(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 + } + 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.addsize_bytes != nil { + fields = append(fields, sentinelappbinary.FieldSizeBytes) + } + 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.FieldSizeBytes: + return m.AddedSizeBytes() + } + 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.FieldSizeBytes: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddSizeBytes(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.FieldSentinelLibraryID: + m.ResetSentinelLibraryID() + 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 + } + 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, 2) + if m.sentinel_library != nil { + edges = append(edges, sentinelappbinary.EdgeSentinelLibrary) + } + if m.sentinel_app_binary_file != nil { + edges = append(edges, sentinelappbinary.EdgeSentinelAppBinaryFile) + } + 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 { + switch name { + case sentinelappbinary.EdgeSentinelLibrary: + if id := m.sentinel_library; id != nil { + return []ent.Value{*id} + } + case sentinelappbinary.EdgeSentinelAppBinaryFile: + ids := make([]ent.Value, 0, len(m.sentinel_app_binary_file)) + for id := range m.sentinel_app_binary_file { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *SentinelAppBinaryMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + if m.removedsentinel_app_binary_file != nil { + edges = append(edges, sentinelappbinary.EdgeSentinelAppBinaryFile) + } + 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 { + switch name { + case sentinelappbinary.EdgeSentinelAppBinaryFile: + ids := make([]ent.Value, 0, len(m.removedsentinel_app_binary_file)) + for id := range m.removedsentinel_app_binary_file { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *SentinelAppBinaryMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedsentinel_library { + edges = append(edges, sentinelappbinary.EdgeSentinelLibrary) + } + if m.clearedsentinel_app_binary_file { + edges = append(edges, sentinelappbinary.EdgeSentinelAppBinaryFile) + } + 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 { + switch name { + case sentinelappbinary.EdgeSentinelLibrary: + return m.clearedsentinel_library + case sentinelappbinary.EdgeSentinelAppBinaryFile: + return m.clearedsentinel_app_binary_file + } + 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 { + switch name { + case sentinelappbinary.EdgeSentinelLibrary: + m.ClearSentinelLibrary() + return nil + } + 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 { + switch name { + case sentinelappbinary.EdgeSentinelLibrary: + m.ResetSentinelLibrary() + return nil + case sentinelappbinary.EdgeSentinelAppBinaryFile: + m.ResetSentinelAppBinaryFile() + return nil + } + 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 + 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 + clearedFields map[string]struct{} + sentinel_app_binary *int + clearedsentinel_app_binary bool + 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) + } +} + +// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. +func (m *SentinelAppBinaryFileMutation) SetSentinelAppBinaryID(i int) { + m.sentinel_app_binary = &i +} + +// SentinelAppBinaryID returns the value of the "sentinel_app_binary_id" field in the mutation. +func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryID() (r int, exists bool) { + v := m.sentinel_app_binary + if v == nil { + return + } + return *v, true +} + +// OldSentinelAppBinaryID returns the old "sentinel_app_binary_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) OldSentinelAppBinaryID(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSentinelAppBinaryID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSentinelAppBinaryID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSentinelAppBinaryID: %w", err) + } + return oldValue.SentinelAppBinaryID, nil +} + +// ResetSentinelAppBinaryID resets all changes to the "sentinel_app_binary_id" field. +func (m *SentinelAppBinaryFileMutation) ResetSentinelAppBinaryID() { + m.sentinel_app_binary = 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 +} + +// ClearSentinelAppBinary clears the "sentinel_app_binary" edge to the SentinelAppBinary entity. +func (m *SentinelAppBinaryFileMutation) ClearSentinelAppBinary() { + m.clearedsentinel_app_binary = true + m.clearedFields[sentinelappbinaryfile.FieldSentinelAppBinaryID] = struct{}{} +} + +// SentinelAppBinaryCleared reports if the "sentinel_app_binary" edge to the SentinelAppBinary entity was cleared. +func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryCleared() bool { + return m.clearedsentinel_app_binary +} + +// SentinelAppBinaryIDs returns the "sentinel_app_binary" edge IDs in the mutation. +// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use +// SentinelAppBinaryID instead. It exists only for internal usage by the builders. +func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryIDs() (ids []int) { + if id := m.sentinel_app_binary; id != nil { + ids = append(ids, *id) + } + return +} + +// ResetSentinelAppBinary resets all changes to the "sentinel_app_binary" edge. +func (m *SentinelAppBinaryFileMutation) ResetSentinelAppBinary() { + m.sentinel_app_binary = nil + m.clearedsentinel_app_binary = false +} + +// 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, 8) + if m.sentinel_app_binary != nil { + fields = append(fields, sentinelappbinaryfile.FieldSentinelAppBinaryID) + } + 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) + } + 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.FieldSentinelAppBinaryID: + return m.SentinelAppBinaryID() + 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() + } + 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.FieldSentinelAppBinaryID: + return m.OldSentinelAppBinaryID(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) + } + 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.FieldSentinelAppBinaryID: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSentinelAppBinaryID(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 + } + 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.addsize_bytes != nil { + fields = append(fields, sentinelappbinaryfile.FieldSizeBytes) + } + 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.FieldSizeBytes: + return m.AddedSizeBytes() + } + 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.FieldSizeBytes: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddSizeBytes(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.FieldSentinelAppBinaryID: + m.ResetSentinelAppBinaryID() + 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 + } + 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, 1) + if m.sentinel_app_binary != nil { + edges = append(edges, sentinelappbinaryfile.EdgeSentinelAppBinary) + } + 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 { + switch name { + case sentinelappbinaryfile.EdgeSentinelAppBinary: + if id := m.sentinel_app_binary; id != nil { + return []ent.Value{*id} + } + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *SentinelAppBinaryFileMutation) 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 *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, 1) + if m.clearedsentinel_app_binary { + edges = append(edges, sentinelappbinaryfile.EdgeSentinelAppBinary) + } + 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 { + switch name { + case sentinelappbinaryfile.EdgeSentinelAppBinary: + return m.clearedsentinel_app_binary + } + 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 { + switch name { + case sentinelappbinaryfile.EdgeSentinelAppBinary: + m.ClearSentinelAppBinary() + return nil + } + 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 { + switch name { + case sentinelappbinaryfile.EdgeSentinelAppBinary: + m.ResetSentinelAppBinary() + return nil + } + 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 *int + user_id *model.InternalID + adduser_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 + 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 int) 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 +} + +// 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 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 *SentinelInfoMutation) 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().SentinelInfo.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetUserID sets the "user_id" field. +func (m *SentinelInfoMutation) SetUserID(mi model.InternalID) { + m.user_id = &mi + m.adduser_id = nil +} + +// UserID returns the value of the "user_id" field in the mutation. +func (m *SentinelInfoMutation) UserID() (r model.InternalID, exists bool) { + v := m.user_id + if v == nil { + return + } + return *v, true +} + +// OldUserID returns the old "user_id" 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) OldUserID(ctx context.Context) (v model.InternalID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUserID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUserID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUserID: %w", err) + } + return oldValue.UserID, nil +} + +// AddUserID adds mi to the "user_id" field. +func (m *SentinelInfoMutation) AddUserID(mi model.InternalID) { + if m.adduser_id != nil { + *m.adduser_id += mi + } else { + m.adduser_id = &mi + } +} + +// AddedUserID returns the value that was added to the "user_id" field in this mutation. +func (m *SentinelInfoMutation) AddedUserID() (r model.InternalID, exists bool) { + v := m.adduser_id + if v == nil { + return + } + return *v, true +} + +// ResetUserID resets all changes to the "user_id" field. +func (m *SentinelInfoMutation) ResetUserID() { + m.user_id = nil + m.adduser_id = nil +} + +// 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 +} + +// 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, 7) + if m.user_id != nil { + fields = append(fields, sentinelinfo.FieldUserID) + } + 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) + } + 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.FieldUserID: + return m.UserID() + 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() + } + 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.FieldUserID: + return m.OldUserID(ctx) + 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) + } + 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.FieldUserID: + v, ok := value.(model.InternalID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUserID(v) + return nil + 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 + } + 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.adduser_id != nil { + fields = append(fields, sentinelinfo.FieldUserID) + } + 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.FieldUserID: + return m.AddedUserID() + } + 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.FieldUserID: + v, ok := value.(model.InternalID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddUserID(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.FieldUserID: + m.ResetUserID() + return nil + 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 + } + 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 + clearedFields map[string]struct{} + sentinel_info *int + clearedsentinel_info bool + sentinel_app_binary map[int]struct{} + removedsentinel_app_binary map[int]struct{} + clearedsentinel_app_binary 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(i int) { + m.sentinel_info = &i +} + +// SentinelInfoID returns the value of the "sentinel_info_id" field in the mutation. +func (m *SentinelLibraryMutation) SentinelInfoID() (r int, 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 int, 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 +} + +// 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 []int) { + 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 +} + +// AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by ids. +func (m *SentinelLibraryMutation) AddSentinelAppBinaryIDs(ids ...int) { + if m.sentinel_app_binary == nil { + m.sentinel_app_binary = make(map[int]struct{}) + } + for i := range ids { + m.sentinel_app_binary[ids[i]] = struct{}{} + } +} + +// ClearSentinelAppBinary clears the "sentinel_app_binary" edge to the SentinelAppBinary entity. +func (m *SentinelLibraryMutation) ClearSentinelAppBinary() { + m.clearedsentinel_app_binary = true +} + +// SentinelAppBinaryCleared reports if the "sentinel_app_binary" edge to the SentinelAppBinary entity was cleared. +func (m *SentinelLibraryMutation) SentinelAppBinaryCleared() bool { + return m.clearedsentinel_app_binary +} + +// RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. +func (m *SentinelLibraryMutation) RemoveSentinelAppBinaryIDs(ids ...int) { + if m.removedsentinel_app_binary == nil { + m.removedsentinel_app_binary = make(map[int]struct{}) + } + for i := range ids { + delete(m.sentinel_app_binary, ids[i]) + m.removedsentinel_app_binary[ids[i]] = struct{}{} + } +} + +// RemovedSentinelAppBinary returns the removed IDs of the "sentinel_app_binary" edge to the SentinelAppBinary entity. +func (m *SentinelLibraryMutation) RemovedSentinelAppBinaryIDs() (ids []int) { + for id := range m.removedsentinel_app_binary { + ids = append(ids, id) + } + return +} + +// SentinelAppBinaryIDs returns the "sentinel_app_binary" edge IDs in the mutation. +func (m *SentinelLibraryMutation) SentinelAppBinaryIDs() (ids []int) { + for id := range m.sentinel_app_binary { + ids = append(ids, id) + } + return +} + +// ResetSentinelAppBinary resets all changes to the "sentinel_app_binary" edge. +func (m *SentinelLibraryMutation) ResetSentinelAppBinary() { + m.sentinel_app_binary = nil + m.clearedsentinel_app_binary = false + m.removedsentinel_app_binary = nil +} + +// 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, 5) + 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) + } + 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() + } + 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) + } + 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.(int) + 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 + } + 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) + } + 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() + } + 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 + } + 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 + } + 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, 2) + if m.sentinel_info != nil { + edges = append(edges, sentinellibrary.EdgeSentinelInfo) + } + if m.sentinel_app_binary != nil { + edges = append(edges, sentinellibrary.EdgeSentinelAppBinary) + } + 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} + } + case sentinellibrary.EdgeSentinelAppBinary: + ids := make([]ent.Value, 0, len(m.sentinel_app_binary)) + for id := range m.sentinel_app_binary { + ids = append(ids, id) + } + return ids + } + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *SentinelLibraryMutation) RemovedEdges() []string { + edges := make([]string, 0, 2) + if m.removedsentinel_app_binary != nil { + edges = append(edges, sentinellibrary.EdgeSentinelAppBinary) + } + 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 { + switch name { + case sentinellibrary.EdgeSentinelAppBinary: + ids := make([]ent.Value, 0, len(m.removedsentinel_app_binary)) + for id := range m.removedsentinel_app_binary { + ids = append(ids, id) + } + return ids + } + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *SentinelLibraryMutation) ClearedEdges() []string { + edges := make([]string, 0, 2) + if m.clearedsentinel_info { + edges = append(edges, sentinellibrary.EdgeSentinelInfo) + } + if m.clearedsentinel_app_binary { + edges = append(edges, sentinellibrary.EdgeSentinelAppBinary) + } + 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 + case sentinellibrary.EdgeSentinelAppBinary: + return m.clearedsentinel_app_binary + } + 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 + case sentinellibrary.EdgeSentinelAppBinary: + m.ResetSentinelAppBinary() + 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..821891c6 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[8].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[9].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[6].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[7].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..bf257ee8 --- /dev/null +++ b/internal/data/internal/ent/schema/sentinel_app_binary.go @@ -0,0 +1,48 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "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.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), + } +} + +func (SentinelAppBinary) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("sentinel_library_id", "generated_id"), + } +} + +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..3f4fc30c --- /dev/null +++ b/internal/data/internal/ent/schema/sentinel_app_binary_file.go @@ -0,0 +1,44 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/schema/edge" + "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.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), + } +} + +func (SentinelAppBinaryFile) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("sentinel_app_binary_id", "name"), + } +} + +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..a233d82f --- /dev/null +++ b/internal/data/internal/ent/schema/sentinel_info.go @@ -0,0 +1,43 @@ +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 SentinelInfo struct { + ent.Schema +} + +func (SentinelInfo) Fields() []ent.Field { + return []ent.Field{ + field.Int64("user_id").GoType(model.InternalID(0)), + 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), + } +} + +func (SentinelInfo) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("user_id"), + } +} + +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..0f8c8345 --- /dev/null +++ b/internal/data/internal/ent/schema/sentinel_library.go @@ -0,0 +1,42 @@ +package schema + +import ( + "time" + + "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.Int("sentinel_info_id"), + 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), + } +} +func (SentinelLibrary) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("sentinel_info_id", "reported_id"), + } +} + +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..c55dcecd --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary.go @@ -0,0 +1,252 @@ +// 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/data/internal/ent/sentinellibrary" +) + +// SentinelAppBinary is the model entity for the SentinelAppBinary schema. +type SentinelAppBinary struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // SentinelLibraryID holds the value of the "sentinel_library_id" field. + SentinelLibraryID int `json:"sentinel_library_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"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the SentinelAppBinaryQuery when eager-loading is set. + Edges SentinelAppBinaryEdges `json:"edges"` + selectValues sql.SelectValues +} + +// SentinelAppBinaryEdges holds the relations/edges for other nodes in the graph. +type SentinelAppBinaryEdges struct { + // SentinelLibrary holds the value of the sentinel_library edge. + SentinelLibrary *SentinelLibrary `json:"sentinel_library,omitempty"` + // SentinelAppBinaryFile holds the value of the sentinel_app_binary_file edge. + SentinelAppBinaryFile []*SentinelAppBinaryFile `json:"sentinel_app_binary_file,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [2]bool +} + +// SentinelLibraryOrErr returns the SentinelLibrary value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e SentinelAppBinaryEdges) SentinelLibraryOrErr() (*SentinelLibrary, error) { + if e.SentinelLibrary != nil { + return e.SentinelLibrary, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: sentinellibrary.Label} + } + return nil, &NotLoadedError{edge: "sentinel_library"} +} + +// SentinelAppBinaryFileOrErr returns the SentinelAppBinaryFile value or an error if the edge +// was not loaded in eager-loading. +func (e SentinelAppBinaryEdges) SentinelAppBinaryFileOrErr() ([]*SentinelAppBinaryFile, error) { + if e.loadedTypes[1] { + return e.SentinelAppBinaryFile, nil + } + return nil, &NotLoadedError{edge: "sentinel_app_binary_file"} +} + +// 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.FieldSentinelLibraryID, sentinelappbinary.FieldSizeBytes: + 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.FieldSentinelLibraryID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field sentinel_library_id", values[i]) + } else if value.Valid { + sab.SentinelLibraryID = int(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 + } + 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) +} + +// QuerySentinelLibrary queries the "sentinel_library" edge of the SentinelAppBinary entity. +func (sab *SentinelAppBinary) QuerySentinelLibrary() *SentinelLibraryQuery { + return NewSentinelAppBinaryClient(sab.config).QuerySentinelLibrary(sab) +} + +// QuerySentinelAppBinaryFile queries the "sentinel_app_binary_file" edge of the SentinelAppBinary entity. +func (sab *SentinelAppBinary) QuerySentinelAppBinaryFile() *SentinelAppBinaryFileQuery { + return NewSentinelAppBinaryClient(sab.config).QuerySentinelAppBinaryFile(sab) +} + +// 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_library_id=") + builder.WriteString(fmt.Sprintf("%v", sab.SentinelLibraryID)) + 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.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..06fd4b7a --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go @@ -0,0 +1,184 @@ +// Code generated by ent, DO NOT EDIT. + +package sentinelappbinary + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +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" + // FieldSentinelLibraryID holds the string denoting the sentinel_library_id field in the database. + FieldSentinelLibraryID = "sentinel_library_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" + // EdgeSentinelLibrary holds the string denoting the sentinel_library edge name in mutations. + EdgeSentinelLibrary = "sentinel_library" + // EdgeSentinelAppBinaryFile holds the string denoting the sentinel_app_binary_file edge name in mutations. + EdgeSentinelAppBinaryFile = "sentinel_app_binary_file" + // Table holds the table name of the sentinelappbinary in the database. + Table = "sentinel_app_binaries" + // SentinelLibraryTable is the table that holds the sentinel_library relation/edge. + SentinelLibraryTable = "sentinel_app_binaries" + // 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_library_id" + // SentinelAppBinaryFileTable is the table that holds the sentinel_app_binary_file relation/edge. + SentinelAppBinaryFileTable = "sentinel_app_binary_files" + // SentinelAppBinaryFileInverseTable is the table name for the SentinelAppBinaryFile entity. + // It exists in this package in order to avoid circular dependency with the "sentinelappbinaryfile" package. + SentinelAppBinaryFileInverseTable = "sentinel_app_binary_files" + // SentinelAppBinaryFileColumn is the table column denoting the sentinel_app_binary_file relation/edge. + SentinelAppBinaryFileColumn = "sentinel_app_binary_id" +) + +// Columns holds all SQL columns for sentinelappbinary fields. +var Columns = []string{ + FieldID, + FieldSentinelLibraryID, + FieldGeneratedID, + FieldSizeBytes, + FieldNeedToken, + FieldName, + FieldVersion, + FieldDeveloper, + FieldPublisher, + FieldUpdatedAt, + FieldCreatedAt, +} + +// 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() +} + +// BySentinelLibraryID orders the results by the sentinel_library_id field. +func BySentinelLibraryID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSentinelLibraryID, 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() +} + +// BySentinelLibraryField orders the results by sentinel_library field. +func BySentinelLibraryField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSentinelLibraryStep(), sql.OrderByField(field, opts...)) + } +} + +// BySentinelAppBinaryFileCount orders the results by sentinel_app_binary_file count. +func BySentinelAppBinaryFileCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newSentinelAppBinaryFileStep(), opts...) + } +} + +// BySentinelAppBinaryFile orders the results by sentinel_app_binary_file terms. +func BySentinelAppBinaryFile(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSentinelAppBinaryFileStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newSentinelLibraryStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SentinelLibraryInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, SentinelLibraryTable, SentinelLibraryColumn), + ) +} +func newSentinelAppBinaryFileStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SentinelAppBinaryFileInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, SentinelAppBinaryFileTable, SentinelAppBinaryFileColumn), + ) +} diff --git a/internal/data/internal/ent/sentinelappbinary/where.go b/internal/data/internal/ent/sentinelappbinary/where.go new file mode 100644 index 00000000..0be68fe9 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary/where.go @@ -0,0 +1,682 @@ +// Code generated by ent, DO NOT EDIT. + +package sentinelappbinary + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" +) + +// 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)) +} + +// SentinelLibraryID applies equality check predicate on the "sentinel_library_id" field. It's identical to SentinelLibraryIDEQ. +func SentinelLibraryID(v int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, 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)) +} + +// SentinelLibraryIDEQ applies the EQ predicate on the "sentinel_library_id" field. +func SentinelLibraryIDEQ(v int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, v)) +} + +// SentinelLibraryIDNEQ applies the NEQ predicate on the "sentinel_library_id" field. +func SentinelLibraryIDNEQ(v int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldSentinelLibraryID, v)) +} + +// SentinelLibraryIDIn applies the In predicate on the "sentinel_library_id" field. +func SentinelLibraryIDIn(vs ...int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldSentinelLibraryID, vs...)) +} + +// SentinelLibraryIDNotIn applies the NotIn predicate on the "sentinel_library_id" field. +func SentinelLibraryIDNotIn(vs ...int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldSentinelLibraryID, vs...)) +} + +// 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)) +} + +// HasSentinelLibrary applies the HasEdge predicate on the "sentinel_library" edge. +func HasSentinelLibrary() predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, 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.SentinelAppBinary { + return predicate.SentinelAppBinary(func(s *sql.Selector) { + step := newSentinelLibraryStep() + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasSentinelAppBinaryFile applies the HasEdge predicate on the "sentinel_app_binary_file" edge. +func HasSentinelAppBinaryFile() predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, SentinelAppBinaryFileTable, SentinelAppBinaryFileColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSentinelAppBinaryFileWith applies the HasEdge predicate on the "sentinel_app_binary_file" edge with a given conditions (other predicates). +func HasSentinelAppBinaryFileWith(preds ...predicate.SentinelAppBinaryFile) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(func(s *sql.Selector) { + step := newSentinelAppBinaryFileStep() + 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.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..59891699 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary_create.go @@ -0,0 +1,1136 @@ +// 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/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" +) + +// SentinelAppBinaryCreate is the builder for creating a SentinelAppBinary entity. +type SentinelAppBinaryCreate struct { + config + mutation *SentinelAppBinaryMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetSentinelLibraryID sets the "sentinel_library_id" field. +func (sabc *SentinelAppBinaryCreate) SetSentinelLibraryID(i int) *SentinelAppBinaryCreate { + sabc.mutation.SetSentinelLibraryID(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 +} + +// SetSentinelLibrary sets the "sentinel_library" edge to the SentinelLibrary entity. +func (sabc *SentinelAppBinaryCreate) SetSentinelLibrary(s *SentinelLibrary) *SentinelAppBinaryCreate { + return sabc.SetSentinelLibraryID(s.ID) +} + +// AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. +func (sabc *SentinelAppBinaryCreate) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryCreate { + sabc.mutation.AddSentinelAppBinaryFileIDs(ids...) + return sabc +} + +// AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. +func (sabc *SentinelAppBinaryCreate) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryCreate { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return sabc.AddSentinelAppBinaryFileIDs(ids...) +} + +// 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.SentinelLibraryID(); !ok { + return &ValidationError{Name: "sentinel_library_id", err: errors.New(`ent: missing required field "SentinelAppBinary.sentinel_library_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 len(sabc.mutation.SentinelLibraryIDs()) == 0 { + return &ValidationError{Name: "sentinel_library", err: errors.New(`ent: missing required edge "SentinelAppBinary.sentinel_library"`)} + } + 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.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 nodes := sabc.mutation.SentinelLibraryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinelappbinary.SentinelLibraryTable, + Columns: []string{sentinelappbinary.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) + } + _node.SentinelLibraryID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := sabc.mutation.SentinelAppBinaryFileIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelappbinary.SentinelAppBinaryFileTable, + Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.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.SentinelAppBinary.Create(). +// SetSentinelLibraryID(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) { +// SetSentinelLibraryID(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 + } +) + +// SetSentinelLibraryID sets the "sentinel_library_id" field. +func (u *SentinelAppBinaryUpsert) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldSentinelLibraryID, v) + return u +} + +// UpdateSentinelLibraryID sets the "sentinel_library_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateSentinelLibraryID() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldSentinelLibraryID) + 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 +} + +// 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 +} + +// SetSentinelLibraryID sets the "sentinel_library_id" field. +func (u *SentinelAppBinaryUpsertOne) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetSentinelLibraryID(v) + }) +} + +// UpdateSentinelLibraryID sets the "sentinel_library_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateSentinelLibraryID() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateSentinelLibraryID() + }) +} + +// 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() + }) +} + +// 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) { +// SetSentinelLibraryID(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 +} + +// SetSentinelLibraryID sets the "sentinel_library_id" field. +func (u *SentinelAppBinaryUpsertBulk) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetSentinelLibraryID(v) + }) +} + +// UpdateSentinelLibraryID sets the "sentinel_library_id" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateSentinelLibraryID() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateSentinelLibraryID() + }) +} + +// 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() + }) +} + +// 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..14486346 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary_query.go @@ -0,0 +1,683 @@ +// 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/sentinelappbinary" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" +) + +// SentinelAppBinaryQuery is the builder for querying SentinelAppBinary entities. +type SentinelAppBinaryQuery struct { + config + ctx *QueryContext + order []sentinelappbinary.OrderOption + inters []Interceptor + predicates []predicate.SentinelAppBinary + withSentinelLibrary *SentinelLibraryQuery + withSentinelAppBinaryFile *SentinelAppBinaryFileQuery + // 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 +} + +// QuerySentinelLibrary chains the current query on the "sentinel_library" edge. +func (sabq *SentinelAppBinaryQuery) QuerySentinelLibrary() *SentinelLibraryQuery { + query := (&SentinelLibraryClient{config: sabq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := sabq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := sabq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(sentinelappbinary.Table, sentinelappbinary.FieldID, selector), + sqlgraph.To(sentinellibrary.Table, sentinellibrary.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, sentinelappbinary.SentinelLibraryTable, sentinelappbinary.SentinelLibraryColumn), + ) + fromU = sqlgraph.SetNeighbors(sabq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QuerySentinelAppBinaryFile chains the current query on the "sentinel_app_binary_file" edge. +func (sabq *SentinelAppBinaryQuery) QuerySentinelAppBinaryFile() *SentinelAppBinaryFileQuery { + query := (&SentinelAppBinaryFileClient{config: sabq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := sabq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := sabq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(sentinelappbinary.Table, sentinelappbinary.FieldID, selector), + sqlgraph.To(sentinelappbinaryfile.Table, sentinelappbinaryfile.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, sentinelappbinary.SentinelAppBinaryFileTable, sentinelappbinary.SentinelAppBinaryFileColumn), + ) + fromU = sqlgraph.SetNeighbors(sabq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// 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...), + withSentinelLibrary: sabq.withSentinelLibrary.Clone(), + withSentinelAppBinaryFile: sabq.withSentinelAppBinaryFile.Clone(), + // clone intermediate query. + sql: sabq.sql.Clone(), + path: sabq.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 (sabq *SentinelAppBinaryQuery) WithSentinelLibrary(opts ...func(*SentinelLibraryQuery)) *SentinelAppBinaryQuery { + query := (&SentinelLibraryClient{config: sabq.config}).Query() + for _, opt := range opts { + opt(query) + } + sabq.withSentinelLibrary = query + return sabq +} + +// WithSentinelAppBinaryFile tells the query-builder to eager-load the nodes that are connected to +// the "sentinel_app_binary_file" edge. The optional arguments are used to configure the query builder of the edge. +func (sabq *SentinelAppBinaryQuery) WithSentinelAppBinaryFile(opts ...func(*SentinelAppBinaryFileQuery)) *SentinelAppBinaryQuery { + query := (&SentinelAppBinaryFileClient{config: sabq.config}).Query() + for _, opt := range opts { + opt(query) + } + sabq.withSentinelAppBinaryFile = query + return sabq +} + +// 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 { +// SentinelLibraryID int `json:"sentinel_library_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.SentinelAppBinary.Query(). +// GroupBy(sentinelappbinary.FieldSentinelLibraryID). +// 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 { +// SentinelLibraryID int `json:"sentinel_library_id,omitempty"` +// } +// +// client.SentinelAppBinary.Query(). +// Select(sentinelappbinary.FieldSentinelLibraryID). +// 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() + loadedTypes = [2]bool{ + sabq.withSentinelLibrary != nil, + sabq.withSentinelAppBinaryFile != nil, + } + ) + _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) + node.Edges.loadedTypes = loadedTypes + 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 + } + if query := sabq.withSentinelLibrary; query != nil { + if err := sabq.loadSentinelLibrary(ctx, query, nodes, nil, + func(n *SentinelAppBinary, e *SentinelLibrary) { n.Edges.SentinelLibrary = e }); err != nil { + return nil, err + } + } + if query := sabq.withSentinelAppBinaryFile; query != nil { + if err := sabq.loadSentinelAppBinaryFile(ctx, query, nodes, + func(n *SentinelAppBinary) { n.Edges.SentinelAppBinaryFile = []*SentinelAppBinaryFile{} }, + func(n *SentinelAppBinary, e *SentinelAppBinaryFile) { + n.Edges.SentinelAppBinaryFile = append(n.Edges.SentinelAppBinaryFile, e) + }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (sabq *SentinelAppBinaryQuery) loadSentinelLibrary(ctx context.Context, query *SentinelLibraryQuery, nodes []*SentinelAppBinary, init func(*SentinelAppBinary), assign func(*SentinelAppBinary, *SentinelLibrary)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*SentinelAppBinary) + for i := range nodes { + fk := nodes[i].SentinelLibraryID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(sentinellibrary.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_library_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return nil +} +func (sabq *SentinelAppBinaryQuery) loadSentinelAppBinaryFile(ctx context.Context, query *SentinelAppBinaryFileQuery, nodes []*SentinelAppBinary, init func(*SentinelAppBinary), assign func(*SentinelAppBinary, *SentinelAppBinaryFile)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int]*SentinelAppBinary) + 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(sentinelappbinaryfile.FieldSentinelAppBinaryID) + } + query.Where(predicate.SentinelAppBinaryFile(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(sentinelappbinary.SentinelAppBinaryFileColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.SentinelAppBinaryID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "sentinel_app_binary_id" returned %v for node %v`, fk, n.ID) + } + assign(node, n) + } + return 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 sabq.withSentinelLibrary != nil { + _spec.Node.AddColumnOnce(sentinelappbinary.FieldSentinelLibraryID) + } + } + 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..150dc467 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinary_update.go @@ -0,0 +1,870 @@ +// 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/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" +) + +// 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 +} + +// SetSentinelLibraryID sets the "sentinel_library_id" field. +func (sabu *SentinelAppBinaryUpdate) SetSentinelLibraryID(i int) *SentinelAppBinaryUpdate { + sabu.mutation.SetSentinelLibraryID(i) + return sabu +} + +// SetNillableSentinelLibraryID sets the "sentinel_library_id" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableSentinelLibraryID(i *int) *SentinelAppBinaryUpdate { + if i != nil { + sabu.SetSentinelLibraryID(*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 +} + +// SetSentinelLibrary sets the "sentinel_library" edge to the SentinelLibrary entity. +func (sabu *SentinelAppBinaryUpdate) SetSentinelLibrary(s *SentinelLibrary) *SentinelAppBinaryUpdate { + return sabu.SetSentinelLibraryID(s.ID) +} + +// AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. +func (sabu *SentinelAppBinaryUpdate) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdate { + sabu.mutation.AddSentinelAppBinaryFileIDs(ids...) + return sabu +} + +// AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. +func (sabu *SentinelAppBinaryUpdate) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdate { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return sabu.AddSentinelAppBinaryFileIDs(ids...) +} + +// Mutation returns the SentinelAppBinaryMutation object of the builder. +func (sabu *SentinelAppBinaryUpdate) Mutation() *SentinelAppBinaryMutation { + return sabu.mutation +} + +// ClearSentinelLibrary clears the "sentinel_library" edge to the SentinelLibrary entity. +func (sabu *SentinelAppBinaryUpdate) ClearSentinelLibrary() *SentinelAppBinaryUpdate { + sabu.mutation.ClearSentinelLibrary() + return sabu +} + +// ClearSentinelAppBinaryFile clears all "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. +func (sabu *SentinelAppBinaryUpdate) ClearSentinelAppBinaryFile() *SentinelAppBinaryUpdate { + sabu.mutation.ClearSentinelAppBinaryFile() + return sabu +} + +// RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to SentinelAppBinaryFile entities by IDs. +func (sabu *SentinelAppBinaryUpdate) RemoveSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdate { + sabu.mutation.RemoveSentinelAppBinaryFileIDs(ids...) + return sabu +} + +// RemoveSentinelAppBinaryFile removes "sentinel_app_binary_file" edges to SentinelAppBinaryFile entities. +func (sabu *SentinelAppBinaryUpdate) RemoveSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdate { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return sabu.RemoveSentinelAppBinaryFileIDs(ids...) +} + +// 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) + } +} + +// check runs all checks and user-defined validators on the builder. +func (sabu *SentinelAppBinaryUpdate) check() error { + if sabu.mutation.SentinelLibraryCleared() && len(sabu.mutation.SentinelLibraryIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "SentinelAppBinary.sentinel_library"`) + } + return nil +} + +func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := sabu.check(); err != nil { + return n, err + } + _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.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 sabu.mutation.SentinelLibraryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinelappbinary.SentinelLibraryTable, + Columns: []string{sentinelappbinary.SentinelLibraryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := sabu.mutation.SentinelLibraryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinelappbinary.SentinelLibraryTable, + Columns: []string{sentinelappbinary.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 sabu.mutation.SentinelAppBinaryFileCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelappbinary.SentinelAppBinaryFileTable, + Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := sabu.mutation.RemovedSentinelAppBinaryFileIDs(); len(nodes) > 0 && !sabu.mutation.SentinelAppBinaryFileCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelappbinary.SentinelAppBinaryFileTable, + Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.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 := sabu.mutation.SentinelAppBinaryFileIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelappbinary.SentinelAppBinaryFileTable, + Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.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, 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 +} + +// SetSentinelLibraryID sets the "sentinel_library_id" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelLibraryID(i int) *SentinelAppBinaryUpdateOne { + sabuo.mutation.SetSentinelLibraryID(i) + return sabuo +} + +// SetNillableSentinelLibraryID sets the "sentinel_library_id" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableSentinelLibraryID(i *int) *SentinelAppBinaryUpdateOne { + if i != nil { + sabuo.SetSentinelLibraryID(*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 +} + +// SetSentinelLibrary sets the "sentinel_library" edge to the SentinelLibrary entity. +func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelLibrary(s *SentinelLibrary) *SentinelAppBinaryUpdateOne { + return sabuo.SetSentinelLibraryID(s.ID) +} + +// AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. +func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdateOne { + sabuo.mutation.AddSentinelAppBinaryFileIDs(ids...) + return sabuo +} + +// AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. +func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdateOne { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return sabuo.AddSentinelAppBinaryFileIDs(ids...) +} + +// Mutation returns the SentinelAppBinaryMutation object of the builder. +func (sabuo *SentinelAppBinaryUpdateOne) Mutation() *SentinelAppBinaryMutation { + return sabuo.mutation +} + +// ClearSentinelLibrary clears the "sentinel_library" edge to the SentinelLibrary entity. +func (sabuo *SentinelAppBinaryUpdateOne) ClearSentinelLibrary() *SentinelAppBinaryUpdateOne { + sabuo.mutation.ClearSentinelLibrary() + return sabuo +} + +// ClearSentinelAppBinaryFile clears all "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. +func (sabuo *SentinelAppBinaryUpdateOne) ClearSentinelAppBinaryFile() *SentinelAppBinaryUpdateOne { + sabuo.mutation.ClearSentinelAppBinaryFile() + return sabuo +} + +// RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to SentinelAppBinaryFile entities by IDs. +func (sabuo *SentinelAppBinaryUpdateOne) RemoveSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdateOne { + sabuo.mutation.RemoveSentinelAppBinaryFileIDs(ids...) + return sabuo +} + +// RemoveSentinelAppBinaryFile removes "sentinel_app_binary_file" edges to SentinelAppBinaryFile entities. +func (sabuo *SentinelAppBinaryUpdateOne) RemoveSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdateOne { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return sabuo.RemoveSentinelAppBinaryFileIDs(ids...) +} + +// 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) + } +} + +// check runs all checks and user-defined validators on the builder. +func (sabuo *SentinelAppBinaryUpdateOne) check() error { + if sabuo.mutation.SentinelLibraryCleared() && len(sabuo.mutation.SentinelLibraryIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "SentinelAppBinary.sentinel_library"`) + } + return nil +} + +func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *SentinelAppBinary, err error) { + if err := sabuo.check(); err != nil { + return _node, err + } + _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.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 sabuo.mutation.SentinelLibraryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinelappbinary.SentinelLibraryTable, + Columns: []string{sentinelappbinary.SentinelLibraryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := sabuo.mutation.SentinelLibraryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinelappbinary.SentinelLibraryTable, + Columns: []string{sentinelappbinary.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 sabuo.mutation.SentinelAppBinaryFileCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelappbinary.SentinelAppBinaryFileTable, + Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := sabuo.mutation.RemovedSentinelAppBinaryFileIDs(); len(nodes) > 0 && !sabuo.mutation.SentinelAppBinaryFileCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelappbinary.SentinelAppBinaryFileTable, + Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.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 := sabuo.mutation.SentinelAppBinaryFileIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinelappbinary.SentinelAppBinaryFileTable, + Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _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..490e770f --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile.go @@ -0,0 +1,214 @@ +// 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/data/internal/ent/sentinelappbinaryfile" +) + +// SentinelAppBinaryFile is the model entity for the SentinelAppBinaryFile schema. +type SentinelAppBinaryFile struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // SentinelAppBinaryID holds the value of the "sentinel_app_binary_id" field. + SentinelAppBinaryID int `json:"sentinel_app_binary_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"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the SentinelAppBinaryFileQuery when eager-loading is set. + Edges SentinelAppBinaryFileEdges `json:"edges"` + selectValues sql.SelectValues +} + +// SentinelAppBinaryFileEdges holds the relations/edges for other nodes in the graph. +type SentinelAppBinaryFileEdges struct { + // SentinelAppBinary holds the value of the sentinel_app_binary edge. + SentinelAppBinary *SentinelAppBinary `json:"sentinel_app_binary,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// SentinelAppBinaryOrErr returns the SentinelAppBinary value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e SentinelAppBinaryFileEdges) SentinelAppBinaryOrErr() (*SentinelAppBinary, error) { + if e.SentinelAppBinary != nil { + return e.SentinelAppBinary, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: sentinelappbinary.Label} + } + return nil, &NotLoadedError{edge: "sentinel_app_binary"} +} + +// 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.FieldSentinelAppBinaryID, sentinelappbinaryfile.FieldSizeBytes: + values[i] = new(sql.NullInt64) + case 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.FieldSentinelAppBinaryID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field sentinel_app_binary_id", values[i]) + } else if value.Valid { + sabf.SentinelAppBinaryID = int(value.Int64) + } + 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 + } + 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) +} + +// QuerySentinelAppBinary queries the "sentinel_app_binary" edge of the SentinelAppBinaryFile entity. +func (sabf *SentinelAppBinaryFile) QuerySentinelAppBinary() *SentinelAppBinaryQuery { + return NewSentinelAppBinaryFileClient(sabf.config).QuerySentinelAppBinary(sabf) +} + +// 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_app_binary_id=") + builder.WriteString(fmt.Sprintf("%v", sabf.SentinelAppBinaryID)) + 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.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..8614cf59 --- /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" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +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" + // FieldSentinelAppBinaryID holds the string denoting the sentinel_app_binary_id field in the database. + FieldSentinelAppBinaryID = "sentinel_app_binary_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" + // EdgeSentinelAppBinary holds the string denoting the sentinel_app_binary edge name in mutations. + EdgeSentinelAppBinary = "sentinel_app_binary" + // Table holds the table name of the sentinelappbinaryfile in the database. + Table = "sentinel_app_binary_files" + // SentinelAppBinaryTable is the table that holds the sentinel_app_binary relation/edge. + SentinelAppBinaryTable = "sentinel_app_binary_files" + // SentinelAppBinaryInverseTable is the table name for the SentinelAppBinary entity. + // It exists in this package in order to avoid circular dependency with the "sentinelappbinary" package. + SentinelAppBinaryInverseTable = "sentinel_app_binaries" + // SentinelAppBinaryColumn is the table column denoting the sentinel_app_binary relation/edge. + SentinelAppBinaryColumn = "sentinel_app_binary_id" +) + +// Columns holds all SQL columns for sentinelappbinaryfile fields. +var Columns = []string{ + FieldID, + FieldSentinelAppBinaryID, + FieldName, + FieldSizeBytes, + FieldSha256, + FieldServerFilePath, + FieldChunksInfo, + FieldUpdatedAt, + FieldCreatedAt, +} + +// 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() +} + +// BySentinelAppBinaryID orders the results by the sentinel_app_binary_id field. +func BySentinelAppBinaryID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSentinelAppBinaryID, 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() +} + +// BySentinelAppBinaryField orders the results by sentinel_app_binary field. +func BySentinelAppBinaryField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSentinelAppBinaryStep(), sql.OrderByField(field, opts...)) + } +} +func newSentinelAppBinaryStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SentinelAppBinaryInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, SentinelAppBinaryTable, SentinelAppBinaryColumn), + ) +} diff --git a/internal/data/internal/ent/sentinelappbinaryfile/where.go b/internal/data/internal/ent/sentinelappbinaryfile/where.go new file mode 100644 index 00000000..f55b839f --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile/where.go @@ -0,0 +1,519 @@ +// Code generated by ent, DO NOT EDIT. + +package sentinelappbinaryfile + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "github.com/tuihub/librarian/internal/data/internal/ent/predicate" +) + +// 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)) +} + +// SentinelAppBinaryID applies equality check predicate on the "sentinel_app_binary_id" field. It's identical to SentinelAppBinaryIDEQ. +func SentinelAppBinaryID(v int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, 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)) +} + +// SentinelAppBinaryIDEQ applies the EQ predicate on the "sentinel_app_binary_id" field. +func SentinelAppBinaryIDEQ(v int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, v)) +} + +// SentinelAppBinaryIDNEQ applies the NEQ predicate on the "sentinel_app_binary_id" field. +func SentinelAppBinaryIDNEQ(v int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldSentinelAppBinaryID, v)) +} + +// SentinelAppBinaryIDIn applies the In predicate on the "sentinel_app_binary_id" field. +func SentinelAppBinaryIDIn(vs ...int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldSentinelAppBinaryID, vs...)) +} + +// SentinelAppBinaryIDNotIn applies the NotIn predicate on the "sentinel_app_binary_id" field. +func SentinelAppBinaryIDNotIn(vs ...int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldSentinelAppBinaryID, vs...)) +} + +// 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)) +} + +// HasSentinelAppBinary applies the HasEdge predicate on the "sentinel_app_binary" edge. +func HasSentinelAppBinary() predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, SentinelAppBinaryTable, SentinelAppBinaryColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSentinelAppBinaryWith applies the HasEdge predicate on the "sentinel_app_binary" edge with a given conditions (other predicates). +func HasSentinelAppBinaryWith(preds ...predicate.SentinelAppBinary) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(func(s *sql.Selector) { + step := newSentinelAppBinaryStep() + 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.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..20650a8f --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile_create.go @@ -0,0 +1,923 @@ +// 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/data/internal/ent/sentinelappbinaryfile" +) + +// SentinelAppBinaryFileCreate is the builder for creating a SentinelAppBinaryFile entity. +type SentinelAppBinaryFileCreate struct { + config + mutation *SentinelAppBinaryFileMutation + hooks []Hook + conflict []sql.ConflictOption +} + +// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. +func (sabfc *SentinelAppBinaryFileCreate) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetSentinelAppBinaryID(i) + 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 +} + +// SetSentinelAppBinary sets the "sentinel_app_binary" edge to the SentinelAppBinary entity. +func (sabfc *SentinelAppBinaryFileCreate) SetSentinelAppBinary(s *SentinelAppBinary) *SentinelAppBinaryFileCreate { + return sabfc.SetSentinelAppBinaryID(s.ID) +} + +// 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.SentinelAppBinaryID(); !ok { + return &ValidationError{Name: "sentinel_app_binary_id", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.sentinel_app_binary_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 len(sabfc.mutation.SentinelAppBinaryIDs()) == 0 { + return &ValidationError{Name: "sentinel_app_binary", err: errors.New(`ent: missing required edge "SentinelAppBinaryFile.sentinel_app_binary"`)} + } + 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.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 nodes := sabfc.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinelappbinaryfile.SentinelAppBinaryTable, + Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.SentinelAppBinaryID = 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.SentinelAppBinaryFile.Create(). +// SetSentinelAppBinaryID(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) { +// SetSentinelAppBinaryID(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 + } +) + +// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. +func (u *SentinelAppBinaryFileUpsert) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsert { + u.Set(sentinelappbinaryfile.FieldSentinelAppBinaryID, v) + return u +} + +// UpdateSentinelAppBinaryID sets the "sentinel_app_binary_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsert) UpdateSentinelAppBinaryID() *SentinelAppBinaryFileUpsert { + u.SetExcluded(sentinelappbinaryfile.FieldSentinelAppBinaryID) + 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 +} + +// 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 +} + +// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. +func (u *SentinelAppBinaryFileUpsertOne) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSentinelAppBinaryID(v) + }) +} + +// UpdateSentinelAppBinaryID sets the "sentinel_app_binary_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertOne) UpdateSentinelAppBinaryID() *SentinelAppBinaryFileUpsertOne { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSentinelAppBinaryID() + }) +} + +// 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() + }) +} + +// 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) { +// SetSentinelAppBinaryID(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 +} + +// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. +func (u *SentinelAppBinaryFileUpsertBulk) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.SetSentinelAppBinaryID(v) + }) +} + +// UpdateSentinelAppBinaryID sets the "sentinel_app_binary_id" field to the value that was provided on create. +func (u *SentinelAppBinaryFileUpsertBulk) UpdateSentinelAppBinaryID() *SentinelAppBinaryFileUpsertBulk { + return u.Update(func(s *SentinelAppBinaryFileUpsert) { + s.UpdateSentinelAppBinaryID() + }) +} + +// 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() + }) +} + +// 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..5dec5c78 --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile_query.go @@ -0,0 +1,606 @@ +// 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" + "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 + withSentinelAppBinary *SentinelAppBinaryQuery + // 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 +} + +// QuerySentinelAppBinary chains the current query on the "sentinel_app_binary" edge. +func (sabfq *SentinelAppBinaryFileQuery) QuerySentinelAppBinary() *SentinelAppBinaryQuery { + query := (&SentinelAppBinaryClient{config: sabfq.config}).Query() + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := sabfq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := sabfq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(sentinelappbinaryfile.Table, sentinelappbinaryfile.FieldID, selector), + sqlgraph.To(sentinelappbinary.Table, sentinelappbinary.FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, sentinelappbinaryfile.SentinelAppBinaryTable, sentinelappbinaryfile.SentinelAppBinaryColumn), + ) + fromU = sqlgraph.SetNeighbors(sabfq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// 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...), + withSentinelAppBinary: sabfq.withSentinelAppBinary.Clone(), + // clone intermediate query. + sql: sabfq.sql.Clone(), + path: sabfq.path, + } +} + +// WithSentinelAppBinary tells the query-builder to eager-load the nodes that are connected to +// the "sentinel_app_binary" edge. The optional arguments are used to configure the query builder of the edge. +func (sabfq *SentinelAppBinaryFileQuery) WithSentinelAppBinary(opts ...func(*SentinelAppBinaryQuery)) *SentinelAppBinaryFileQuery { + query := (&SentinelAppBinaryClient{config: sabfq.config}).Query() + for _, opt := range opts { + opt(query) + } + sabfq.withSentinelAppBinary = query + return sabfq +} + +// 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 { +// SentinelAppBinaryID int `json:"sentinel_app_binary_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.SentinelAppBinaryFile.Query(). +// GroupBy(sentinelappbinaryfile.FieldSentinelAppBinaryID). +// 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 { +// SentinelAppBinaryID int `json:"sentinel_app_binary_id,omitempty"` +// } +// +// client.SentinelAppBinaryFile.Query(). +// Select(sentinelappbinaryfile.FieldSentinelAppBinaryID). +// 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() + loadedTypes = [1]bool{ + sabfq.withSentinelAppBinary != nil, + } + ) + _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) + node.Edges.loadedTypes = loadedTypes + 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 + } + if query := sabfq.withSentinelAppBinary; query != nil { + if err := sabfq.loadSentinelAppBinary(ctx, query, nodes, nil, + func(n *SentinelAppBinaryFile, e *SentinelAppBinary) { n.Edges.SentinelAppBinary = e }); err != nil { + return nil, err + } + } + return nodes, nil +} + +func (sabfq *SentinelAppBinaryFileQuery) loadSentinelAppBinary(ctx context.Context, query *SentinelAppBinaryQuery, nodes []*SentinelAppBinaryFile, init func(*SentinelAppBinaryFile), assign func(*SentinelAppBinaryFile, *SentinelAppBinary)) error { + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*SentinelAppBinaryFile) + for i := range nodes { + fk := nodes[i].SentinelAppBinaryID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + if len(ids) == 0 { + return nil + } + query.Where(sentinelappbinary.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_app_binary_id" returned %v`, n.ID) + } + for i := range nodes { + assign(nodes[i], n) + } + } + return 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 sabfq.withSentinelAppBinary != nil { + _spec.Node.AddColumnOnce(sentinelappbinaryfile.FieldSentinelAppBinaryID) + } + } + 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..8d8b050e --- /dev/null +++ b/internal/data/internal/ent/sentinelappbinaryfile_update.go @@ -0,0 +1,569 @@ +// 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/data/internal/ent/sentinelappbinaryfile" +) + +// 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 +} + +// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileUpdate { + sabfu.mutation.SetSentinelAppBinaryID(i) + return sabfu +} + +// SetNillableSentinelAppBinaryID sets the "sentinel_app_binary_id" field if the given value is not nil. +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableSentinelAppBinaryID(i *int) *SentinelAppBinaryFileUpdate { + if i != nil { + sabfu.SetSentinelAppBinaryID(*i) + } + 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 +} + +// SetSentinelAppBinary sets the "sentinel_app_binary" edge to the SentinelAppBinary entity. +func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelAppBinary(s *SentinelAppBinary) *SentinelAppBinaryFileUpdate { + return sabfu.SetSentinelAppBinaryID(s.ID) +} + +// Mutation returns the SentinelAppBinaryFileMutation object of the builder. +func (sabfu *SentinelAppBinaryFileUpdate) Mutation() *SentinelAppBinaryFileMutation { + return sabfu.mutation +} + +// ClearSentinelAppBinary clears the "sentinel_app_binary" edge to the SentinelAppBinary entity. +func (sabfu *SentinelAppBinaryFileUpdate) ClearSentinelAppBinary() *SentinelAppBinaryFileUpdate { + sabfu.mutation.ClearSentinelAppBinary() + return sabfu +} + +// 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) + } +} + +// check runs all checks and user-defined validators on the builder. +func (sabfu *SentinelAppBinaryFileUpdate) check() error { + if sabfu.mutation.SentinelAppBinaryCleared() && len(sabfu.mutation.SentinelAppBinaryIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "SentinelAppBinaryFile.sentinel_app_binary"`) + } + return nil +} + +func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := sabfu.check(); err != nil { + return n, err + } + _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.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 sabfu.mutation.SentinelAppBinaryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinelappbinaryfile.SentinelAppBinaryTable, + Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := sabfu.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinelappbinaryfile.SentinelAppBinaryTable, + Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.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, 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 +} + +// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.SetSentinelAppBinaryID(i) + return sabfuo +} + +// SetNillableSentinelAppBinaryID sets the "sentinel_app_binary_id" field if the given value is not nil. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableSentinelAppBinaryID(i *int) *SentinelAppBinaryFileUpdateOne { + if i != nil { + sabfuo.SetSentinelAppBinaryID(*i) + } + 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 +} + +// SetSentinelAppBinary sets the "sentinel_app_binary" edge to the SentinelAppBinary entity. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelAppBinary(s *SentinelAppBinary) *SentinelAppBinaryFileUpdateOne { + return sabfuo.SetSentinelAppBinaryID(s.ID) +} + +// Mutation returns the SentinelAppBinaryFileMutation object of the builder. +func (sabfuo *SentinelAppBinaryFileUpdateOne) Mutation() *SentinelAppBinaryFileMutation { + return sabfuo.mutation +} + +// ClearSentinelAppBinary clears the "sentinel_app_binary" edge to the SentinelAppBinary entity. +func (sabfuo *SentinelAppBinaryFileUpdateOne) ClearSentinelAppBinary() *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.ClearSentinelAppBinary() + return sabfuo +} + +// 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) + } +} + +// check runs all checks and user-defined validators on the builder. +func (sabfuo *SentinelAppBinaryFileUpdateOne) check() error { + if sabfuo.mutation.SentinelAppBinaryCleared() && len(sabfuo.mutation.SentinelAppBinaryIDs()) > 0 { + return errors.New(`ent: clearing a required unique edge "SentinelAppBinaryFile.sentinel_app_binary"`) + } + return nil +} + +func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_node *SentinelAppBinaryFile, err error) { + if err := sabfuo.check(); err != nil { + return _node, err + } + _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.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 sabfuo.mutation.SentinelAppBinaryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinelappbinaryfile.SentinelAppBinaryTable, + Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := sabfuo.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: false, + Table: sentinelappbinaryfile.SentinelAppBinaryTable, + Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _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..dc79e8b7 --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo.go @@ -0,0 +1,204 @@ +// 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 int `json:"id,omitempty"` + // UserID holds the value of the "user_id" field. + UserID model.InternalID `json:"user_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"` + // 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.FieldUserID: + 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: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + si.ID = int(value.Int64) + case sentinelinfo.FieldUserID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field user_id", values[i]) + } else if value.Valid { + si.UserID = 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 + } + 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("user_id=") + builder.WriteString(fmt.Sprintf("%v", si.UserID)) + builder.WriteString(", ") + 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.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..8e0f39c0 --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo/sentinelinfo.go @@ -0,0 +1,132 @@ +// 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" + // FieldUserID holds the string denoting the user_id field in the database. + FieldUserID = "user_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" + // 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, + FieldUserID, + FieldURL, + FieldAlternativeUrls, + FieldGetTokenPath, + FieldDownloadFileBasePath, + FieldUpdatedAt, + FieldCreatedAt, +} + +// 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() +} + +// ByUserID orders the results by the user_id field. +func ByUserID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUserID, 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() +} + +// 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..a4f99ef0 --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo/where.go @@ -0,0 +1,475 @@ +// 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 int) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.SentinelInfo { + return predicate.SentinelInfo(sql.FieldLTE(FieldID, id)) +} + +// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ. +func UserID(v model.InternalID) predicate.SentinelInfo { + vc := int64(v) + return predicate.SentinelInfo(sql.FieldEQ(FieldUserID, vc)) +} + +// 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)) +} + +// UserIDEQ applies the EQ predicate on the "user_id" field. +func UserIDEQ(v model.InternalID) predicate.SentinelInfo { + vc := int64(v) + return predicate.SentinelInfo(sql.FieldEQ(FieldUserID, vc)) +} + +// UserIDNEQ applies the NEQ predicate on the "user_id" field. +func UserIDNEQ(v model.InternalID) predicate.SentinelInfo { + vc := int64(v) + return predicate.SentinelInfo(sql.FieldNEQ(FieldUserID, vc)) +} + +// UserIDIn applies the In predicate on the "user_id" field. +func UserIDIn(vs ...model.InternalID) predicate.SentinelInfo { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelInfo(sql.FieldIn(FieldUserID, v...)) +} + +// UserIDNotIn applies the NotIn predicate on the "user_id" field. +func UserIDNotIn(vs ...model.InternalID) predicate.SentinelInfo { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelInfo(sql.FieldNotIn(FieldUserID, v...)) +} + +// UserIDGT applies the GT predicate on the "user_id" field. +func UserIDGT(v model.InternalID) predicate.SentinelInfo { + vc := int64(v) + return predicate.SentinelInfo(sql.FieldGT(FieldUserID, vc)) +} + +// UserIDGTE applies the GTE predicate on the "user_id" field. +func UserIDGTE(v model.InternalID) predicate.SentinelInfo { + vc := int64(v) + return predicate.SentinelInfo(sql.FieldGTE(FieldUserID, vc)) +} + +// UserIDLT applies the LT predicate on the "user_id" field. +func UserIDLT(v model.InternalID) predicate.SentinelInfo { + vc := int64(v) + return predicate.SentinelInfo(sql.FieldLT(FieldUserID, vc)) +} + +// UserIDLTE applies the LTE predicate on the "user_id" field. +func UserIDLTE(v model.InternalID) predicate.SentinelInfo { + vc := int64(v) + return predicate.SentinelInfo(sql.FieldLTE(FieldUserID, vc)) +} + +// 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)) +} + +// 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..efeb0199 --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo_create.go @@ -0,0 +1,898 @@ +// 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 +} + +// SetUserID sets the "user_id" field. +func (sic *SentinelInfoCreate) SetUserID(mi model.InternalID) *SentinelInfoCreate { + sic.mutation.SetUserID(mi) + return sic +} + +// 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 +} + +// 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.UserID(); !ok { + return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "SentinelInfo.user_id"`)} + } + 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"`)} + } + 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 + } + id := _spec.ID.Value.(int64) + _node.ID = int(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.TypeInt)) + ) + _spec.OnConflict = sic.conflict + if value, ok := sic.mutation.UserID(); ok { + _spec.SetField(sentinelinfo.FieldUserID, field.TypeInt64, value) + _node.UserID = value + } + 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 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(). +// SetUserID(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) { +// SetUserID(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 + } +) + +// SetUserID sets the "user_id" field. +func (u *SentinelInfoUpsert) SetUserID(v model.InternalID) *SentinelInfoUpsert { + u.Set(sentinelinfo.FieldUserID, v) + return u +} + +// UpdateUserID sets the "user_id" field to the value that was provided on create. +func (u *SentinelInfoUpsert) UpdateUserID() *SentinelInfoUpsert { + u.SetExcluded(sentinelinfo.FieldUserID) + return u +} + +// AddUserID adds v to the "user_id" field. +func (u *SentinelInfoUpsert) AddUserID(v model.InternalID) *SentinelInfoUpsert { + u.Add(sentinelinfo.FieldUserID, v) + return u +} + +// 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 +} + +// 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(), +// ). +// Exec(ctx) +func (u *SentinelInfoUpsertOne) UpdateNewValues() *SentinelInfoUpsertOne { + 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.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 +} + +// SetUserID sets the "user_id" field. +func (u *SentinelInfoUpsertOne) SetUserID(v model.InternalID) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetUserID(v) + }) +} + +// AddUserID adds v to the "user_id" field. +func (u *SentinelInfoUpsertOne) AddUserID(v model.InternalID) *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.AddUserID(v) + }) +} + +// UpdateUserID sets the "user_id" field to the value that was provided on create. +func (u *SentinelInfoUpsertOne) UpdateUserID() *SentinelInfoUpsertOne { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateUserID() + }) +} + +// 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() + }) +} + +// 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 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 *SentinelInfoUpsertOne) IDX(ctx context.Context) int { + 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 { + 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, 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) { +// SetUserID(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(), +// ). +// Exec(ctx) +func (u *SentinelInfoUpsertBulk) UpdateNewValues() *SentinelInfoUpsertBulk { + 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.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 +} + +// SetUserID sets the "user_id" field. +func (u *SentinelInfoUpsertBulk) SetUserID(v model.InternalID) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.SetUserID(v) + }) +} + +// AddUserID adds v to the "user_id" field. +func (u *SentinelInfoUpsertBulk) AddUserID(v model.InternalID) *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.AddUserID(v) + }) +} + +// UpdateUserID sets the "user_id" field to the value that was provided on create. +func (u *SentinelInfoUpsertBulk) UpdateUserID() *SentinelInfoUpsertBulk { + return u.Update(func(s *SentinelInfoUpsert) { + s.UpdateUserID() + }) +} + +// 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() + }) +} + +// 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..bfbe275e --- /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.TypeInt)) + 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..106a8bee --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo_query.go @@ -0,0 +1,608 @@ +// 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" +) + +// 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 int, err error) { + var ids []int + 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) int { + 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 int, err error) { + var ids []int + 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) int { + 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 []int, 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) []int { + 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 { +// UserID model.InternalID `json:"user_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.SentinelInfo.Query(). +// GroupBy(sentinelinfo.FieldUserID). +// 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 { +// UserID model.InternalID `json:"user_id,omitempty"` +// } +// +// client.SentinelInfo.Query(). +// Select(sentinelinfo.FieldUserID). +// 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[int]*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.TypeInt)) + _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..735aca98 --- /dev/null +++ b/internal/data/internal/ent/sentinelinfo_update.go @@ -0,0 +1,643 @@ +// 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" + "github.com/tuihub/librarian/internal/model" +) + +// 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 +} + +// SetUserID sets the "user_id" field. +func (siu *SentinelInfoUpdate) SetUserID(mi model.InternalID) *SentinelInfoUpdate { + siu.mutation.ResetUserID() + siu.mutation.SetUserID(mi) + return siu +} + +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (siu *SentinelInfoUpdate) SetNillableUserID(mi *model.InternalID) *SentinelInfoUpdate { + if mi != nil { + siu.SetUserID(*mi) + } + return siu +} + +// AddUserID adds mi to the "user_id" field. +func (siu *SentinelInfoUpdate) AddUserID(mi model.InternalID) *SentinelInfoUpdate { + siu.mutation.AddUserID(mi) + 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 +} + +// 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.TypeInt)) + 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.UserID(); ok { + _spec.SetField(sentinelinfo.FieldUserID, field.TypeInt64, value) + } + if value, ok := siu.mutation.AddedUserID(); ok { + _spec.AddField(sentinelinfo.FieldUserID, field.TypeInt64, value) + } + 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 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 +} + +// SetUserID sets the "user_id" field. +func (siuo *SentinelInfoUpdateOne) SetUserID(mi model.InternalID) *SentinelInfoUpdateOne { + siuo.mutation.ResetUserID() + siuo.mutation.SetUserID(mi) + return siuo +} + +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (siuo *SentinelInfoUpdateOne) SetNillableUserID(mi *model.InternalID) *SentinelInfoUpdateOne { + if mi != nil { + siuo.SetUserID(*mi) + } + return siuo +} + +// AddUserID adds mi to the "user_id" field. +func (siuo *SentinelInfoUpdateOne) AddUserID(mi model.InternalID) *SentinelInfoUpdateOne { + siuo.mutation.AddUserID(mi) + return siuo +} + +// 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 +} + +// 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.TypeInt)) + 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.UserID(); ok { + _spec.SetField(sentinelinfo.FieldUserID, field.TypeInt64, value) + } + if value, ok := siuo.mutation.AddedUserID(); ok { + _spec.AddField(sentinelinfo.FieldUserID, field.TypeInt64, value) + } + 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 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..585b327d --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary.go @@ -0,0 +1,195 @@ +// 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" +) + +// 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 int `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"` + // 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"` + // SentinelAppBinary holds the value of the sentinel_app_binary edge. + SentinelAppBinary []*SentinelAppBinary `json:"sentinel_app_binary,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [2]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"} +} + +// SentinelAppBinaryOrErr returns the SentinelAppBinary value or an error if the edge +// was not loaded in eager-loading. +func (e SentinelLibraryEdges) SentinelAppBinaryOrErr() ([]*SentinelAppBinary, error) { + if e.loadedTypes[1] { + return e.SentinelAppBinary, nil + } + return nil, &NotLoadedError{edge: "sentinel_app_binary"} +} + +// 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: + 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 = int(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 + } + 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) +} + +// QuerySentinelAppBinary queries the "sentinel_app_binary" edge of the SentinelLibrary entity. +func (sl *SentinelLibrary) QuerySentinelAppBinary() *SentinelAppBinaryQuery { + return NewSentinelLibraryClient(sl.config).QuerySentinelAppBinary(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.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..40f3b69d --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary/sentinellibrary.go @@ -0,0 +1,144 @@ +// 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" + // EdgeSentinelInfo holds the string denoting the sentinel_info edge name in mutations. + EdgeSentinelInfo = "sentinel_info" + // EdgeSentinelAppBinary holds the string denoting the sentinel_app_binary edge name in mutations. + EdgeSentinelAppBinary = "sentinel_app_binary" + // 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" + // SentinelAppBinaryTable is the table that holds the sentinel_app_binary relation/edge. + SentinelAppBinaryTable = "sentinel_app_binaries" + // SentinelAppBinaryInverseTable is the table name for the SentinelAppBinary entity. + // It exists in this package in order to avoid circular dependency with the "sentinelappbinary" package. + SentinelAppBinaryInverseTable = "sentinel_app_binaries" + // SentinelAppBinaryColumn is the table column denoting the sentinel_app_binary relation/edge. + SentinelAppBinaryColumn = "sentinel_library_id" +) + +// Columns holds all SQL columns for sentinellibrary fields. +var Columns = []string{ + FieldID, + FieldSentinelInfoID, + FieldReportedID, + FieldDownloadBasePath, + FieldUpdatedAt, + FieldCreatedAt, +} + +// 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() +} + +// 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...)) + } +} + +// BySentinelAppBinaryCount orders the results by sentinel_app_binary count. +func BySentinelAppBinaryCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newSentinelAppBinaryStep(), opts...) + } +} + +// BySentinelAppBinary orders the results by sentinel_app_binary terms. +func BySentinelAppBinary(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newSentinelAppBinaryStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newSentinelInfoStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SentinelInfoInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, SentinelInfoTable, SentinelInfoColumn), + ) +} +func newSentinelAppBinaryStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(SentinelAppBinaryInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, SentinelAppBinaryTable, SentinelAppBinaryColumn), + ) +} diff --git a/internal/data/internal/ent/sentinellibrary/where.go b/internal/data/internal/ent/sentinellibrary/where.go new file mode 100644 index 00000000..8c5323b0 --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary/where.go @@ -0,0 +1,347 @@ +// 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" +) + +// 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 int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldSentinelInfoID, v)) +} + +// 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)) +} + +// SentinelInfoIDEQ applies the EQ predicate on the "sentinel_info_id" field. +func SentinelInfoIDEQ(v int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldSentinelInfoID, v)) +} + +// SentinelInfoIDNEQ applies the NEQ predicate on the "sentinel_info_id" field. +func SentinelInfoIDNEQ(v int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNEQ(FieldSentinelInfoID, v)) +} + +// SentinelInfoIDIn applies the In predicate on the "sentinel_info_id" field. +func SentinelInfoIDIn(vs ...int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldIn(FieldSentinelInfoID, vs...)) +} + +// SentinelInfoIDNotIn applies the NotIn predicate on the "sentinel_info_id" field. +func SentinelInfoIDNotIn(vs ...int) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNotIn(FieldSentinelInfoID, vs...)) +} + +// 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)) +} + +// 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) + } + }) + }) +} + +// HasSentinelAppBinary applies the HasEdge predicate on the "sentinel_app_binary" edge. +func HasSentinelAppBinary() predicate.SentinelLibrary { + return predicate.SentinelLibrary(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, SentinelAppBinaryTable, SentinelAppBinaryColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasSentinelAppBinaryWith applies the HasEdge predicate on the "sentinel_app_binary" edge with a given conditions (other predicates). +func HasSentinelAppBinaryWith(preds ...predicate.SentinelAppBinary) predicate.SentinelLibrary { + return predicate.SentinelLibrary(func(s *sql.Selector) { + step := newSentinelAppBinaryStep() + 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..048efe6c --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary_create.go @@ -0,0 +1,771 @@ +// 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/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" +) + +// 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(i int) *SentinelLibraryCreate { + slc.mutation.SetSentinelInfoID(i) + 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 +} + +// SetSentinelInfo sets the "sentinel_info" edge to the SentinelInfo entity. +func (slc *SentinelLibraryCreate) SetSentinelInfo(s *SentinelInfo) *SentinelLibraryCreate { + return slc.SetSentinelInfoID(s.ID) +} + +// AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. +func (slc *SentinelLibraryCreate) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryCreate { + slc.mutation.AddSentinelAppBinaryIDs(ids...) + return slc +} + +// AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. +func (slc *SentinelLibraryCreate) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryCreate { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return slc.AddSentinelAppBinaryIDs(ids...) +} + +// 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 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 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.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.SentinelInfoID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := slc.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinellibrary.SentinelAppBinaryTable, + Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.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.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 int) *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 +} + +// 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 int) *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() + }) +} + +// 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 int) *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() + }) +} + +// 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..fc81eb1b --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary_query.go @@ -0,0 +1,683 @@ +// 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/sentinelappbinary" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" +) + +// SentinelLibraryQuery is the builder for querying SentinelLibrary entities. +type SentinelLibraryQuery struct { + config + ctx *QueryContext + order []sentinellibrary.OrderOption + inters []Interceptor + predicates []predicate.SentinelLibrary + withSentinelInfo *SentinelInfoQuery + withSentinelAppBinary *SentinelAppBinaryQuery + // 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 +} + +// QuerySentinelAppBinary chains the current query on the "sentinel_app_binary" edge. +func (slq *SentinelLibraryQuery) QuerySentinelAppBinary() *SentinelAppBinaryQuery { + query := (&SentinelAppBinaryClient{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(sentinelappbinary.Table, sentinelappbinary.FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, sentinellibrary.SentinelAppBinaryTable, sentinellibrary.SentinelAppBinaryColumn), + ) + 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(), + withSentinelAppBinary: slq.withSentinelAppBinary.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 +} + +// WithSentinelAppBinary tells the query-builder to eager-load the nodes that are connected to +// the "sentinel_app_binary" edge. The optional arguments are used to configure the query builder of the edge. +func (slq *SentinelLibraryQuery) WithSentinelAppBinary(opts ...func(*SentinelAppBinaryQuery)) *SentinelLibraryQuery { + query := (&SentinelAppBinaryClient{config: slq.config}).Query() + for _, opt := range opts { + opt(query) + } + slq.withSentinelAppBinary = 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 int `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 int `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 = [2]bool{ + slq.withSentinelInfo != nil, + slq.withSentinelAppBinary != 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 + } + } + if query := slq.withSentinelAppBinary; query != nil { + if err := slq.loadSentinelAppBinary(ctx, query, nodes, + func(n *SentinelLibrary) { n.Edges.SentinelAppBinary = []*SentinelAppBinary{} }, + func(n *SentinelLibrary, e *SentinelAppBinary) { + n.Edges.SentinelAppBinary = append(n.Edges.SentinelAppBinary, 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([]int, 0, len(nodes)) + nodeids := make(map[int][]*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) loadSentinelAppBinary(ctx context.Context, query *SentinelAppBinaryQuery, nodes []*SentinelLibrary, init func(*SentinelLibrary), assign func(*SentinelLibrary, *SentinelAppBinary)) error { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int]*SentinelLibrary) + 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(sentinelappbinary.FieldSentinelLibraryID) + } + query.Where(predicate.SentinelAppBinary(func(s *sql.Selector) { + s.Where(sql.InValues(s.C(sentinellibrary.SentinelAppBinaryColumn), fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return err + } + for _, n := range neighbors { + fk := n.SentinelLibraryID + node, ok := nodeids[fk] + if !ok { + return fmt.Errorf(`unexpected referenced foreign-key "sentinel_library_id" returned %v for node %v`, fk, n.ID) + } + assign(node, 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..b4f49d65 --- /dev/null +++ b/internal/data/internal/ent/sentinellibrary_update.go @@ -0,0 +1,628 @@ +// 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/data/internal/ent/sentinelinfo" + "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" +) + +// 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(i int) *SentinelLibraryUpdate { + slu.mutation.SetSentinelInfoID(i) + return slu +} + +// SetNillableSentinelInfoID sets the "sentinel_info_id" field if the given value is not nil. +func (slu *SentinelLibraryUpdate) SetNillableSentinelInfoID(i *int) *SentinelLibraryUpdate { + if i != nil { + slu.SetSentinelInfoID(*i) + } + 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 +} + +// SetSentinelInfo sets the "sentinel_info" edge to the SentinelInfo entity. +func (slu *SentinelLibraryUpdate) SetSentinelInfo(s *SentinelInfo) *SentinelLibraryUpdate { + return slu.SetSentinelInfoID(s.ID) +} + +// AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. +func (slu *SentinelLibraryUpdate) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdate { + slu.mutation.AddSentinelAppBinaryIDs(ids...) + return slu +} + +// AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. +func (slu *SentinelLibraryUpdate) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdate { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return slu.AddSentinelAppBinaryIDs(ids...) +} + +// 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 +} + +// ClearSentinelAppBinary clears all "sentinel_app_binary" edges to the SentinelAppBinary entity. +func (slu *SentinelLibraryUpdate) ClearSentinelAppBinary() *SentinelLibraryUpdate { + slu.mutation.ClearSentinelAppBinary() + return slu +} + +// RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to SentinelAppBinary entities by IDs. +func (slu *SentinelLibraryUpdate) RemoveSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdate { + slu.mutation.RemoveSentinelAppBinaryIDs(ids...) + return slu +} + +// RemoveSentinelAppBinary removes "sentinel_app_binary" edges to SentinelAppBinary entities. +func (slu *SentinelLibraryUpdate) RemoveSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdate { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return slu.RemoveSentinelAppBinaryIDs(ids...) +} + +// 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 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.TypeInt), + }, + } + _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.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if slu.mutation.SentinelAppBinaryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinellibrary.SentinelAppBinaryTable, + Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := slu.mutation.RemovedSentinelAppBinaryIDs(); len(nodes) > 0 && !slu.mutation.SentinelAppBinaryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinellibrary.SentinelAppBinaryTable, + Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.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 := slu.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinellibrary.SentinelAppBinaryTable, + Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.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, 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(i int) *SentinelLibraryUpdateOne { + sluo.mutation.SetSentinelInfoID(i) + return sluo +} + +// SetNillableSentinelInfoID sets the "sentinel_info_id" field if the given value is not nil. +func (sluo *SentinelLibraryUpdateOne) SetNillableSentinelInfoID(i *int) *SentinelLibraryUpdateOne { + if i != nil { + sluo.SetSentinelInfoID(*i) + } + 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 +} + +// SetSentinelInfo sets the "sentinel_info" edge to the SentinelInfo entity. +func (sluo *SentinelLibraryUpdateOne) SetSentinelInfo(s *SentinelInfo) *SentinelLibraryUpdateOne { + return sluo.SetSentinelInfoID(s.ID) +} + +// AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. +func (sluo *SentinelLibraryUpdateOne) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdateOne { + sluo.mutation.AddSentinelAppBinaryIDs(ids...) + return sluo +} + +// AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. +func (sluo *SentinelLibraryUpdateOne) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdateOne { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return sluo.AddSentinelAppBinaryIDs(ids...) +} + +// 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 +} + +// ClearSentinelAppBinary clears all "sentinel_app_binary" edges to the SentinelAppBinary entity. +func (sluo *SentinelLibraryUpdateOne) ClearSentinelAppBinary() *SentinelLibraryUpdateOne { + sluo.mutation.ClearSentinelAppBinary() + return sluo +} + +// RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to SentinelAppBinary entities by IDs. +func (sluo *SentinelLibraryUpdateOne) RemoveSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdateOne { + sluo.mutation.RemoveSentinelAppBinaryIDs(ids...) + return sluo +} + +// RemoveSentinelAppBinary removes "sentinel_app_binary" edges to SentinelAppBinary entities. +func (sluo *SentinelLibraryUpdateOne) RemoveSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdateOne { + ids := make([]int, len(s)) + for i := range s { + ids[i] = s[i].ID + } + return sluo.RemoveSentinelAppBinaryIDs(ids...) +} + +// 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 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.TypeInt), + }, + } + _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.TypeInt), + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if sluo.mutation.SentinelAppBinaryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinellibrary.SentinelAppBinaryTable, + Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := sluo.mutation.RemovedSentinelAppBinaryIDs(); len(nodes) > 0 && !sluo.mutation.SentinelAppBinaryCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinellibrary.SentinelAppBinaryTable, + Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.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 := sluo.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: true, + Table: sentinellibrary.SentinelAppBinaryTable, + Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + }, + } + 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/model/modelgebura/modelgebura.go b/internal/model/modelgebura/modelgebura.go index d65b866f..bc14da83 100644 --- a/internal/model/modelgebura/modelgebura.go +++ b/internal/model/modelgebura/modelgebura.go @@ -107,3 +107,38 @@ type AppCategory struct { Name string AppIDs []model.InternalID } + +//nolint:stylecheck // no check for Url +type SentinelInfo struct { + UserID model.InternalID + Url string + AlternativeUrls []string + GetTokenPath string + DownloadFileBasePath string + Libraries []*SentinelLibrary +} + +type SentinelLibrary struct { + ReportedID int64 + DownloadBasePath string + AppBinaries []*SentinelAppBinary +} + +type SentinelAppBinary struct { + 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/service/sentinel/tiphereth.go b/internal/service/sentinel/tiphereth.go index 9ca860bd..e1c0a24e 100644 --- a/internal/service/sentinel/tiphereth.go +++ b/internal/service/sentinel/tiphereth.go @@ -2,6 +2,7 @@ package sentinel import ( "context" + "github.com/tuihub/librarian/internal/lib/logger" pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1/sentinel" ) From e3a8f73cb107bdf9c10d9c7a591c53a1b48bff0a Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Wed, 9 Apr 2025 00:08:40 +0800 Subject: [PATCH 05/16] feat(sentinel): add sentinel refresh token --- internal/server/token_matcher.go | 1 + 1 file changed, 1 insertion(+) 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, } } From cd190df61b4039f49ac129bb5e3511f5c603aae1 Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Wed, 9 Apr 2025 11:12:52 +0800 Subject: [PATCH 06/16] feat(sentinel): update model, impl ReportSentinelInformation --- go.mod | 4 +- go.sum | 8 +- internal/biz/bizgebura/sentinel.go | 33 ++ internal/data/gebura.go | 69 +++ internal/data/internal/ent/client.go | 32 +- internal/data/internal/ent/migrate/schema.go | 39 +- internal/data/internal/ent/mutation.go | 426 +++++++++++------- internal/data/internal/ent/runtime.go | 12 +- .../ent/schema/sentinel_app_binary.go | 10 +- .../ent/schema/sentinel_app_binary_file.go | 5 +- .../data/internal/ent/schema/sentinel_info.go | 9 +- .../internal/ent/schema/sentinel_library.go | 10 +- .../data/internal/ent/sentinelappbinary.go | 28 +- .../sentinelappbinary/sentinelappbinary.go | 8 + .../internal/ent/sentinelappbinary/where.go | 95 +++- .../internal/ent/sentinelappbinary_create.go | 138 +++++- .../internal/ent/sentinelappbinary_delete.go | 2 +- .../internal/ent/sentinelappbinary_query.go | 29 +- .../internal/ent/sentinelappbinary_update.go | 115 +++-- .../internal/ent/sentinelappbinaryfile.go | 15 +- .../ent/sentinelappbinaryfile/where.go | 50 +- .../ent/sentinelappbinaryfile_create.go | 59 ++- .../ent/sentinelappbinaryfile_delete.go | 2 +- .../ent/sentinelappbinaryfile_query.go | 27 +- .../ent/sentinelappbinaryfile_update.go | 33 +- internal/data/internal/ent/sentinelinfo.go | 19 +- .../internal/ent/sentinelinfo/sentinelinfo.go | 8 - .../data/internal/ent/sentinelinfo/where.go | 78 +--- .../data/internal/ent/sentinelinfo_create.go | 129 ++---- .../data/internal/ent/sentinelinfo_delete.go | 2 +- .../data/internal/ent/sentinelinfo_query.go | 29 +- .../data/internal/ent/sentinelinfo_update.go | 86 +--- internal/data/internal/ent/sentinellibrary.go | 28 +- .../ent/sentinellibrary/sentinellibrary.go | 8 + .../internal/ent/sentinellibrary/where.go | 95 +++- .../internal/ent/sentinellibrary_create.go | 138 +++++- .../internal/ent/sentinellibrary_delete.go | 2 +- .../internal/ent/sentinellibrary_query.go | 29 +- .../internal/ent/sentinellibrary_update.go | 115 +++-- internal/model/modelgebura/modelgebura.go | 23 +- .../service/sentinel/converter/converter.go | 5 + .../service/sentinel/converter/generated.go | 82 ++++ .../service/sentinel/converter/pb_to_biz.go | 37 ++ internal/service/sentinel/gebura.go | 27 ++ .../service/sephirah/converter/biz_to_pb.go | 4 +- .../service/sephirah/converter/generated.go | 24 +- .../service/sephirah/converter/pb_to_biz.go | 4 +- 47 files changed, 1475 insertions(+), 755 deletions(-) create mode 100644 internal/biz/bizgebura/sentinel.go create mode 100644 internal/service/sentinel/converter/converter.go create mode 100644 internal/service/sentinel/converter/generated.go create mode 100644 internal/service/sentinel/converter/pb_to_biz.go create mode 100644 internal/service/sentinel/gebura.go 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..85927553 --- /dev/null +++ b/internal/biz/bizgebura/sentinel.go @@ -0,0 +1,33 @@ +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) UpdateSentinelInfo( + ctx context.Context, info *modelgebura.SentinelInfo, +) error { + claims := libauth.FromContextAssertUserType(ctx, model.UserTypeSentinel) + if claims == nil { + return bizutils.NoPermissionError() + } + info.ID = claims.UserID + var err error + for _, lib := range info.Libraries { + lib.ID, err = g.id.New() + if err != nil { + return pb.ErrorErrorReasonUnspecified("%s", err.Error()) + } + } + err = g.repo.UpsertSentinelInfo(ctx, info) + if err != nil { + return pb.ErrorErrorReasonUnspecified("%s", err.Error()) + } + return nil +} diff --git a/internal/data/gebura.go b/internal/data/gebura.go index 2ee20ea9..52f28034 100644 --- a/internal/data/gebura.go +++ b/internal/data/gebura.go @@ -11,9 +11,13 @@ 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/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" ) type GeburaRepo struct { @@ -610,3 +614,68 @@ func (g *GeburaRepo) DeleteAppCategory( return err }) } + +func (g *GeburaRepo) UpsertSentinelInfo( + ctx context.Context, + info *modelgebura.SentinelInfo, +) error { + return g.data.WithTx(ctx, func(tx *ent.Tx) error { + // upsert sentinel info + q := tx.SentinelInfo.Create(). + SetID(info.ID). + SetURL(info.Url). + SetAlternativeUrls(info.AlternativeUrls). + SetGetTokenPath(info.GetTokenPath). + SetDownloadFileBasePath(info.DownloadFileBasePath) + err := q.OnConflict(sql.ConflictColumns(sentinelinfo.FieldID)). + UpdateNewValues(). + 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 + } + oldLibs, err := tx.SentinelLibrary.Query(). + Where(sentinellibrary.SentinelInfoIDEQ(sInfo.ID)). + All(ctx) + if err != nil { + return err + } + oldLibsMap := make(map[int64]*ent.SentinelLibrary, len(oldLibs)) + for _, lib := range oldLibs { + oldLibsMap[lib.ReportedID] = lib + } + newLibs := make([]*ent.SentinelLibraryCreate, 0, len(info.Libraries)) + for _, lib := range info.Libraries { + var reportSeq int64 + if oldLib, exists := oldLibsMap[lib.ReportedID]; exists { + reportSeq = oldLib.ReportSequence + 1 + } else { + reportSeq = 0 + } + newLibs = append(newLibs, tx.SentinelLibrary.Create(). + SetID(lib.ID). + SetSentinelInfoID(sInfo.ID). + SetReportedID(lib.ReportedID). + SetDownloadBasePath(lib.DownloadBasePath). + SetReportSequence(reportSeq)) + } + return tx.SentinelLibrary.CreateBulk(newLibs...). + OnConflict( + sql.ConflictColumns( + sentinellibrary.FieldSentinelInfoID, + sentinellibrary.FieldReportedID, + ), + resolveWithIgnores([]string{ + sentinellibrary.FieldID, + }), + ). + UpdateNewValues(). + Exec(ctx) + }) +} diff --git a/internal/data/internal/ent/client.go b/internal/data/internal/ent/client.go index dfce893e..a1c2bc26 100644 --- a/internal/data/internal/ent/client.go +++ b/internal/data/internal/ent/client.go @@ -4269,7 +4269,7 @@ func (c *SentinelAppBinaryClient) UpdateOne(sab *SentinelAppBinary) *SentinelApp } // UpdateOneID returns an update builder for the given id. -func (c *SentinelAppBinaryClient) UpdateOneID(id int) *SentinelAppBinaryUpdateOne { +func (c *SentinelAppBinaryClient) UpdateOneID(id model.InternalID) *SentinelAppBinaryUpdateOne { mutation := newSentinelAppBinaryMutation(c.config, OpUpdateOne, withSentinelAppBinaryID(id)) return &SentinelAppBinaryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } @@ -4286,7 +4286,7 @@ func (c *SentinelAppBinaryClient) DeleteOne(sab *SentinelAppBinary) *SentinelApp } // DeleteOneID returns a builder for deleting the given entity by its id. -func (c *SentinelAppBinaryClient) DeleteOneID(id int) *SentinelAppBinaryDeleteOne { +func (c *SentinelAppBinaryClient) DeleteOneID(id model.InternalID) *SentinelAppBinaryDeleteOne { builder := c.Delete().Where(sentinelappbinary.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne @@ -4303,12 +4303,12 @@ func (c *SentinelAppBinaryClient) Query() *SentinelAppBinaryQuery { } // Get returns a SentinelAppBinary entity by its id. -func (c *SentinelAppBinaryClient) Get(ctx context.Context, id int) (*SentinelAppBinary, error) { +func (c *SentinelAppBinaryClient) Get(ctx context.Context, id model.InternalID) (*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 { +func (c *SentinelAppBinaryClient) GetX(ctx context.Context, id model.InternalID) *SentinelAppBinary { obj, err := c.Get(ctx, id) if err != nil { panic(err) @@ -4434,7 +4434,7 @@ func (c *SentinelAppBinaryFileClient) UpdateOne(sabf *SentinelAppBinaryFile) *Se } // UpdateOneID returns an update builder for the given id. -func (c *SentinelAppBinaryFileClient) UpdateOneID(id int) *SentinelAppBinaryFileUpdateOne { +func (c *SentinelAppBinaryFileClient) UpdateOneID(id model.InternalID) *SentinelAppBinaryFileUpdateOne { mutation := newSentinelAppBinaryFileMutation(c.config, OpUpdateOne, withSentinelAppBinaryFileID(id)) return &SentinelAppBinaryFileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } @@ -4451,7 +4451,7 @@ func (c *SentinelAppBinaryFileClient) DeleteOne(sabf *SentinelAppBinaryFile) *Se } // DeleteOneID returns a builder for deleting the given entity by its id. -func (c *SentinelAppBinaryFileClient) DeleteOneID(id int) *SentinelAppBinaryFileDeleteOne { +func (c *SentinelAppBinaryFileClient) DeleteOneID(id model.InternalID) *SentinelAppBinaryFileDeleteOne { builder := c.Delete().Where(sentinelappbinaryfile.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne @@ -4468,12 +4468,12 @@ func (c *SentinelAppBinaryFileClient) Query() *SentinelAppBinaryFileQuery { } // Get returns a SentinelAppBinaryFile entity by its id. -func (c *SentinelAppBinaryFileClient) Get(ctx context.Context, id int) (*SentinelAppBinaryFile, error) { +func (c *SentinelAppBinaryFileClient) Get(ctx context.Context, id model.InternalID) (*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 { +func (c *SentinelAppBinaryFileClient) GetX(ctx context.Context, id model.InternalID) *SentinelAppBinaryFile { obj, err := c.Get(ctx, id) if err != nil { panic(err) @@ -4583,7 +4583,7 @@ func (c *SentinelInfoClient) UpdateOne(si *SentinelInfo) *SentinelInfoUpdateOne } // UpdateOneID returns an update builder for the given id. -func (c *SentinelInfoClient) UpdateOneID(id int) *SentinelInfoUpdateOne { +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} } @@ -4600,7 +4600,7 @@ func (c *SentinelInfoClient) DeleteOne(si *SentinelInfo) *SentinelInfoDeleteOne } // DeleteOneID returns a builder for deleting the given entity by its id. -func (c *SentinelInfoClient) DeleteOneID(id int) *SentinelInfoDeleteOne { +func (c *SentinelInfoClient) DeleteOneID(id model.InternalID) *SentinelInfoDeleteOne { builder := c.Delete().Where(sentinelinfo.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne @@ -4617,12 +4617,12 @@ func (c *SentinelInfoClient) Query() *SentinelInfoQuery { } // Get returns a SentinelInfo entity by its id. -func (c *SentinelInfoClient) Get(ctx context.Context, id int) (*SentinelInfo, error) { +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 int) *SentinelInfo { +func (c *SentinelInfoClient) GetX(ctx context.Context, id model.InternalID) *SentinelInfo { obj, err := c.Get(ctx, id) if err != nil { panic(err) @@ -4732,7 +4732,7 @@ func (c *SentinelLibraryClient) UpdateOne(sl *SentinelLibrary) *SentinelLibraryU } // UpdateOneID returns an update builder for the given id. -func (c *SentinelLibraryClient) UpdateOneID(id int) *SentinelLibraryUpdateOne { +func (c *SentinelLibraryClient) UpdateOneID(id model.InternalID) *SentinelLibraryUpdateOne { mutation := newSentinelLibraryMutation(c.config, OpUpdateOne, withSentinelLibraryID(id)) return &SentinelLibraryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } @@ -4749,7 +4749,7 @@ func (c *SentinelLibraryClient) DeleteOne(sl *SentinelLibrary) *SentinelLibraryD } // DeleteOneID returns a builder for deleting the given entity by its id. -func (c *SentinelLibraryClient) DeleteOneID(id int) *SentinelLibraryDeleteOne { +func (c *SentinelLibraryClient) DeleteOneID(id model.InternalID) *SentinelLibraryDeleteOne { builder := c.Delete().Where(sentinellibrary.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne @@ -4766,12 +4766,12 @@ func (c *SentinelLibraryClient) Query() *SentinelLibraryQuery { } // Get returns a SentinelLibrary entity by its id. -func (c *SentinelLibraryClient) Get(ctx context.Context, id int) (*SentinelLibrary, error) { +func (c *SentinelLibraryClient) Get(ctx context.Context, id model.InternalID) (*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 { +func (c *SentinelLibraryClient) GetX(ctx context.Context, id model.InternalID) *SentinelLibrary { obj, err := c.Get(ctx, id) if err != nil { panic(err) diff --git a/internal/data/internal/ent/migrate/schema.go b/internal/data/internal/ent/migrate/schema.go index 1c1faa32..868d5b09 100644 --- a/internal/data/internal/ent/migrate/schema.go +++ b/internal/data/internal/ent/migrate/schema.go @@ -739,7 +739,7 @@ var ( } // SentinelAppBinariesColumns holds the columns for the "sentinel_app_binaries" table. SentinelAppBinariesColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "id", Type: field.TypeInt64}, {Name: "generated_id", Type: field.TypeString}, {Name: "size_bytes", Type: field.TypeInt64}, {Name: "need_token", Type: field.TypeBool}, @@ -749,7 +749,8 @@ var ( {Name: "publisher", Type: field.TypeString, Nullable: true}, {Name: "updated_at", Type: field.TypeTime}, {Name: "created_at", Type: field.TypeTime}, - {Name: "sentinel_library_id", Type: field.TypeInt}, + {Name: "report_sequence", Type: field.TypeInt64}, + {Name: "sentinel_library_id", Type: field.TypeInt64}, } // SentinelAppBinariesTable holds the schema information for the "sentinel_app_binaries" table. SentinelAppBinariesTable = &schema.Table{ @@ -759,7 +760,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "sentinel_app_binaries_sentinel_libraries_sentinel_library", - Columns: []*schema.Column{SentinelAppBinariesColumns[10]}, + Columns: []*schema.Column{SentinelAppBinariesColumns[11]}, RefColumns: []*schema.Column{SentinelLibrariesColumns[0]}, OnDelete: schema.NoAction, }, @@ -767,14 +768,19 @@ var ( Indexes: []*schema.Index{ { Name: "sentinelappbinary_sentinel_library_id_generated_id", + Unique: true, + Columns: []*schema.Column{SentinelAppBinariesColumns[11], SentinelAppBinariesColumns[1]}, + }, + { + Name: "sentinelappbinary_generated_id", Unique: false, - Columns: []*schema.Column{SentinelAppBinariesColumns[10], SentinelAppBinariesColumns[1]}, + Columns: []*schema.Column{SentinelAppBinariesColumns[1]}, }, }, } // SentinelAppBinaryFilesColumns holds the columns for the "sentinel_app_binary_files" table. SentinelAppBinaryFilesColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "id", Type: field.TypeInt64}, {Name: "name", Type: field.TypeString}, {Name: "size_bytes", Type: field.TypeInt64}, {Name: "sha256", Type: field.TypeBytes}, @@ -782,7 +788,7 @@ var ( {Name: "chunks_info", Type: field.TypeString, Nullable: true}, {Name: "updated_at", Type: field.TypeTime}, {Name: "created_at", Type: field.TypeTime}, - {Name: "sentinel_app_binary_id", Type: field.TypeInt}, + {Name: "sentinel_app_binary_id", Type: field.TypeInt64}, } // SentinelAppBinaryFilesTable holds the schema information for the "sentinel_app_binary_files" table. SentinelAppBinaryFilesTable = &schema.Table{ @@ -807,8 +813,7 @@ var ( } // SentinelInfosColumns holds the columns for the "sentinel_infos" table. SentinelInfosColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "user_id", Type: field.TypeInt64}, + {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}, @@ -821,22 +826,16 @@ var ( Name: "sentinel_infos", Columns: SentinelInfosColumns, PrimaryKey: []*schema.Column{SentinelInfosColumns[0]}, - Indexes: []*schema.Index{ - { - Name: "sentinelinfo_user_id", - Unique: false, - Columns: []*schema.Column{SentinelInfosColumns[1]}, - }, - }, } // SentinelLibrariesColumns holds the columns for the "sentinel_libraries" table. SentinelLibrariesColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "id", Type: field.TypeInt64}, {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: "sentinel_info_id", Type: field.TypeInt}, + {Name: "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{ @@ -846,7 +845,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "sentinel_libraries_sentinel_infos_sentinel_info", - Columns: []*schema.Column{SentinelLibrariesColumns[5]}, + Columns: []*schema.Column{SentinelLibrariesColumns[6]}, RefColumns: []*schema.Column{SentinelInfosColumns[0]}, OnDelete: schema.NoAction, }, @@ -854,8 +853,8 @@ var ( Indexes: []*schema.Index{ { Name: "sentinellibrary_sentinel_info_id_reported_id", - Unique: false, - Columns: []*schema.Column{SentinelLibrariesColumns[5], SentinelLibrariesColumns[1]}, + Unique: true, + Columns: []*schema.Column{SentinelLibrariesColumns[6], SentinelLibrariesColumns[1]}, }, }, } diff --git a/internal/data/internal/ent/mutation.go b/internal/data/internal/ent/mutation.go index 55425e6d..9d7cc046 100644 --- a/internal/data/internal/ent/mutation.go +++ b/internal/data/internal/ent/mutation.go @@ -21858,7 +21858,7 @@ type SentinelAppBinaryMutation struct { config op Op typ string - id *int + id *model.InternalID generated_id *string size_bytes *int64 addsize_bytes *int64 @@ -21869,11 +21869,13 @@ type SentinelAppBinaryMutation struct { publisher *string updated_at *time.Time created_at *time.Time + report_sequence *int64 + addreport_sequence *int64 clearedFields map[string]struct{} - sentinel_library *int + sentinel_library *model.InternalID clearedsentinel_library bool - sentinel_app_binary_file map[int]struct{} - removedsentinel_app_binary_file map[int]struct{} + sentinel_app_binary_file map[model.InternalID]struct{} + removedsentinel_app_binary_file map[model.InternalID]struct{} clearedsentinel_app_binary_file bool done bool oldValue func(context.Context) (*SentinelAppBinary, error) @@ -21900,7 +21902,7 @@ func newSentinelAppBinaryMutation(c config, op Op, opts ...sentinelappbinaryOpti } // withSentinelAppBinaryID sets the ID field of the mutation. -func withSentinelAppBinaryID(id int) sentinelappbinaryOption { +func withSentinelAppBinaryID(id model.InternalID) sentinelappbinaryOption { return func(m *SentinelAppBinaryMutation) { var ( err error @@ -21950,9 +21952,15 @@ func (m SentinelAppBinaryMutation) Tx() (*Tx, error) { return tx, nil } +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of SentinelAppBinary entities. +func (m *SentinelAppBinaryMutation) 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 *SentinelAppBinaryMutation) ID() (id int, exists bool) { +func (m *SentinelAppBinaryMutation) ID() (id model.InternalID, exists bool) { if m.id == nil { return } @@ -21963,12 +21971,12 @@ func (m *SentinelAppBinaryMutation) ID() (id int, exists bool) { // 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) { +func (m *SentinelAppBinaryMutation) IDs(ctx context.Context) ([]model.InternalID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { - return []int{id}, nil + return []model.InternalID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): @@ -21979,12 +21987,12 @@ func (m *SentinelAppBinaryMutation) IDs(ctx context.Context) ([]int, error) { } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (m *SentinelAppBinaryMutation) SetSentinelLibraryID(i int) { - m.sentinel_library = &i +func (m *SentinelAppBinaryMutation) SetSentinelLibraryID(mi model.InternalID) { + m.sentinel_library = &mi } // SentinelLibraryID returns the value of the "sentinel_library_id" field in the mutation. -func (m *SentinelAppBinaryMutation) SentinelLibraryID() (r int, exists bool) { +func (m *SentinelAppBinaryMutation) SentinelLibraryID() (r model.InternalID, exists bool) { v := m.sentinel_library if v == nil { return @@ -21995,7 +22003,7 @@ func (m *SentinelAppBinaryMutation) SentinelLibraryID() (r int, exists bool) { // OldSentinelLibraryID returns the old "sentinel_library_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) OldSentinelLibraryID(ctx context.Context) (v int, err error) { +func (m *SentinelAppBinaryMutation) OldSentinelLibraryID(ctx context.Context) (v model.InternalID, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSentinelLibraryID is only allowed on UpdateOne operations") } @@ -22410,6 +22418,62 @@ func (m *SentinelAppBinaryMutation) ResetCreatedAt() { m.created_at = nil } +// SetReportSequence sets the "report_sequence" field. +func (m *SentinelAppBinaryMutation) SetReportSequence(i int64) { + m.report_sequence = &i + m.addreport_sequence = nil +} + +// ReportSequence returns the value of the "report_sequence" field in the mutation. +func (m *SentinelAppBinaryMutation) ReportSequence() (r int64, exists bool) { + v := m.report_sequence + if v == nil { + return + } + return *v, true +} + +// OldReportSequence returns the old "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) OldReportSequence(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldReportSequence is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldReportSequence requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldReportSequence: %w", err) + } + return oldValue.ReportSequence, nil +} + +// AddReportSequence adds i to the "report_sequence" field. +func (m *SentinelAppBinaryMutation) AddReportSequence(i int64) { + if m.addreport_sequence != nil { + *m.addreport_sequence += i + } else { + m.addreport_sequence = &i + } +} + +// AddedReportSequence returns the value that was added to the "report_sequence" field in this mutation. +func (m *SentinelAppBinaryMutation) AddedReportSequence() (r int64, exists bool) { + v := m.addreport_sequence + if v == nil { + return + } + return *v, true +} + +// ResetReportSequence resets all changes to the "report_sequence" field. +func (m *SentinelAppBinaryMutation) ResetReportSequence() { + m.report_sequence = nil + m.addreport_sequence = nil +} + // ClearSentinelLibrary clears the "sentinel_library" edge to the SentinelLibrary entity. func (m *SentinelAppBinaryMutation) ClearSentinelLibrary() { m.clearedsentinel_library = true @@ -22424,7 +22488,7 @@ func (m *SentinelAppBinaryMutation) SentinelLibraryCleared() bool { // SentinelLibraryIDs returns the "sentinel_library" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // SentinelLibraryID instead. It exists only for internal usage by the builders. -func (m *SentinelAppBinaryMutation) SentinelLibraryIDs() (ids []int) { +func (m *SentinelAppBinaryMutation) SentinelLibraryIDs() (ids []model.InternalID) { if id := m.sentinel_library; id != nil { ids = append(ids, *id) } @@ -22438,9 +22502,9 @@ func (m *SentinelAppBinaryMutation) ResetSentinelLibrary() { } // AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by ids. -func (m *SentinelAppBinaryMutation) AddSentinelAppBinaryFileIDs(ids ...int) { +func (m *SentinelAppBinaryMutation) AddSentinelAppBinaryFileIDs(ids ...model.InternalID) { if m.sentinel_app_binary_file == nil { - m.sentinel_app_binary_file = make(map[int]struct{}) + m.sentinel_app_binary_file = make(map[model.InternalID]struct{}) } for i := range ids { m.sentinel_app_binary_file[ids[i]] = struct{}{} @@ -22458,9 +22522,9 @@ func (m *SentinelAppBinaryMutation) SentinelAppBinaryFileCleared() bool { } // RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (m *SentinelAppBinaryMutation) RemoveSentinelAppBinaryFileIDs(ids ...int) { +func (m *SentinelAppBinaryMutation) RemoveSentinelAppBinaryFileIDs(ids ...model.InternalID) { if m.removedsentinel_app_binary_file == nil { - m.removedsentinel_app_binary_file = make(map[int]struct{}) + m.removedsentinel_app_binary_file = make(map[model.InternalID]struct{}) } for i := range ids { delete(m.sentinel_app_binary_file, ids[i]) @@ -22469,7 +22533,7 @@ func (m *SentinelAppBinaryMutation) RemoveSentinelAppBinaryFileIDs(ids ...int) { } // RemovedSentinelAppBinaryFile returns the removed IDs of the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity. -func (m *SentinelAppBinaryMutation) RemovedSentinelAppBinaryFileIDs() (ids []int) { +func (m *SentinelAppBinaryMutation) RemovedSentinelAppBinaryFileIDs() (ids []model.InternalID) { for id := range m.removedsentinel_app_binary_file { ids = append(ids, id) } @@ -22477,7 +22541,7 @@ func (m *SentinelAppBinaryMutation) RemovedSentinelAppBinaryFileIDs() (ids []int } // SentinelAppBinaryFileIDs returns the "sentinel_app_binary_file" edge IDs in the mutation. -func (m *SentinelAppBinaryMutation) SentinelAppBinaryFileIDs() (ids []int) { +func (m *SentinelAppBinaryMutation) SentinelAppBinaryFileIDs() (ids []model.InternalID) { for id := range m.sentinel_app_binary_file { ids = append(ids, id) } @@ -22525,7 +22589,7 @@ func (m *SentinelAppBinaryMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *SentinelAppBinaryMutation) Fields() []string { - fields := make([]string, 0, 10) + fields := make([]string, 0, 11) if m.sentinel_library != nil { fields = append(fields, sentinelappbinary.FieldSentinelLibraryID) } @@ -22556,6 +22620,9 @@ func (m *SentinelAppBinaryMutation) Fields() []string { if m.created_at != nil { fields = append(fields, sentinelappbinary.FieldCreatedAt) } + if m.report_sequence != nil { + fields = append(fields, sentinelappbinary.FieldReportSequence) + } return fields } @@ -22584,6 +22651,8 @@ func (m *SentinelAppBinaryMutation) Field(name string) (ent.Value, bool) { return m.UpdatedAt() case sentinelappbinary.FieldCreatedAt: return m.CreatedAt() + case sentinelappbinary.FieldReportSequence: + return m.ReportSequence() } return nil, false } @@ -22613,6 +22682,8 @@ func (m *SentinelAppBinaryMutation) OldField(ctx context.Context, name string) ( return m.OldUpdatedAt(ctx) case sentinelappbinary.FieldCreatedAt: return m.OldCreatedAt(ctx) + case sentinelappbinary.FieldReportSequence: + return m.OldReportSequence(ctx) } return nil, fmt.Errorf("unknown SentinelAppBinary field %s", name) } @@ -22623,7 +22694,7 @@ func (m *SentinelAppBinaryMutation) OldField(ctx context.Context, name string) ( func (m *SentinelAppBinaryMutation) SetField(name string, value ent.Value) error { switch name { case sentinelappbinary.FieldSentinelLibraryID: - v, ok := value.(int) + v, ok := value.(model.InternalID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -22692,6 +22763,13 @@ func (m *SentinelAppBinaryMutation) SetField(name string, value ent.Value) error } m.SetCreatedAt(v) return nil + case sentinelappbinary.FieldReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetReportSequence(v) + return nil } return fmt.Errorf("unknown SentinelAppBinary field %s", name) } @@ -22703,6 +22781,9 @@ func (m *SentinelAppBinaryMutation) AddedFields() []string { if m.addsize_bytes != nil { fields = append(fields, sentinelappbinary.FieldSizeBytes) } + if m.addreport_sequence != nil { + fields = append(fields, sentinelappbinary.FieldReportSequence) + } return fields } @@ -22713,6 +22794,8 @@ func (m *SentinelAppBinaryMutation) AddedField(name string) (ent.Value, bool) { switch name { case sentinelappbinary.FieldSizeBytes: return m.AddedSizeBytes() + case sentinelappbinary.FieldReportSequence: + return m.AddedReportSequence() } return nil, false } @@ -22729,6 +22812,13 @@ func (m *SentinelAppBinaryMutation) AddField(name string, value ent.Value) error } m.AddSizeBytes(v) return nil + case sentinelappbinary.FieldReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddReportSequence(v) + return nil } return fmt.Errorf("unknown SentinelAppBinary numeric field %s", name) } @@ -22813,6 +22903,9 @@ func (m *SentinelAppBinaryMutation) ResetField(name string) error { case sentinelappbinary.FieldCreatedAt: m.ResetCreatedAt() return nil + case sentinelappbinary.FieldReportSequence: + m.ResetReportSequence() + return nil } return fmt.Errorf("unknown SentinelAppBinary field %s", name) } @@ -22924,7 +23017,7 @@ type SentinelAppBinaryFileMutation struct { config op Op typ string - id *int + id *model.InternalID name *string size_bytes *int64 addsize_bytes *int64 @@ -22934,7 +23027,7 @@ type SentinelAppBinaryFileMutation struct { updated_at *time.Time created_at *time.Time clearedFields map[string]struct{} - sentinel_app_binary *int + sentinel_app_binary *model.InternalID clearedsentinel_app_binary bool done bool oldValue func(context.Context) (*SentinelAppBinaryFile, error) @@ -22961,7 +23054,7 @@ func newSentinelAppBinaryFileMutation(c config, op Op, opts ...sentinelappbinary } // withSentinelAppBinaryFileID sets the ID field of the mutation. -func withSentinelAppBinaryFileID(id int) sentinelappbinaryfileOption { +func withSentinelAppBinaryFileID(id model.InternalID) sentinelappbinaryfileOption { return func(m *SentinelAppBinaryFileMutation) { var ( err error @@ -23011,9 +23104,15 @@ func (m SentinelAppBinaryFileMutation) Tx() (*Tx, error) { return tx, nil } +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of SentinelAppBinaryFile entities. +func (m *SentinelAppBinaryFileMutation) 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 *SentinelAppBinaryFileMutation) ID() (id int, exists bool) { +func (m *SentinelAppBinaryFileMutation) ID() (id model.InternalID, exists bool) { if m.id == nil { return } @@ -23024,12 +23123,12 @@ func (m *SentinelAppBinaryFileMutation) ID() (id int, exists bool) { // 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) { +func (m *SentinelAppBinaryFileMutation) IDs(ctx context.Context) ([]model.InternalID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { - return []int{id}, nil + return []model.InternalID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): @@ -23040,12 +23139,12 @@ func (m *SentinelAppBinaryFileMutation) IDs(ctx context.Context) ([]int, error) } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (m *SentinelAppBinaryFileMutation) SetSentinelAppBinaryID(i int) { - m.sentinel_app_binary = &i +func (m *SentinelAppBinaryFileMutation) SetSentinelAppBinaryID(mi model.InternalID) { + m.sentinel_app_binary = &mi } // SentinelAppBinaryID returns the value of the "sentinel_app_binary_id" field in the mutation. -func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryID() (r int, exists bool) { +func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryID() (r model.InternalID, exists bool) { v := m.sentinel_app_binary if v == nil { return @@ -23056,7 +23155,7 @@ func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryID() (r int, exists boo // OldSentinelAppBinaryID returns the old "sentinel_app_binary_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) OldSentinelAppBinaryID(ctx context.Context) (v int, err error) { +func (m *SentinelAppBinaryFileMutation) OldSentinelAppBinaryID(ctx context.Context) (v model.InternalID, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSentinelAppBinaryID is only allowed on UpdateOne operations") } @@ -23374,7 +23473,7 @@ func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryCleared() bool { // SentinelAppBinaryIDs returns the "sentinel_app_binary" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // SentinelAppBinaryID instead. It exists only for internal usage by the builders. -func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryIDs() (ids []int) { +func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryIDs() (ids []model.InternalID) { if id := m.sentinel_app_binary; id != nil { ids = append(ids, *id) } @@ -23505,7 +23604,7 @@ func (m *SentinelAppBinaryFileMutation) OldField(ctx context.Context, name strin func (m *SentinelAppBinaryFileMutation) SetField(name string, value ent.Value) error { switch name { case sentinelappbinaryfile.FieldSentinelAppBinaryID: - v, ok := value.(int) + v, ok := value.(model.InternalID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -23740,9 +23839,7 @@ type SentinelInfoMutation struct { config op Op typ string - id *int - user_id *model.InternalID - adduser_id *model.InternalID + id *model.InternalID url *string alternative_urls *[]string appendalternative_urls []string @@ -23751,8 +23848,8 @@ type SentinelInfoMutation struct { updated_at *time.Time created_at *time.Time clearedFields map[string]struct{} - sentinel_library map[int]struct{} - removedsentinel_library map[int]struct{} + sentinel_library map[model.InternalID]struct{} + removedsentinel_library map[model.InternalID]struct{} clearedsentinel_library bool done bool oldValue func(context.Context) (*SentinelInfo, error) @@ -23779,7 +23876,7 @@ func newSentinelInfoMutation(c config, op Op, opts ...sentinelinfoOption) *Senti } // withSentinelInfoID sets the ID field of the mutation. -func withSentinelInfoID(id int) sentinelinfoOption { +func withSentinelInfoID(id model.InternalID) sentinelinfoOption { return func(m *SentinelInfoMutation) { var ( err error @@ -23829,9 +23926,15 @@ func (m SentinelInfoMutation) Tx() (*Tx, error) { 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 int, exists bool) { +func (m *SentinelInfoMutation) ID() (id model.InternalID, exists bool) { if m.id == nil { return } @@ -23842,12 +23945,12 @@ func (m *SentinelInfoMutation) ID() (id int, exists bool) { // 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) ([]int, error) { +func (m *SentinelInfoMutation) IDs(ctx context.Context) ([]model.InternalID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { - return []int{id}, nil + return []model.InternalID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): @@ -23857,62 +23960,6 @@ func (m *SentinelInfoMutation) IDs(ctx context.Context) ([]int, error) { } } -// SetUserID sets the "user_id" field. -func (m *SentinelInfoMutation) SetUserID(mi model.InternalID) { - m.user_id = &mi - m.adduser_id = nil -} - -// UserID returns the value of the "user_id" field in the mutation. -func (m *SentinelInfoMutation) UserID() (r model.InternalID, exists bool) { - v := m.user_id - if v == nil { - return - } - return *v, true -} - -// OldUserID returns the old "user_id" 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) OldUserID(ctx context.Context) (v model.InternalID, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUserID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUserID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUserID: %w", err) - } - return oldValue.UserID, nil -} - -// AddUserID adds mi to the "user_id" field. -func (m *SentinelInfoMutation) AddUserID(mi model.InternalID) { - if m.adduser_id != nil { - *m.adduser_id += mi - } else { - m.adduser_id = &mi - } -} - -// AddedUserID returns the value that was added to the "user_id" field in this mutation. -func (m *SentinelInfoMutation) AddedUserID() (r model.InternalID, exists bool) { - v := m.adduser_id - if v == nil { - return - } - return *v, true -} - -// ResetUserID resets all changes to the "user_id" field. -func (m *SentinelInfoMutation) ResetUserID() { - m.user_id = nil - m.adduser_id = nil -} - // SetURL sets the "url" field. func (m *SentinelInfoMutation) SetURL(s string) { m.url = &s @@ -24172,9 +24219,9 @@ func (m *SentinelInfoMutation) ResetCreatedAt() { } // AddSentinelLibraryIDs adds the "sentinel_library" edge to the SentinelLibrary entity by ids. -func (m *SentinelInfoMutation) AddSentinelLibraryIDs(ids ...int) { +func (m *SentinelInfoMutation) AddSentinelLibraryIDs(ids ...model.InternalID) { if m.sentinel_library == nil { - m.sentinel_library = make(map[int]struct{}) + m.sentinel_library = make(map[model.InternalID]struct{}) } for i := range ids { m.sentinel_library[ids[i]] = struct{}{} @@ -24192,9 +24239,9 @@ func (m *SentinelInfoMutation) SentinelLibraryCleared() bool { } // RemoveSentinelLibraryIDs removes the "sentinel_library" edge to the SentinelLibrary entity by IDs. -func (m *SentinelInfoMutation) RemoveSentinelLibraryIDs(ids ...int) { +func (m *SentinelInfoMutation) RemoveSentinelLibraryIDs(ids ...model.InternalID) { if m.removedsentinel_library == nil { - m.removedsentinel_library = make(map[int]struct{}) + m.removedsentinel_library = make(map[model.InternalID]struct{}) } for i := range ids { delete(m.sentinel_library, ids[i]) @@ -24203,7 +24250,7 @@ func (m *SentinelInfoMutation) RemoveSentinelLibraryIDs(ids ...int) { } // RemovedSentinelLibrary returns the removed IDs of the "sentinel_library" edge to the SentinelLibrary entity. -func (m *SentinelInfoMutation) RemovedSentinelLibraryIDs() (ids []int) { +func (m *SentinelInfoMutation) RemovedSentinelLibraryIDs() (ids []model.InternalID) { for id := range m.removedsentinel_library { ids = append(ids, id) } @@ -24211,7 +24258,7 @@ func (m *SentinelInfoMutation) RemovedSentinelLibraryIDs() (ids []int) { } // SentinelLibraryIDs returns the "sentinel_library" edge IDs in the mutation. -func (m *SentinelInfoMutation) SentinelLibraryIDs() (ids []int) { +func (m *SentinelInfoMutation) SentinelLibraryIDs() (ids []model.InternalID) { for id := range m.sentinel_library { ids = append(ids, id) } @@ -24259,10 +24306,7 @@ func (m *SentinelInfoMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *SentinelInfoMutation) Fields() []string { - fields := make([]string, 0, 7) - if m.user_id != nil { - fields = append(fields, sentinelinfo.FieldUserID) - } + fields := make([]string, 0, 6) if m.url != nil { fields = append(fields, sentinelinfo.FieldURL) } @@ -24289,8 +24333,6 @@ func (m *SentinelInfoMutation) Fields() []string { // schema. func (m *SentinelInfoMutation) Field(name string) (ent.Value, bool) { switch name { - case sentinelinfo.FieldUserID: - return m.UserID() case sentinelinfo.FieldURL: return m.URL() case sentinelinfo.FieldAlternativeUrls: @@ -24312,8 +24354,6 @@ func (m *SentinelInfoMutation) Field(name string) (ent.Value, bool) { // database failed. func (m *SentinelInfoMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case sentinelinfo.FieldUserID: - return m.OldUserID(ctx) case sentinelinfo.FieldURL: return m.OldURL(ctx) case sentinelinfo.FieldAlternativeUrls: @@ -24335,13 +24375,6 @@ func (m *SentinelInfoMutation) OldField(ctx context.Context, name string) (ent.V // type. func (m *SentinelInfoMutation) SetField(name string, value ent.Value) error { switch name { - case sentinelinfo.FieldUserID: - v, ok := value.(model.InternalID) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUserID(v) - return nil case sentinelinfo.FieldURL: v, ok := value.(string) if !ok { @@ -24391,21 +24424,13 @@ func (m *SentinelInfoMutation) SetField(name string, value ent.Value) error { // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *SentinelInfoMutation) AddedFields() []string { - var fields []string - if m.adduser_id != nil { - fields = append(fields, sentinelinfo.FieldUserID) - } - return fields + return nil } // 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.FieldUserID: - return m.AddedUserID() - } return nil, false } @@ -24414,13 +24439,6 @@ func (m *SentinelInfoMutation) AddedField(name string) (ent.Value, bool) { // type. func (m *SentinelInfoMutation) AddField(name string, value ent.Value) error { switch name { - case sentinelinfo.FieldUserID: - v, ok := value.(model.InternalID) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.AddUserID(v) - return nil } return fmt.Errorf("unknown SentinelInfo numeric field %s", name) } @@ -24463,9 +24481,6 @@ func (m *SentinelInfoMutation) ClearField(name string) error { // It returns an error if the field is not defined in the schema. func (m *SentinelInfoMutation) ResetField(name string) error { switch name { - case sentinelinfo.FieldUserID: - m.ResetUserID() - return nil case sentinelinfo.FieldURL: m.ResetURL() return nil @@ -24577,17 +24592,19 @@ type SentinelLibraryMutation struct { config op Op typ string - id *int + id *model.InternalID reported_id *int64 addreported_id *int64 download_base_path *string updated_at *time.Time created_at *time.Time + report_sequence *int64 + addreport_sequence *int64 clearedFields map[string]struct{} - sentinel_info *int + sentinel_info *model.InternalID clearedsentinel_info bool - sentinel_app_binary map[int]struct{} - removedsentinel_app_binary map[int]struct{} + sentinel_app_binary map[model.InternalID]struct{} + removedsentinel_app_binary map[model.InternalID]struct{} clearedsentinel_app_binary bool done bool oldValue func(context.Context) (*SentinelLibrary, error) @@ -24614,7 +24631,7 @@ func newSentinelLibraryMutation(c config, op Op, opts ...sentinellibraryOption) } // withSentinelLibraryID sets the ID field of the mutation. -func withSentinelLibraryID(id int) sentinellibraryOption { +func withSentinelLibraryID(id model.InternalID) sentinellibraryOption { return func(m *SentinelLibraryMutation) { var ( err error @@ -24664,9 +24681,15 @@ func (m SentinelLibraryMutation) Tx() (*Tx, error) { return tx, nil } +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of SentinelLibrary entities. +func (m *SentinelLibraryMutation) 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 *SentinelLibraryMutation) ID() (id int, exists bool) { +func (m *SentinelLibraryMutation) ID() (id model.InternalID, exists bool) { if m.id == nil { return } @@ -24677,12 +24700,12 @@ func (m *SentinelLibraryMutation) ID() (id int, exists bool) { // 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) { +func (m *SentinelLibraryMutation) IDs(ctx context.Context) ([]model.InternalID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { - return []int{id}, nil + return []model.InternalID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): @@ -24693,12 +24716,12 @@ func (m *SentinelLibraryMutation) IDs(ctx context.Context) ([]int, error) { } // SetSentinelInfoID sets the "sentinel_info_id" field. -func (m *SentinelLibraryMutation) SetSentinelInfoID(i int) { - m.sentinel_info = &i +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 int, exists bool) { +func (m *SentinelLibraryMutation) SentinelInfoID() (r model.InternalID, exists bool) { v := m.sentinel_info if v == nil { return @@ -24709,7 +24732,7 @@ func (m *SentinelLibraryMutation) SentinelInfoID() (r int, exists bool) { // 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 int, err error) { +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") } @@ -24892,6 +24915,62 @@ func (m *SentinelLibraryMutation) ResetCreatedAt() { m.created_at = nil } +// SetReportSequence sets the "report_sequence" field. +func (m *SentinelLibraryMutation) SetReportSequence(i int64) { + m.report_sequence = &i + m.addreport_sequence = nil +} + +// ReportSequence returns the value of the "report_sequence" field in the mutation. +func (m *SentinelLibraryMutation) ReportSequence() (r int64, exists bool) { + v := m.report_sequence + if v == nil { + return + } + return *v, true +} + +// OldReportSequence returns the old "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) OldReportSequence(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldReportSequence is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldReportSequence requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldReportSequence: %w", err) + } + return oldValue.ReportSequence, nil +} + +// AddReportSequence adds i to the "report_sequence" field. +func (m *SentinelLibraryMutation) AddReportSequence(i int64) { + if m.addreport_sequence != nil { + *m.addreport_sequence += i + } else { + m.addreport_sequence = &i + } +} + +// AddedReportSequence returns the value that was added to the "report_sequence" field in this mutation. +func (m *SentinelLibraryMutation) AddedReportSequence() (r int64, exists bool) { + v := m.addreport_sequence + if v == nil { + return + } + return *v, true +} + +// ResetReportSequence resets all changes to the "report_sequence" field. +func (m *SentinelLibraryMutation) ResetReportSequence() { + m.report_sequence = nil + m.addreport_sequence = nil +} + // ClearSentinelInfo clears the "sentinel_info" edge to the SentinelInfo entity. func (m *SentinelLibraryMutation) ClearSentinelInfo() { m.clearedsentinel_info = true @@ -24906,7 +24985,7 @@ func (m *SentinelLibraryMutation) SentinelInfoCleared() bool { // 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 []int) { +func (m *SentinelLibraryMutation) SentinelInfoIDs() (ids []model.InternalID) { if id := m.sentinel_info; id != nil { ids = append(ids, *id) } @@ -24920,9 +24999,9 @@ func (m *SentinelLibraryMutation) ResetSentinelInfo() { } // AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by ids. -func (m *SentinelLibraryMutation) AddSentinelAppBinaryIDs(ids ...int) { +func (m *SentinelLibraryMutation) AddSentinelAppBinaryIDs(ids ...model.InternalID) { if m.sentinel_app_binary == nil { - m.sentinel_app_binary = make(map[int]struct{}) + m.sentinel_app_binary = make(map[model.InternalID]struct{}) } for i := range ids { m.sentinel_app_binary[ids[i]] = struct{}{} @@ -24940,9 +25019,9 @@ func (m *SentinelLibraryMutation) SentinelAppBinaryCleared() bool { } // RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (m *SentinelLibraryMutation) RemoveSentinelAppBinaryIDs(ids ...int) { +func (m *SentinelLibraryMutation) RemoveSentinelAppBinaryIDs(ids ...model.InternalID) { if m.removedsentinel_app_binary == nil { - m.removedsentinel_app_binary = make(map[int]struct{}) + m.removedsentinel_app_binary = make(map[model.InternalID]struct{}) } for i := range ids { delete(m.sentinel_app_binary, ids[i]) @@ -24951,7 +25030,7 @@ func (m *SentinelLibraryMutation) RemoveSentinelAppBinaryIDs(ids ...int) { } // RemovedSentinelAppBinary returns the removed IDs of the "sentinel_app_binary" edge to the SentinelAppBinary entity. -func (m *SentinelLibraryMutation) RemovedSentinelAppBinaryIDs() (ids []int) { +func (m *SentinelLibraryMutation) RemovedSentinelAppBinaryIDs() (ids []model.InternalID) { for id := range m.removedsentinel_app_binary { ids = append(ids, id) } @@ -24959,7 +25038,7 @@ func (m *SentinelLibraryMutation) RemovedSentinelAppBinaryIDs() (ids []int) { } // SentinelAppBinaryIDs returns the "sentinel_app_binary" edge IDs in the mutation. -func (m *SentinelLibraryMutation) SentinelAppBinaryIDs() (ids []int) { +func (m *SentinelLibraryMutation) SentinelAppBinaryIDs() (ids []model.InternalID) { for id := range m.sentinel_app_binary { ids = append(ids, id) } @@ -25007,7 +25086,7 @@ func (m *SentinelLibraryMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *SentinelLibraryMutation) Fields() []string { - fields := make([]string, 0, 5) + fields := make([]string, 0, 6) if m.sentinel_info != nil { fields = append(fields, sentinellibrary.FieldSentinelInfoID) } @@ -25023,6 +25102,9 @@ func (m *SentinelLibraryMutation) Fields() []string { if m.created_at != nil { fields = append(fields, sentinellibrary.FieldCreatedAt) } + if m.report_sequence != nil { + fields = append(fields, sentinellibrary.FieldReportSequence) + } return fields } @@ -25041,6 +25123,8 @@ func (m *SentinelLibraryMutation) Field(name string) (ent.Value, bool) { return m.UpdatedAt() case sentinellibrary.FieldCreatedAt: return m.CreatedAt() + case sentinellibrary.FieldReportSequence: + return m.ReportSequence() } return nil, false } @@ -25060,6 +25144,8 @@ func (m *SentinelLibraryMutation) OldField(ctx context.Context, name string) (en return m.OldUpdatedAt(ctx) case sentinellibrary.FieldCreatedAt: return m.OldCreatedAt(ctx) + case sentinellibrary.FieldReportSequence: + return m.OldReportSequence(ctx) } return nil, fmt.Errorf("unknown SentinelLibrary field %s", name) } @@ -25070,7 +25156,7 @@ func (m *SentinelLibraryMutation) OldField(ctx context.Context, name string) (en func (m *SentinelLibraryMutation) SetField(name string, value ent.Value) error { switch name { case sentinellibrary.FieldSentinelInfoID: - v, ok := value.(int) + v, ok := value.(model.InternalID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -25104,6 +25190,13 @@ func (m *SentinelLibraryMutation) SetField(name string, value ent.Value) error { } m.SetCreatedAt(v) return nil + case sentinellibrary.FieldReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetReportSequence(v) + return nil } return fmt.Errorf("unknown SentinelLibrary field %s", name) } @@ -25115,6 +25208,9 @@ func (m *SentinelLibraryMutation) AddedFields() []string { if m.addreported_id != nil { fields = append(fields, sentinellibrary.FieldReportedID) } + if m.addreport_sequence != nil { + fields = append(fields, sentinellibrary.FieldReportSequence) + } return fields } @@ -25125,6 +25221,8 @@ func (m *SentinelLibraryMutation) AddedField(name string) (ent.Value, bool) { switch name { case sentinellibrary.FieldReportedID: return m.AddedReportedID() + case sentinellibrary.FieldReportSequence: + return m.AddedReportSequence() } return nil, false } @@ -25141,6 +25239,13 @@ func (m *SentinelLibraryMutation) AddField(name string, value ent.Value) error { } m.AddReportedID(v) return nil + case sentinellibrary.FieldReportSequence: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddReportSequence(v) + return nil } return fmt.Errorf("unknown SentinelLibrary numeric field %s", name) } @@ -25183,6 +25288,9 @@ func (m *SentinelLibraryMutation) ResetField(name string) error { case sentinellibrary.FieldCreatedAt: m.ResetCreatedAt() return nil + case sentinellibrary.FieldReportSequence: + m.ResetReportSequence() + return nil } return fmt.Errorf("unknown SentinelLibrary field %s", name) } diff --git a/internal/data/internal/ent/runtime.go b/internal/data/internal/ent/runtime.go index 821891c6..723dd0f3 100644 --- a/internal/data/internal/ent/runtime.go +++ b/internal/data/internal/ent/runtime.go @@ -314,25 +314,25 @@ func init() { sentinelappbinaryFields := schema.SentinelAppBinary{}.Fields() _ = sentinelappbinaryFields // sentinelappbinaryDescUpdatedAt is the schema descriptor for updated_at field. - sentinelappbinaryDescUpdatedAt := sentinelappbinaryFields[8].Descriptor() + 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[9].Descriptor() + 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[6].Descriptor() + sentinelappbinaryfileDescUpdatedAt := sentinelappbinaryfileFields[7].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[7].Descriptor() + sentinelappbinaryfileDescCreatedAt := sentinelappbinaryfileFields[8].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() @@ -350,13 +350,13 @@ func init() { sentinellibraryFields := schema.SentinelLibrary{}.Fields() _ = sentinellibraryFields // sentinellibraryDescUpdatedAt is the schema descriptor for updated_at field. - sentinellibraryDescUpdatedAt := sentinellibraryFields[3].Descriptor() + sentinellibraryDescUpdatedAt := sentinellibraryFields[4].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() + sentinellibraryDescCreatedAt := sentinellibraryFields[5].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() diff --git a/internal/data/internal/ent/schema/sentinel_app_binary.go b/internal/data/internal/ent/schema/sentinel_app_binary.go index bf257ee8..91fdcfd8 100644 --- a/internal/data/internal/ent/schema/sentinel_app_binary.go +++ b/internal/data/internal/ent/schema/sentinel_app_binary.go @@ -3,6 +3,8 @@ package schema import ( "time" + "github.com/tuihub/librarian/internal/model" + "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" @@ -15,7 +17,8 @@ type SentinelAppBinary struct { func (SentinelAppBinary) Fields() []ent.Field { return []ent.Field{ - field.Int("sentinel_library_id"), + defaultPrimaryKey(), + field.Int64("sentinel_library_id").GoType(model.InternalID(0)), field.String("generated_id"), field.Int64("size_bytes"), field.Bool("need_token"), @@ -27,12 +30,15 @@ func (SentinelAppBinary) Fields() []ent.Field { Default(time.Now).UpdateDefault(time.Now), field.Time("created_at"). Default(time.Now), + field.Int64("report_sequence"), } } func (SentinelAppBinary) Indexes() []ent.Index { return []ent.Index{ - index.Fields("sentinel_library_id", "generated_id"), + index.Fields("sentinel_library_id", "generated_id"). + Unique(), + index.Fields("generated_id"), } } diff --git a/internal/data/internal/ent/schema/sentinel_app_binary_file.go b/internal/data/internal/ent/schema/sentinel_app_binary_file.go index 3f4fc30c..d1118c52 100644 --- a/internal/data/internal/ent/schema/sentinel_app_binary_file.go +++ b/internal/data/internal/ent/schema/sentinel_app_binary_file.go @@ -3,6 +3,8 @@ package schema import ( "time" + "github.com/tuihub/librarian/internal/model" + "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" @@ -15,7 +17,8 @@ type SentinelAppBinaryFile struct { func (SentinelAppBinaryFile) Fields() []ent.Field { return []ent.Field{ - field.Int("sentinel_app_binary_id"), + defaultPrimaryKey(), + field.Int64("sentinel_app_binary_id").GoType(model.InternalID(0)), field.String("name"), field.Int64("size_bytes"), field.Bytes("sha256"), diff --git a/internal/data/internal/ent/schema/sentinel_info.go b/internal/data/internal/ent/schema/sentinel_info.go index a233d82f..b6306bc9 100644 --- a/internal/data/internal/ent/schema/sentinel_info.go +++ b/internal/data/internal/ent/schema/sentinel_info.go @@ -3,12 +3,9 @@ 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 SentinelInfo struct { @@ -17,7 +14,7 @@ type SentinelInfo struct { func (SentinelInfo) Fields() []ent.Field { return []ent.Field{ - field.Int64("user_id").GoType(model.InternalID(0)), + defaultPrimaryKey(), field.String("url"), field.Strings("alternative_urls").Optional(), field.String("get_token_path").Optional(), @@ -30,9 +27,7 @@ func (SentinelInfo) Fields() []ent.Field { } func (SentinelInfo) Indexes() []ent.Index { - return []ent.Index{ - index.Fields("user_id"), - } + return []ent.Index{} } func (SentinelInfo) Edges() []ent.Edge { diff --git a/internal/data/internal/ent/schema/sentinel_library.go b/internal/data/internal/ent/schema/sentinel_library.go index 0f8c8345..56f3039b 100644 --- a/internal/data/internal/ent/schema/sentinel_library.go +++ b/internal/data/internal/ent/schema/sentinel_library.go @@ -3,6 +3,8 @@ package schema import ( "time" + "github.com/tuihub/librarian/internal/model" + "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" @@ -15,18 +17,22 @@ type SentinelLibrary struct { func (SentinelLibrary) Fields() []ent.Field { return []ent.Field{ - field.Int("sentinel_info_id"), + defaultPrimaryKey(), + 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("report_sequence"), } } + func (SentinelLibrary) Indexes() []ent.Index { return []ent.Index{ - index.Fields("sentinel_info_id", "reported_id"), + index.Fields("sentinel_info_id", "reported_id"). + Unique(), } } diff --git a/internal/data/internal/ent/sentinelappbinary.go b/internal/data/internal/ent/sentinelappbinary.go index c55dcecd..f0cc90bb 100644 --- a/internal/data/internal/ent/sentinelappbinary.go +++ b/internal/data/internal/ent/sentinelappbinary.go @@ -11,15 +11,16 @@ import ( "entgo.io/ent/dialect/sql" "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" + "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"` + ID model.InternalID `json:"id,omitempty"` // SentinelLibraryID holds the value of the "sentinel_library_id" field. - SentinelLibraryID int `json:"sentinel_library_id,omitempty"` + SentinelLibraryID model.InternalID `json:"sentinel_library_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. @@ -38,6 +39,8 @@ type SentinelAppBinary struct { UpdatedAt time.Time `json:"updated_at,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` + // ReportSequence holds the value of the "report_sequence" field. + ReportSequence int64 `json:"report_sequence,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the SentinelAppBinaryQuery when eager-loading is set. Edges SentinelAppBinaryEdges `json:"edges"` @@ -82,7 +85,7 @@ func (*SentinelAppBinary) scanValues(columns []string) ([]any, error) { switch columns[i] { case sentinelappbinary.FieldNeedToken: values[i] = new(sql.NullBool) - case sentinelappbinary.FieldID, sentinelappbinary.FieldSentinelLibraryID, sentinelappbinary.FieldSizeBytes: + case sentinelappbinary.FieldID, sentinelappbinary.FieldSentinelLibraryID, sentinelappbinary.FieldSizeBytes, sentinelappbinary.FieldReportSequence: values[i] = new(sql.NullInt64) case sentinelappbinary.FieldGeneratedID, sentinelappbinary.FieldName, sentinelappbinary.FieldVersion, sentinelappbinary.FieldDeveloper, sentinelappbinary.FieldPublisher: values[i] = new(sql.NullString) @@ -104,16 +107,16 @@ func (sab *SentinelAppBinary) assignValues(columns []string, values []any) error 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) + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value.Valid { + sab.ID = model.InternalID(value.Int64) } - sab.ID = int(value.Int64) case sentinelappbinary.FieldSentinelLibraryID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field sentinel_library_id", values[i]) } else if value.Valid { - sab.SentinelLibraryID = int(value.Int64) + sab.SentinelLibraryID = model.InternalID(value.Int64) } case sentinelappbinary.FieldGeneratedID: if value, ok := values[i].(*sql.NullString); !ok { @@ -169,6 +172,12 @@ func (sab *SentinelAppBinary) assignValues(columns []string, values []any) error } else if value.Valid { sab.CreatedAt = value.Time } + case sentinelappbinary.FieldReportSequence: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field report_sequence", values[i]) + } else if value.Valid { + sab.ReportSequence = value.Int64 + } default: sab.selectValues.Set(columns[i], values[i]) } @@ -244,6 +253,9 @@ func (sab *SentinelAppBinary) String() string { builder.WriteString(", ") builder.WriteString("created_at=") builder.WriteString(sab.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("report_sequence=") + builder.WriteString(fmt.Sprintf("%v", sab.ReportSequence)) builder.WriteByte(')') return builder.String() } diff --git a/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go b/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go index 06fd4b7a..137734c4 100644 --- a/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go +++ b/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go @@ -34,6 +34,8 @@ const ( FieldUpdatedAt = "updated_at" // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" + // FieldReportSequence holds the string denoting the report_sequence field in the database. + FieldReportSequence = "report_sequence" // EdgeSentinelLibrary holds the string denoting the sentinel_library edge name in mutations. EdgeSentinelLibrary = "sentinel_library" // EdgeSentinelAppBinaryFile holds the string denoting the sentinel_app_binary_file edge name in mutations. @@ -69,6 +71,7 @@ var Columns = []string{ FieldPublisher, FieldUpdatedAt, FieldCreatedAt, + FieldReportSequence, } // ValidColumn reports if the column name is valid (part of the table columns). @@ -148,6 +151,11 @@ func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() } +// ByReportSequence orders the results by the report_sequence field. +func ByReportSequence(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldReportSequence, opts...).ToFunc() +} + // BySentinelLibraryField orders the results by sentinel_library field. func BySentinelLibraryField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { diff --git a/internal/data/internal/ent/sentinelappbinary/where.go b/internal/data/internal/ent/sentinelappbinary/where.go index 0be68fe9..1008426d 100644 --- a/internal/data/internal/ent/sentinelappbinary/where.go +++ b/internal/data/internal/ent/sentinelappbinary/where.go @@ -8,56 +8,58 @@ import ( "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.SentinelAppBinary { +func ID(id model.InternalID) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.SentinelAppBinary { +func IDEQ(id model.InternalID) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.SentinelAppBinary { +func IDNEQ(id model.InternalID) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.SentinelAppBinary { +func IDIn(ids ...model.InternalID) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.SentinelAppBinary { +func IDNotIn(ids ...model.InternalID) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.SentinelAppBinary { +func IDGT(id model.InternalID) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.SentinelAppBinary { +func IDGTE(id model.InternalID) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.SentinelAppBinary { +func IDLT(id model.InternalID) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.SentinelAppBinary { +func IDLTE(id model.InternalID) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldLTE(FieldID, id)) } // SentinelLibraryID applies equality check predicate on the "sentinel_library_id" field. It's identical to SentinelLibraryIDEQ. -func SentinelLibraryID(v int) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, v)) +func SentinelLibraryID(v model.InternalID) predicate.SentinelAppBinary { + vc := int64(v) + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, vc)) } // GeneratedID applies equality check predicate on the "generated_id" field. It's identical to GeneratedIDEQ. @@ -105,24 +107,39 @@ func CreatedAt(v time.Time) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldEQ(FieldCreatedAt, v)) } +// ReportSequence applies equality check predicate on the "report_sequence" field. It's identical to ReportSequenceEQ. +func ReportSequence(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldReportSequence, v)) +} + // SentinelLibraryIDEQ applies the EQ predicate on the "sentinel_library_id" field. -func SentinelLibraryIDEQ(v int) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, v)) +func SentinelLibraryIDEQ(v model.InternalID) predicate.SentinelAppBinary { + vc := int64(v) + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, vc)) } // SentinelLibraryIDNEQ applies the NEQ predicate on the "sentinel_library_id" field. -func SentinelLibraryIDNEQ(v int) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldNEQ(FieldSentinelLibraryID, v)) +func SentinelLibraryIDNEQ(v model.InternalID) predicate.SentinelAppBinary { + vc := int64(v) + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldSentinelLibraryID, vc)) } // SentinelLibraryIDIn applies the In predicate on the "sentinel_library_id" field. -func SentinelLibraryIDIn(vs ...int) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldIn(FieldSentinelLibraryID, vs...)) +func SentinelLibraryIDIn(vs ...model.InternalID) predicate.SentinelAppBinary { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelAppBinary(sql.FieldIn(FieldSentinelLibraryID, v...)) } // SentinelLibraryIDNotIn applies the NotIn predicate on the "sentinel_library_id" field. -func SentinelLibraryIDNotIn(vs ...int) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldNotIn(FieldSentinelLibraryID, vs...)) +func SentinelLibraryIDNotIn(vs ...model.InternalID) predicate.SentinelAppBinary { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldSentinelLibraryID, v...)) } // GeneratedIDEQ applies the EQ predicate on the "generated_id" field. @@ -620,6 +637,46 @@ func CreatedAtLTE(v time.Time) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldLTE(FieldCreatedAt, v)) } +// ReportSequenceEQ applies the EQ predicate on the "report_sequence" field. +func ReportSequenceEQ(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldReportSequence, v)) +} + +// ReportSequenceNEQ applies the NEQ predicate on the "report_sequence" field. +func ReportSequenceNEQ(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldReportSequence, v)) +} + +// ReportSequenceIn applies the In predicate on the "report_sequence" field. +func ReportSequenceIn(vs ...int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldReportSequence, vs...)) +} + +// ReportSequenceNotIn applies the NotIn predicate on the "report_sequence" field. +func ReportSequenceNotIn(vs ...int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldReportSequence, vs...)) +} + +// ReportSequenceGT applies the GT predicate on the "report_sequence" field. +func ReportSequenceGT(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGT(FieldReportSequence, v)) +} + +// ReportSequenceGTE applies the GTE predicate on the "report_sequence" field. +func ReportSequenceGTE(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldGTE(FieldReportSequence, v)) +} + +// ReportSequenceLT applies the LT predicate on the "report_sequence" field. +func ReportSequenceLT(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLT(FieldReportSequence, v)) +} + +// ReportSequenceLTE applies the LTE predicate on the "report_sequence" field. +func ReportSequenceLTE(v int64) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldLTE(FieldReportSequence, v)) +} + // HasSentinelLibrary applies the HasEdge predicate on the "sentinel_library" edge. func HasSentinelLibrary() predicate.SentinelAppBinary { return predicate.SentinelAppBinary(func(s *sql.Selector) { diff --git a/internal/data/internal/ent/sentinelappbinary_create.go b/internal/data/internal/ent/sentinelappbinary_create.go index 59891699..65d95248 100644 --- a/internal/data/internal/ent/sentinelappbinary_create.go +++ b/internal/data/internal/ent/sentinelappbinary_create.go @@ -14,6 +14,7 @@ import ( "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/sentinellibrary" + "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryCreate is the builder for creating a SentinelAppBinary entity. @@ -25,8 +26,8 @@ type SentinelAppBinaryCreate struct { } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (sabc *SentinelAppBinaryCreate) SetSentinelLibraryID(i int) *SentinelAppBinaryCreate { - sabc.mutation.SetSentinelLibraryID(i) +func (sabc *SentinelAppBinaryCreate) SetSentinelLibraryID(mi model.InternalID) *SentinelAppBinaryCreate { + sabc.mutation.SetSentinelLibraryID(mi) return sabc } @@ -132,20 +133,32 @@ func (sabc *SentinelAppBinaryCreate) SetNillableCreatedAt(t *time.Time) *Sentine return sabc } +// SetReportSequence sets the "report_sequence" field. +func (sabc *SentinelAppBinaryCreate) SetReportSequence(i int64) *SentinelAppBinaryCreate { + sabc.mutation.SetReportSequence(i) + return sabc +} + +// SetID sets the "id" field. +func (sabc *SentinelAppBinaryCreate) SetID(mi model.InternalID) *SentinelAppBinaryCreate { + sabc.mutation.SetID(mi) + return sabc +} + // SetSentinelLibrary sets the "sentinel_library" edge to the SentinelLibrary entity. func (sabc *SentinelAppBinaryCreate) SetSentinelLibrary(s *SentinelLibrary) *SentinelAppBinaryCreate { return sabc.SetSentinelLibraryID(s.ID) } // AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (sabc *SentinelAppBinaryCreate) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryCreate { +func (sabc *SentinelAppBinaryCreate) AddSentinelAppBinaryFileIDs(ids ...model.InternalID) *SentinelAppBinaryCreate { sabc.mutation.AddSentinelAppBinaryFileIDs(ids...) return sabc } // AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. func (sabc *SentinelAppBinaryCreate) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryCreate { - ids := make([]int, len(s)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -217,6 +230,9 @@ func (sabc *SentinelAppBinaryCreate) check() error { 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.ReportSequence(); !ok { + return &ValidationError{Name: "report_sequence", err: errors.New(`ent: missing required field "SentinelAppBinary.report_sequence"`)} + } if len(sabc.mutation.SentinelLibraryIDs()) == 0 { return &ValidationError{Name: "sentinel_library", err: errors.New(`ent: missing required edge "SentinelAppBinary.sentinel_library"`)} } @@ -234,8 +250,10 @@ func (sabc *SentinelAppBinaryCreate) sqlSave(ctx context.Context) (*SentinelAppB } return nil, err } - id := _spec.ID.Value.(int64) - _node.ID = int(id) + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = model.InternalID(id) + } sabc.mutation.id = &_node.ID sabc.mutation.done = true return _node, nil @@ -244,9 +262,13 @@ func (sabc *SentinelAppBinaryCreate) sqlSave(ctx context.Context) (*SentinelAppB 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 = sqlgraph.NewCreateSpec(sentinelappbinary.Table, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64)) ) _spec.OnConflict = sabc.conflict + if id, ok := sabc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } if value, ok := sabc.mutation.GeneratedID(); ok { _spec.SetField(sentinelappbinary.FieldGeneratedID, field.TypeString, value) _node.GeneratedID = value @@ -283,6 +305,10 @@ func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph _spec.SetField(sentinelappbinary.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } + if value, ok := sabc.mutation.ReportSequence(); ok { + _spec.SetField(sentinelappbinary.FieldReportSequence, field.TypeInt64, value) + _node.ReportSequence = value + } if nodes := sabc.mutation.SentinelLibraryIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -291,7 +317,7 @@ func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph Columns: []string{sentinelappbinary.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -308,7 +334,7 @@ func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -369,7 +395,7 @@ type ( ) // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (u *SentinelAppBinaryUpsert) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsert { +func (u *SentinelAppBinaryUpsert) SetSentinelLibraryID(v model.InternalID) *SentinelAppBinaryUpsert { u.Set(sentinelappbinary.FieldSentinelLibraryID, v) return u } @@ -518,16 +544,42 @@ func (u *SentinelAppBinaryUpsert) UpdateCreatedAt() *SentinelAppBinaryUpsert { return u } -// UpdateNewValues updates the mutable fields using the new values that were set on create. +// SetReportSequence sets the "report_sequence" field. +func (u *SentinelAppBinaryUpsert) SetReportSequence(v int64) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldReportSequence, v) + return u +} + +// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsert) UpdateReportSequence() *SentinelAppBinaryUpsert { + u.SetExcluded(sentinelappbinary.FieldReportSequence) + return u +} + +// AddReportSequence adds v to the "report_sequence" field. +func (u *SentinelAppBinaryUpsert) AddReportSequence(v int64) *SentinelAppBinaryUpsert { + u.Add(sentinelappbinary.FieldReportSequence, 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.SentinelAppBinary.Create(). // OnConflict( // sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(sentinelappbinary.FieldID) +// }), // ). // Exec(ctx) func (u *SentinelAppBinaryUpsertOne) UpdateNewValues() *SentinelAppBinaryUpsertOne { 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(sentinelappbinary.FieldID) + } + })) return u } @@ -559,7 +611,7 @@ func (u *SentinelAppBinaryUpsertOne) Update(set func(*SentinelAppBinaryUpsert)) } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (u *SentinelAppBinaryUpsertOne) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsertOne { +func (u *SentinelAppBinaryUpsertOne) SetSentinelLibraryID(v model.InternalID) *SentinelAppBinaryUpsertOne { return u.Update(func(s *SentinelAppBinaryUpsert) { s.SetSentinelLibraryID(v) }) @@ -733,6 +785,27 @@ func (u *SentinelAppBinaryUpsertOne) UpdateCreatedAt() *SentinelAppBinaryUpsertO }) } +// SetReportSequence sets the "report_sequence" field. +func (u *SentinelAppBinaryUpsertOne) SetReportSequence(v int64) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetReportSequence(v) + }) +} + +// AddReportSequence adds v to the "report_sequence" field. +func (u *SentinelAppBinaryUpsertOne) AddReportSequence(v int64) *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.AddReportSequence(v) + }) +} + +// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertOne) UpdateReportSequence() *SentinelAppBinaryUpsertOne { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateReportSequence() + }) +} + // Exec executes the query. func (u *SentinelAppBinaryUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { @@ -749,7 +822,7 @@ func (u *SentinelAppBinaryUpsertOne) ExecX(ctx context.Context) { } // Exec executes the UPSERT query and returns the inserted/updated ID. -func (u *SentinelAppBinaryUpsertOne) ID(ctx context.Context) (id int, err error) { +func (u *SentinelAppBinaryUpsertOne) ID(ctx context.Context) (id model.InternalID, err error) { node, err := u.create.Save(ctx) if err != nil { return id, err @@ -758,7 +831,7 @@ func (u *SentinelAppBinaryUpsertOne) ID(ctx context.Context) (id int, err error) } // IDX is like ID, but panics if an error occurs. -func (u *SentinelAppBinaryUpsertOne) IDX(ctx context.Context) int { +func (u *SentinelAppBinaryUpsertOne) IDX(ctx context.Context) model.InternalID { id, err := u.ID(ctx) if err != nil { panic(err) @@ -813,9 +886,9 @@ func (sabcb *SentinelAppBinaryCreateBulk) Save(ctx context.Context) ([]*Sentinel return nil, err } mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { + if specs[i].ID.Value != nil && nodes[i].ID == 0 { id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) + nodes[i].ID = model.InternalID(id) } mutation.done = true return nodes[i], nil @@ -903,10 +976,20 @@ type SentinelAppBinaryUpsertBulk struct { // client.SentinelAppBinary.Create(). // OnConflict( // sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(sentinelappbinary.FieldID) +// }), // ). // Exec(ctx) func (u *SentinelAppBinaryUpsertBulk) UpdateNewValues() *SentinelAppBinaryUpsertBulk { 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(sentinelappbinary.FieldID) + } + } + })) return u } @@ -938,7 +1021,7 @@ func (u *SentinelAppBinaryUpsertBulk) Update(set func(*SentinelAppBinaryUpsert)) } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (u *SentinelAppBinaryUpsertBulk) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsertBulk { +func (u *SentinelAppBinaryUpsertBulk) SetSentinelLibraryID(v model.InternalID) *SentinelAppBinaryUpsertBulk { return u.Update(func(s *SentinelAppBinaryUpsert) { s.SetSentinelLibraryID(v) }) @@ -1112,6 +1195,27 @@ func (u *SentinelAppBinaryUpsertBulk) UpdateCreatedAt() *SentinelAppBinaryUpsert }) } +// SetReportSequence sets the "report_sequence" field. +func (u *SentinelAppBinaryUpsertBulk) SetReportSequence(v int64) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.SetReportSequence(v) + }) +} + +// AddReportSequence adds v to the "report_sequence" field. +func (u *SentinelAppBinaryUpsertBulk) AddReportSequence(v int64) *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.AddReportSequence(v) + }) +} + +// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. +func (u *SentinelAppBinaryUpsertBulk) UpdateReportSequence() *SentinelAppBinaryUpsertBulk { + return u.Update(func(s *SentinelAppBinaryUpsert) { + s.UpdateReportSequence() + }) +} + // Exec executes the query. func (u *SentinelAppBinaryUpsertBulk) Exec(ctx context.Context) error { if u.create.err != nil { diff --git a/internal/data/internal/ent/sentinelappbinary_delete.go b/internal/data/internal/ent/sentinelappbinary_delete.go index 34ba2f90..b5b67825 100644 --- a/internal/data/internal/ent/sentinelappbinary_delete.go +++ b/internal/data/internal/ent/sentinelappbinary_delete.go @@ -40,7 +40,7 @@ func (sabd *SentinelAppBinaryDelete) ExecX(ctx context.Context) int { } func (sabd *SentinelAppBinaryDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(sentinelappbinary.Table, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt)) + _spec := sqlgraph.NewDeleteSpec(sentinelappbinary.Table, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64)) if ps := sabd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/internal/data/internal/ent/sentinelappbinary_query.go b/internal/data/internal/ent/sentinelappbinary_query.go index 14486346..f76c693e 100644 --- a/internal/data/internal/ent/sentinelappbinary_query.go +++ b/internal/data/internal/ent/sentinelappbinary_query.go @@ -16,6 +16,7 @@ import ( "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/sentinellibrary" + "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryQuery is the builder for querying SentinelAppBinary entities. @@ -131,8 +132,8 @@ func (sabq *SentinelAppBinaryQuery) FirstX(ctx context.Context) *SentinelAppBina // 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 +func (sabq *SentinelAppBinaryQuery) FirstID(ctx context.Context) (id model.InternalID, err error) { + var ids []model.InternalID if ids, err = sabq.Limit(1).IDs(setContextOp(ctx, sabq.ctx, ent.OpQueryFirstID)); err != nil { return } @@ -144,7 +145,7 @@ func (sabq *SentinelAppBinaryQuery) FirstID(ctx context.Context) (id int, err er } // FirstIDX is like FirstID, but panics if an error occurs. -func (sabq *SentinelAppBinaryQuery) FirstIDX(ctx context.Context) int { +func (sabq *SentinelAppBinaryQuery) FirstIDX(ctx context.Context) model.InternalID { id, err := sabq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -182,8 +183,8 @@ func (sabq *SentinelAppBinaryQuery) OnlyX(ctx context.Context) *SentinelAppBinar // 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 +func (sabq *SentinelAppBinaryQuery) OnlyID(ctx context.Context) (id model.InternalID, err error) { + var ids []model.InternalID if ids, err = sabq.Limit(2).IDs(setContextOp(ctx, sabq.ctx, ent.OpQueryOnlyID)); err != nil { return } @@ -199,7 +200,7 @@ func (sabq *SentinelAppBinaryQuery) OnlyID(ctx context.Context) (id int, err err } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (sabq *SentinelAppBinaryQuery) OnlyIDX(ctx context.Context) int { +func (sabq *SentinelAppBinaryQuery) OnlyIDX(ctx context.Context) model.InternalID { id, err := sabq.OnlyID(ctx) if err != nil { panic(err) @@ -227,7 +228,7 @@ func (sabq *SentinelAppBinaryQuery) AllX(ctx context.Context) []*SentinelAppBina } // IDs executes the query and returns a list of SentinelAppBinary IDs. -func (sabq *SentinelAppBinaryQuery) IDs(ctx context.Context) (ids []int, err error) { +func (sabq *SentinelAppBinaryQuery) IDs(ctx context.Context) (ids []model.InternalID, err error) { if sabq.ctx.Unique == nil && sabq.path != nil { sabq.Unique(true) } @@ -239,7 +240,7 @@ func (sabq *SentinelAppBinaryQuery) IDs(ctx context.Context) (ids []int, err err } // IDsX is like IDs, but panics if an error occurs. -func (sabq *SentinelAppBinaryQuery) IDsX(ctx context.Context) []int { +func (sabq *SentinelAppBinaryQuery) IDsX(ctx context.Context) []model.InternalID { ids, err := sabq.IDs(ctx) if err != nil { panic(err) @@ -335,7 +336,7 @@ func (sabq *SentinelAppBinaryQuery) WithSentinelAppBinaryFile(opts ...func(*Sent // Example: // // var v []struct { -// SentinelLibraryID int `json:"sentinel_library_id,omitempty"` +// SentinelLibraryID model.InternalID `json:"sentinel_library_id,omitempty"` // Count int `json:"count,omitempty"` // } // @@ -358,7 +359,7 @@ func (sabq *SentinelAppBinaryQuery) GroupBy(field string, fields ...string) *Sen // Example: // // var v []struct { -// SentinelLibraryID int `json:"sentinel_library_id,omitempty"` +// SentinelLibraryID model.InternalID `json:"sentinel_library_id,omitempty"` // } // // client.SentinelAppBinary.Query(). @@ -449,8 +450,8 @@ func (sabq *SentinelAppBinaryQuery) sqlAll(ctx context.Context, hooks ...queryHo } func (sabq *SentinelAppBinaryQuery) loadSentinelLibrary(ctx context.Context, query *SentinelLibraryQuery, nodes []*SentinelAppBinary, init func(*SentinelAppBinary), assign func(*SentinelAppBinary, *SentinelLibrary)) error { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*SentinelAppBinary) + ids := make([]model.InternalID, 0, len(nodes)) + nodeids := make(map[model.InternalID][]*SentinelAppBinary) for i := range nodes { fk := nodes[i].SentinelLibraryID if _, ok := nodeids[fk]; !ok { @@ -479,7 +480,7 @@ func (sabq *SentinelAppBinaryQuery) loadSentinelLibrary(ctx context.Context, que } func (sabq *SentinelAppBinaryQuery) loadSentinelAppBinaryFile(ctx context.Context, query *SentinelAppBinaryFileQuery, nodes []*SentinelAppBinary, init func(*SentinelAppBinary), assign func(*SentinelAppBinary, *SentinelAppBinaryFile)) error { fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*SentinelAppBinary) + nodeids := make(map[model.InternalID]*SentinelAppBinary) for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] @@ -518,7 +519,7 @@ func (sabq *SentinelAppBinaryQuery) sqlCount(ctx context.Context) (int, error) { } func (sabq *SentinelAppBinaryQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt)) + _spec := sqlgraph.NewQuerySpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64)) _spec.From = sabq.sql if unique := sabq.ctx.Unique; unique != nil { _spec.Unique = *unique diff --git a/internal/data/internal/ent/sentinelappbinary_update.go b/internal/data/internal/ent/sentinelappbinary_update.go index 150dc467..9c2f91c5 100644 --- a/internal/data/internal/ent/sentinelappbinary_update.go +++ b/internal/data/internal/ent/sentinelappbinary_update.go @@ -15,6 +15,7 @@ import ( "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/sentinellibrary" + "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryUpdate is the builder for updating SentinelAppBinary entities. @@ -31,15 +32,15 @@ func (sabu *SentinelAppBinaryUpdate) Where(ps ...predicate.SentinelAppBinary) *S } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (sabu *SentinelAppBinaryUpdate) SetSentinelLibraryID(i int) *SentinelAppBinaryUpdate { - sabu.mutation.SetSentinelLibraryID(i) +func (sabu *SentinelAppBinaryUpdate) SetSentinelLibraryID(mi model.InternalID) *SentinelAppBinaryUpdate { + sabu.mutation.SetSentinelLibraryID(mi) return sabu } // SetNillableSentinelLibraryID sets the "sentinel_library_id" field if the given value is not nil. -func (sabu *SentinelAppBinaryUpdate) SetNillableSentinelLibraryID(i *int) *SentinelAppBinaryUpdate { - if i != nil { - sabu.SetSentinelLibraryID(*i) +func (sabu *SentinelAppBinaryUpdate) SetNillableSentinelLibraryID(mi *model.InternalID) *SentinelAppBinaryUpdate { + if mi != nil { + sabu.SetSentinelLibraryID(*mi) } return sabu } @@ -193,20 +194,41 @@ func (sabu *SentinelAppBinaryUpdate) SetNillableCreatedAt(t *time.Time) *Sentine return sabu } +// SetReportSequence sets the "report_sequence" field. +func (sabu *SentinelAppBinaryUpdate) SetReportSequence(i int64) *SentinelAppBinaryUpdate { + sabu.mutation.ResetReportSequence() + sabu.mutation.SetReportSequence(i) + return sabu +} + +// SetNillableReportSequence sets the "report_sequence" field if the given value is not nil. +func (sabu *SentinelAppBinaryUpdate) SetNillableReportSequence(i *int64) *SentinelAppBinaryUpdate { + if i != nil { + sabu.SetReportSequence(*i) + } + return sabu +} + +// AddReportSequence adds i to the "report_sequence" field. +func (sabu *SentinelAppBinaryUpdate) AddReportSequence(i int64) *SentinelAppBinaryUpdate { + sabu.mutation.AddReportSequence(i) + return sabu +} + // SetSentinelLibrary sets the "sentinel_library" edge to the SentinelLibrary entity. func (sabu *SentinelAppBinaryUpdate) SetSentinelLibrary(s *SentinelLibrary) *SentinelAppBinaryUpdate { return sabu.SetSentinelLibraryID(s.ID) } // AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (sabu *SentinelAppBinaryUpdate) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdate { +func (sabu *SentinelAppBinaryUpdate) AddSentinelAppBinaryFileIDs(ids ...model.InternalID) *SentinelAppBinaryUpdate { sabu.mutation.AddSentinelAppBinaryFileIDs(ids...) return sabu } // AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. func (sabu *SentinelAppBinaryUpdate) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdate { - ids := make([]int, len(s)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -231,14 +253,14 @@ func (sabu *SentinelAppBinaryUpdate) ClearSentinelAppBinaryFile() *SentinelAppBi } // RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to SentinelAppBinaryFile entities by IDs. -func (sabu *SentinelAppBinaryUpdate) RemoveSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdate { +func (sabu *SentinelAppBinaryUpdate) RemoveSentinelAppBinaryFileIDs(ids ...model.InternalID) *SentinelAppBinaryUpdate { sabu.mutation.RemoveSentinelAppBinaryFileIDs(ids...) return sabu } // RemoveSentinelAppBinaryFile removes "sentinel_app_binary_file" edges to SentinelAppBinaryFile entities. func (sabu *SentinelAppBinaryUpdate) RemoveSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdate { - ids := make([]int, len(s)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -293,7 +315,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er if err := sabu.check(); err != nil { return n, err } - _spec := sqlgraph.NewUpdateSpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt)) + _spec := sqlgraph.NewUpdateSpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64)) if ps := sabu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -343,6 +365,12 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er if value, ok := sabu.mutation.CreatedAt(); ok { _spec.SetField(sentinelappbinary.FieldCreatedAt, field.TypeTime, value) } + if value, ok := sabu.mutation.ReportSequence(); ok { + _spec.SetField(sentinelappbinary.FieldReportSequence, field.TypeInt64, value) + } + if value, ok := sabu.mutation.AddedReportSequence(); ok { + _spec.AddField(sentinelappbinary.FieldReportSequence, field.TypeInt64, value) + } if sabu.mutation.SentinelLibraryCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -351,7 +379,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er Columns: []string{sentinelappbinary.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -364,7 +392,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er Columns: []string{sentinelappbinary.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -380,7 +408,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -393,7 +421,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -409,7 +437,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -438,15 +466,15 @@ type SentinelAppBinaryUpdateOne struct { } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelLibraryID(i int) *SentinelAppBinaryUpdateOne { - sabuo.mutation.SetSentinelLibraryID(i) +func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelLibraryID(mi model.InternalID) *SentinelAppBinaryUpdateOne { + sabuo.mutation.SetSentinelLibraryID(mi) return sabuo } // SetNillableSentinelLibraryID sets the "sentinel_library_id" field if the given value is not nil. -func (sabuo *SentinelAppBinaryUpdateOne) SetNillableSentinelLibraryID(i *int) *SentinelAppBinaryUpdateOne { - if i != nil { - sabuo.SetSentinelLibraryID(*i) +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableSentinelLibraryID(mi *model.InternalID) *SentinelAppBinaryUpdateOne { + if mi != nil { + sabuo.SetSentinelLibraryID(*mi) } return sabuo } @@ -600,20 +628,41 @@ func (sabuo *SentinelAppBinaryUpdateOne) SetNillableCreatedAt(t *time.Time) *Sen return sabuo } +// SetReportSequence sets the "report_sequence" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetReportSequence(i int64) *SentinelAppBinaryUpdateOne { + sabuo.mutation.ResetReportSequence() + sabuo.mutation.SetReportSequence(i) + return sabuo +} + +// SetNillableReportSequence sets the "report_sequence" field if the given value is not nil. +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableReportSequence(i *int64) *SentinelAppBinaryUpdateOne { + if i != nil { + sabuo.SetReportSequence(*i) + } + return sabuo +} + +// AddReportSequence adds i to the "report_sequence" field. +func (sabuo *SentinelAppBinaryUpdateOne) AddReportSequence(i int64) *SentinelAppBinaryUpdateOne { + sabuo.mutation.AddReportSequence(i) + return sabuo +} + // SetSentinelLibrary sets the "sentinel_library" edge to the SentinelLibrary entity. func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelLibrary(s *SentinelLibrary) *SentinelAppBinaryUpdateOne { return sabuo.SetSentinelLibraryID(s.ID) } // AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdateOne { +func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelAppBinaryFileIDs(ids ...model.InternalID) *SentinelAppBinaryUpdateOne { sabuo.mutation.AddSentinelAppBinaryFileIDs(ids...) return sabuo } // AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdateOne { - ids := make([]int, len(s)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -638,14 +687,14 @@ func (sabuo *SentinelAppBinaryUpdateOne) ClearSentinelAppBinaryFile() *SentinelA } // RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to SentinelAppBinaryFile entities by IDs. -func (sabuo *SentinelAppBinaryUpdateOne) RemoveSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdateOne { +func (sabuo *SentinelAppBinaryUpdateOne) RemoveSentinelAppBinaryFileIDs(ids ...model.InternalID) *SentinelAppBinaryUpdateOne { sabuo.mutation.RemoveSentinelAppBinaryFileIDs(ids...) return sabuo } // RemoveSentinelAppBinaryFile removes "sentinel_app_binary_file" edges to SentinelAppBinaryFile entities. func (sabuo *SentinelAppBinaryUpdateOne) RemoveSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdateOne { - ids := make([]int, len(s)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -713,7 +762,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se if err := sabuo.check(); err != nil { return _node, err } - _spec := sqlgraph.NewUpdateSpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt)) + _spec := sqlgraph.NewUpdateSpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64)) id, ok := sabuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SentinelAppBinary.id" for update`)} @@ -780,6 +829,12 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se if value, ok := sabuo.mutation.CreatedAt(); ok { _spec.SetField(sentinelappbinary.FieldCreatedAt, field.TypeTime, value) } + if value, ok := sabuo.mutation.ReportSequence(); ok { + _spec.SetField(sentinelappbinary.FieldReportSequence, field.TypeInt64, value) + } + if value, ok := sabuo.mutation.AddedReportSequence(); ok { + _spec.AddField(sentinelappbinary.FieldReportSequence, field.TypeInt64, value) + } if sabuo.mutation.SentinelLibraryCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -788,7 +843,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se Columns: []string{sentinelappbinary.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -801,7 +856,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se Columns: []string{sentinelappbinary.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -817,7 +872,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -830,7 +885,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -846,7 +901,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), }, } for _, k := range nodes { diff --git a/internal/data/internal/ent/sentinelappbinaryfile.go b/internal/data/internal/ent/sentinelappbinaryfile.go index 490e770f..853cbee0 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile.go +++ b/internal/data/internal/ent/sentinelappbinaryfile.go @@ -11,15 +11,16 @@ import ( "entgo.io/ent/dialect/sql" "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" "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"` + ID model.InternalID `json:"id,omitempty"` // SentinelAppBinaryID holds the value of the "sentinel_app_binary_id" field. - SentinelAppBinaryID int `json:"sentinel_app_binary_id,omitempty"` + SentinelAppBinaryID model.InternalID `json:"sentinel_app_binary_id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` // SizeBytes holds the value of the "size_bytes" field. @@ -89,16 +90,16 @@ func (sabf *SentinelAppBinaryFile) assignValues(columns []string, values []any) 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) + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value.Valid { + sabf.ID = model.InternalID(value.Int64) } - sabf.ID = int(value.Int64) case sentinelappbinaryfile.FieldSentinelAppBinaryID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field sentinel_app_binary_id", values[i]) } else if value.Valid { - sabf.SentinelAppBinaryID = int(value.Int64) + sabf.SentinelAppBinaryID = model.InternalID(value.Int64) } case sentinelappbinaryfile.FieldName: if value, ok := values[i].(*sql.NullString); !ok { diff --git a/internal/data/internal/ent/sentinelappbinaryfile/where.go b/internal/data/internal/ent/sentinelappbinaryfile/where.go index f55b839f..03bb1842 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile/where.go +++ b/internal/data/internal/ent/sentinelappbinaryfile/where.go @@ -8,56 +8,58 @@ import ( "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.SentinelAppBinaryFile { +func ID(id model.InternalID) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.SentinelAppBinaryFile { +func IDEQ(id model.InternalID) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.SentinelAppBinaryFile { +func IDNEQ(id model.InternalID) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.SentinelAppBinaryFile { +func IDIn(ids ...model.InternalID) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.SentinelAppBinaryFile { +func IDNotIn(ids ...model.InternalID) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.SentinelAppBinaryFile { +func IDGT(id model.InternalID) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.SentinelAppBinaryFile { +func IDGTE(id model.InternalID) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.SentinelAppBinaryFile { +func IDLT(id model.InternalID) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.SentinelAppBinaryFile { +func IDLTE(id model.InternalID) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldID, id)) } // SentinelAppBinaryID applies equality check predicate on the "sentinel_app_binary_id" field. It's identical to SentinelAppBinaryIDEQ. -func SentinelAppBinaryID(v int) predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, v)) +func SentinelAppBinaryID(v model.InternalID) predicate.SentinelAppBinaryFile { + vc := int64(v) + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, vc)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. @@ -96,23 +98,33 @@ func CreatedAt(v time.Time) predicate.SentinelAppBinaryFile { } // SentinelAppBinaryIDEQ applies the EQ predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDEQ(v int) predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, v)) +func SentinelAppBinaryIDEQ(v model.InternalID) predicate.SentinelAppBinaryFile { + vc := int64(v) + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, vc)) } // SentinelAppBinaryIDNEQ applies the NEQ predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDNEQ(v int) predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldSentinelAppBinaryID, v)) +func SentinelAppBinaryIDNEQ(v model.InternalID) predicate.SentinelAppBinaryFile { + vc := int64(v) + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldSentinelAppBinaryID, vc)) } // SentinelAppBinaryIDIn applies the In predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDIn(vs ...int) predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldSentinelAppBinaryID, vs...)) +func SentinelAppBinaryIDIn(vs ...model.InternalID) predicate.SentinelAppBinaryFile { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldSentinelAppBinaryID, v...)) } // SentinelAppBinaryIDNotIn applies the NotIn predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDNotIn(vs ...int) predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldSentinelAppBinaryID, vs...)) +func SentinelAppBinaryIDNotIn(vs ...model.InternalID) predicate.SentinelAppBinaryFile { + v := make([]any, len(vs)) + for i := range v { + v[i] = int64(vs[i]) + } + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldSentinelAppBinaryID, v...)) } // NameEQ applies the EQ predicate on the "name" field. diff --git a/internal/data/internal/ent/sentinelappbinaryfile_create.go b/internal/data/internal/ent/sentinelappbinaryfile_create.go index 20650a8f..3e2e0e1d 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile_create.go +++ b/internal/data/internal/ent/sentinelappbinaryfile_create.go @@ -13,6 +13,7 @@ import ( "entgo.io/ent/schema/field" "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryFileCreate is the builder for creating a SentinelAppBinaryFile entity. @@ -24,8 +25,8 @@ type SentinelAppBinaryFileCreate struct { } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (sabfc *SentinelAppBinaryFileCreate) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileCreate { - sabfc.mutation.SetSentinelAppBinaryID(i) +func (sabfc *SentinelAppBinaryFileCreate) SetSentinelAppBinaryID(mi model.InternalID) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetSentinelAppBinaryID(mi) return sabfc } @@ -95,6 +96,12 @@ func (sabfc *SentinelAppBinaryFileCreate) SetNillableCreatedAt(t *time.Time) *Se return sabfc } +// SetID sets the "id" field. +func (sabfc *SentinelAppBinaryFileCreate) SetID(mi model.InternalID) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetID(mi) + return sabfc +} + // SetSentinelAppBinary sets the "sentinel_app_binary" edge to the SentinelAppBinary entity. func (sabfc *SentinelAppBinaryFileCreate) SetSentinelAppBinary(s *SentinelAppBinary) *SentinelAppBinaryFileCreate { return sabfc.SetSentinelAppBinaryID(s.ID) @@ -185,8 +192,10 @@ func (sabfc *SentinelAppBinaryFileCreate) sqlSave(ctx context.Context) (*Sentine } return nil, err } - id := _spec.ID.Value.(int64) - _node.ID = int(id) + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = model.InternalID(id) + } sabfc.mutation.id = &_node.ID sabfc.mutation.done = true return _node, nil @@ -195,9 +204,13 @@ func (sabfc *SentinelAppBinaryFileCreate) sqlSave(ctx context.Context) (*Sentine 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 = sqlgraph.NewCreateSpec(sentinelappbinaryfile.Table, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64)) ) _spec.OnConflict = sabfc.conflict + if id, ok := sabfc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } if value, ok := sabfc.mutation.Name(); ok { _spec.SetField(sentinelappbinaryfile.FieldName, field.TypeString, value) _node.Name = value @@ -234,7 +247,7 @@ func (sabfc *SentinelAppBinaryFileCreate) createSpec() (*SentinelAppBinaryFile, Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -296,7 +309,7 @@ type ( ) // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (u *SentinelAppBinaryFileUpsert) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsert { +func (u *SentinelAppBinaryFileUpsert) SetSentinelAppBinaryID(v model.InternalID) *SentinelAppBinaryFileUpsert { u.Set(sentinelappbinaryfile.FieldSentinelAppBinaryID, v) return u } @@ -403,16 +416,24 @@ func (u *SentinelAppBinaryFileUpsert) UpdateCreatedAt() *SentinelAppBinaryFileUp return u } -// UpdateNewValues updates the mutable fields using the new values that were set on create. +// 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.SentinelAppBinaryFile.Create(). // OnConflict( // sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(sentinelappbinaryfile.FieldID) +// }), // ). // Exec(ctx) func (u *SentinelAppBinaryFileUpsertOne) UpdateNewValues() *SentinelAppBinaryFileUpsertOne { 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(sentinelappbinaryfile.FieldID) + } + })) return u } @@ -444,7 +465,7 @@ func (u *SentinelAppBinaryFileUpsertOne) Update(set func(*SentinelAppBinaryFileU } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (u *SentinelAppBinaryFileUpsertOne) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsertOne { +func (u *SentinelAppBinaryFileUpsertOne) SetSentinelAppBinaryID(v model.InternalID) *SentinelAppBinaryFileUpsertOne { return u.Update(func(s *SentinelAppBinaryFileUpsert) { s.SetSentinelAppBinaryID(v) }) @@ -585,7 +606,7 @@ func (u *SentinelAppBinaryFileUpsertOne) ExecX(ctx context.Context) { } // Exec executes the UPSERT query and returns the inserted/updated ID. -func (u *SentinelAppBinaryFileUpsertOne) ID(ctx context.Context) (id int, err error) { +func (u *SentinelAppBinaryFileUpsertOne) ID(ctx context.Context) (id model.InternalID, err error) { node, err := u.create.Save(ctx) if err != nil { return id, err @@ -594,7 +615,7 @@ func (u *SentinelAppBinaryFileUpsertOne) ID(ctx context.Context) (id int, err er } // IDX is like ID, but panics if an error occurs. -func (u *SentinelAppBinaryFileUpsertOne) IDX(ctx context.Context) int { +func (u *SentinelAppBinaryFileUpsertOne) IDX(ctx context.Context) model.InternalID { id, err := u.ID(ctx) if err != nil { panic(err) @@ -649,9 +670,9 @@ func (sabfcb *SentinelAppBinaryFileCreateBulk) Save(ctx context.Context) ([]*Sen return nil, err } mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { + if specs[i].ID.Value != nil && nodes[i].ID == 0 { id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) + nodes[i].ID = model.InternalID(id) } mutation.done = true return nodes[i], nil @@ -739,10 +760,20 @@ type SentinelAppBinaryFileUpsertBulk struct { // client.SentinelAppBinaryFile.Create(). // OnConflict( // sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(sentinelappbinaryfile.FieldID) +// }), // ). // Exec(ctx) func (u *SentinelAppBinaryFileUpsertBulk) UpdateNewValues() *SentinelAppBinaryFileUpsertBulk { 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(sentinelappbinaryfile.FieldID) + } + } + })) return u } @@ -774,7 +805,7 @@ func (u *SentinelAppBinaryFileUpsertBulk) Update(set func(*SentinelAppBinaryFile } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (u *SentinelAppBinaryFileUpsertBulk) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsertBulk { +func (u *SentinelAppBinaryFileUpsertBulk) SetSentinelAppBinaryID(v model.InternalID) *SentinelAppBinaryFileUpsertBulk { return u.Update(func(s *SentinelAppBinaryFileUpsert) { s.SetSentinelAppBinaryID(v) }) diff --git a/internal/data/internal/ent/sentinelappbinaryfile_delete.go b/internal/data/internal/ent/sentinelappbinaryfile_delete.go index 78472628..8365a3a4 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile_delete.go +++ b/internal/data/internal/ent/sentinelappbinaryfile_delete.go @@ -40,7 +40,7 @@ func (sabfd *SentinelAppBinaryFileDelete) ExecX(ctx context.Context) int { } func (sabfd *SentinelAppBinaryFileDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(sentinelappbinaryfile.Table, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt)) + _spec := sqlgraph.NewDeleteSpec(sentinelappbinaryfile.Table, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64)) if ps := sabfd.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/internal/data/internal/ent/sentinelappbinaryfile_query.go b/internal/data/internal/ent/sentinelappbinaryfile_query.go index 5dec5c78..321afc40 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile_query.go +++ b/internal/data/internal/ent/sentinelappbinaryfile_query.go @@ -14,6 +14,7 @@ import ( "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/model" ) // SentinelAppBinaryFileQuery is the builder for querying SentinelAppBinaryFile entities. @@ -106,8 +107,8 @@ func (sabfq *SentinelAppBinaryFileQuery) FirstX(ctx context.Context) *SentinelAp // 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 +func (sabfq *SentinelAppBinaryFileQuery) FirstID(ctx context.Context) (id model.InternalID, err error) { + var ids []model.InternalID if ids, err = sabfq.Limit(1).IDs(setContextOp(ctx, sabfq.ctx, ent.OpQueryFirstID)); err != nil { return } @@ -119,7 +120,7 @@ func (sabfq *SentinelAppBinaryFileQuery) FirstID(ctx context.Context) (id int, e } // FirstIDX is like FirstID, but panics if an error occurs. -func (sabfq *SentinelAppBinaryFileQuery) FirstIDX(ctx context.Context) int { +func (sabfq *SentinelAppBinaryFileQuery) FirstIDX(ctx context.Context) model.InternalID { id, err := sabfq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -157,8 +158,8 @@ func (sabfq *SentinelAppBinaryFileQuery) OnlyX(ctx context.Context) *SentinelApp // 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 +func (sabfq *SentinelAppBinaryFileQuery) OnlyID(ctx context.Context) (id model.InternalID, err error) { + var ids []model.InternalID if ids, err = sabfq.Limit(2).IDs(setContextOp(ctx, sabfq.ctx, ent.OpQueryOnlyID)); err != nil { return } @@ -174,7 +175,7 @@ func (sabfq *SentinelAppBinaryFileQuery) OnlyID(ctx context.Context) (id int, er } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (sabfq *SentinelAppBinaryFileQuery) OnlyIDX(ctx context.Context) int { +func (sabfq *SentinelAppBinaryFileQuery) OnlyIDX(ctx context.Context) model.InternalID { id, err := sabfq.OnlyID(ctx) if err != nil { panic(err) @@ -202,7 +203,7 @@ func (sabfq *SentinelAppBinaryFileQuery) AllX(ctx context.Context) []*SentinelAp } // IDs executes the query and returns a list of SentinelAppBinaryFile IDs. -func (sabfq *SentinelAppBinaryFileQuery) IDs(ctx context.Context) (ids []int, err error) { +func (sabfq *SentinelAppBinaryFileQuery) IDs(ctx context.Context) (ids []model.InternalID, err error) { if sabfq.ctx.Unique == nil && sabfq.path != nil { sabfq.Unique(true) } @@ -214,7 +215,7 @@ func (sabfq *SentinelAppBinaryFileQuery) IDs(ctx context.Context) (ids []int, er } // IDsX is like IDs, but panics if an error occurs. -func (sabfq *SentinelAppBinaryFileQuery) IDsX(ctx context.Context) []int { +func (sabfq *SentinelAppBinaryFileQuery) IDsX(ctx context.Context) []model.InternalID { ids, err := sabfq.IDs(ctx) if err != nil { panic(err) @@ -298,7 +299,7 @@ func (sabfq *SentinelAppBinaryFileQuery) WithSentinelAppBinary(opts ...func(*Sen // Example: // // var v []struct { -// SentinelAppBinaryID int `json:"sentinel_app_binary_id,omitempty"` +// SentinelAppBinaryID model.InternalID `json:"sentinel_app_binary_id,omitempty"` // Count int `json:"count,omitempty"` // } // @@ -321,7 +322,7 @@ func (sabfq *SentinelAppBinaryFileQuery) GroupBy(field string, fields ...string) // Example: // // var v []struct { -// SentinelAppBinaryID int `json:"sentinel_app_binary_id,omitempty"` +// SentinelAppBinaryID model.InternalID `json:"sentinel_app_binary_id,omitempty"` // } // // client.SentinelAppBinaryFile.Query(). @@ -402,8 +403,8 @@ func (sabfq *SentinelAppBinaryFileQuery) sqlAll(ctx context.Context, hooks ...qu } func (sabfq *SentinelAppBinaryFileQuery) loadSentinelAppBinary(ctx context.Context, query *SentinelAppBinaryQuery, nodes []*SentinelAppBinaryFile, init func(*SentinelAppBinaryFile), assign func(*SentinelAppBinaryFile, *SentinelAppBinary)) error { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*SentinelAppBinaryFile) + ids := make([]model.InternalID, 0, len(nodes)) + nodeids := make(map[model.InternalID][]*SentinelAppBinaryFile) for i := range nodes { fk := nodes[i].SentinelAppBinaryID if _, ok := nodeids[fk]; !ok { @@ -441,7 +442,7 @@ func (sabfq *SentinelAppBinaryFileQuery) sqlCount(ctx context.Context) (int, err } func (sabfq *SentinelAppBinaryFileQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt)) + _spec := sqlgraph.NewQuerySpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64)) _spec.From = sabfq.sql if unique := sabfq.ctx.Unique; unique != nil { _spec.Unique = *unique diff --git a/internal/data/internal/ent/sentinelappbinaryfile_update.go b/internal/data/internal/ent/sentinelappbinaryfile_update.go index 8d8b050e..d9f140a1 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile_update.go +++ b/internal/data/internal/ent/sentinelappbinaryfile_update.go @@ -14,6 +14,7 @@ import ( "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/model" ) // SentinelAppBinaryFileUpdate is the builder for updating SentinelAppBinaryFile entities. @@ -30,15 +31,15 @@ func (sabfu *SentinelAppBinaryFileUpdate) Where(ps ...predicate.SentinelAppBinar } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileUpdate { - sabfu.mutation.SetSentinelAppBinaryID(i) +func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelAppBinaryID(mi model.InternalID) *SentinelAppBinaryFileUpdate { + sabfu.mutation.SetSentinelAppBinaryID(mi) return sabfu } // SetNillableSentinelAppBinaryID sets the "sentinel_app_binary_id" field if the given value is not nil. -func (sabfu *SentinelAppBinaryFileUpdate) SetNillableSentinelAppBinaryID(i *int) *SentinelAppBinaryFileUpdate { - if i != nil { - sabfu.SetSentinelAppBinaryID(*i) +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableSentinelAppBinaryID(mi *model.InternalID) *SentinelAppBinaryFileUpdate { + if mi != nil { + sabfu.SetSentinelAppBinaryID(*mi) } return sabfu } @@ -202,7 +203,7 @@ func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, e if err := sabfu.check(); err != nil { return n, err } - _spec := sqlgraph.NewUpdateSpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt)) + _spec := sqlgraph.NewUpdateSpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64)) if ps := sabfu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -245,7 +246,7 @@ func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, e Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -258,7 +259,7 @@ func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, e Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -287,15 +288,15 @@ type SentinelAppBinaryFileUpdateOne struct { } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileUpdateOne { - sabfuo.mutation.SetSentinelAppBinaryID(i) +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelAppBinaryID(mi model.InternalID) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.SetSentinelAppBinaryID(mi) return sabfuo } // SetNillableSentinelAppBinaryID sets the "sentinel_app_binary_id" field if the given value is not nil. -func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableSentinelAppBinaryID(i *int) *SentinelAppBinaryFileUpdateOne { - if i != nil { - sabfuo.SetSentinelAppBinaryID(*i) +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableSentinelAppBinaryID(mi *model.InternalID) *SentinelAppBinaryFileUpdateOne { + if mi != nil { + sabfuo.SetSentinelAppBinaryID(*mi) } return sabfuo } @@ -472,7 +473,7 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_nod if err := sabfuo.check(); err != nil { return _node, err } - _spec := sqlgraph.NewUpdateSpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt)) + _spec := sqlgraph.NewUpdateSpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64)) id, ok := sabfuo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SentinelAppBinaryFile.id" for update`)} @@ -532,7 +533,7 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_nod Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -545,7 +546,7 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_nod Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } for _, k := range nodes { diff --git a/internal/data/internal/ent/sentinelinfo.go b/internal/data/internal/ent/sentinelinfo.go index dc79e8b7..b983203d 100644 --- a/internal/data/internal/ent/sentinelinfo.go +++ b/internal/data/internal/ent/sentinelinfo.go @@ -18,9 +18,7 @@ import ( type SentinelInfo struct { config `json:"-"` // ID of the ent. - ID int `json:"id,omitempty"` - // UserID holds the value of the "user_id" field. - UserID model.InternalID `json:"user_id,omitempty"` + 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. @@ -64,7 +62,7 @@ func (*SentinelInfo) scanValues(columns []string) ([]any, error) { switch columns[i] { case sentinelinfo.FieldAlternativeUrls: values[i] = new([]byte) - case sentinelinfo.FieldID, sentinelinfo.FieldUserID: + case sentinelinfo.FieldID: values[i] = new(sql.NullInt64) case sentinelinfo.FieldURL, sentinelinfo.FieldGetTokenPath, sentinelinfo.FieldDownloadFileBasePath: values[i] = new(sql.NullString) @@ -86,16 +84,10 @@ func (si *SentinelInfo) assignValues(columns []string, values []any) error { for i := range columns { switch columns[i] { case sentinelinfo.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - si.ID = int(value.Int64) - case sentinelinfo.FieldUserID: if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field user_id", values[i]) + return fmt.Errorf("unexpected type %T for field id", values[i]) } else if value.Valid { - si.UserID = model.InternalID(value.Int64) + si.ID = model.InternalID(value.Int64) } case sentinelinfo.FieldURL: if value, ok := values[i].(*sql.NullString); !ok { @@ -176,9 +168,6 @@ func (si *SentinelInfo) String() string { var builder strings.Builder builder.WriteString("SentinelInfo(") builder.WriteString(fmt.Sprintf("id=%v, ", si.ID)) - builder.WriteString("user_id=") - builder.WriteString(fmt.Sprintf("%v", si.UserID)) - builder.WriteString(", ") builder.WriteString("url=") builder.WriteString(si.URL) builder.WriteString(", ") diff --git a/internal/data/internal/ent/sentinelinfo/sentinelinfo.go b/internal/data/internal/ent/sentinelinfo/sentinelinfo.go index 8e0f39c0..9e3c2d83 100644 --- a/internal/data/internal/ent/sentinelinfo/sentinelinfo.go +++ b/internal/data/internal/ent/sentinelinfo/sentinelinfo.go @@ -14,8 +14,6 @@ const ( Label = "sentinel_info" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldUserID holds the string denoting the user_id field in the database. - FieldUserID = "user_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. @@ -44,7 +42,6 @@ const ( // Columns holds all SQL columns for sentinelinfo fields. var Columns = []string{ FieldID, - FieldUserID, FieldURL, FieldAlternativeUrls, FieldGetTokenPath, @@ -80,11 +77,6 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } -// ByUserID orders the results by the user_id field. -func ByUserID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldUserID, opts...).ToFunc() -} - // ByURL orders the results by the url field. func ByURL(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldURL, opts...).ToFunc() diff --git a/internal/data/internal/ent/sentinelinfo/where.go b/internal/data/internal/ent/sentinelinfo/where.go index a4f99ef0..acfe106c 100644 --- a/internal/data/internal/ent/sentinelinfo/where.go +++ b/internal/data/internal/ent/sentinelinfo/where.go @@ -12,56 +12,50 @@ import ( ) // ID filters vertices based on their ID field. -func ID(id int) predicate.SentinelInfo { +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 int) predicate.SentinelInfo { +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 int) predicate.SentinelInfo { +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 ...int) predicate.SentinelInfo { +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 ...int) predicate.SentinelInfo { +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 int) predicate.SentinelInfo { +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 int) predicate.SentinelInfo { +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 int) predicate.SentinelInfo { +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 int) predicate.SentinelInfo { +func IDLTE(id model.InternalID) predicate.SentinelInfo { return predicate.SentinelInfo(sql.FieldLTE(FieldID, id)) } -// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ. -func UserID(v model.InternalID) predicate.SentinelInfo { - vc := int64(v) - return predicate.SentinelInfo(sql.FieldEQ(FieldUserID, vc)) -} - // 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)) @@ -87,60 +81,6 @@ func CreatedAt(v time.Time) predicate.SentinelInfo { return predicate.SentinelInfo(sql.FieldEQ(FieldCreatedAt, v)) } -// UserIDEQ applies the EQ predicate on the "user_id" field. -func UserIDEQ(v model.InternalID) predicate.SentinelInfo { - vc := int64(v) - return predicate.SentinelInfo(sql.FieldEQ(FieldUserID, vc)) -} - -// UserIDNEQ applies the NEQ predicate on the "user_id" field. -func UserIDNEQ(v model.InternalID) predicate.SentinelInfo { - vc := int64(v) - return predicate.SentinelInfo(sql.FieldNEQ(FieldUserID, vc)) -} - -// UserIDIn applies the In predicate on the "user_id" field. -func UserIDIn(vs ...model.InternalID) predicate.SentinelInfo { - v := make([]any, len(vs)) - for i := range v { - v[i] = int64(vs[i]) - } - return predicate.SentinelInfo(sql.FieldIn(FieldUserID, v...)) -} - -// UserIDNotIn applies the NotIn predicate on the "user_id" field. -func UserIDNotIn(vs ...model.InternalID) predicate.SentinelInfo { - v := make([]any, len(vs)) - for i := range v { - v[i] = int64(vs[i]) - } - return predicate.SentinelInfo(sql.FieldNotIn(FieldUserID, v...)) -} - -// UserIDGT applies the GT predicate on the "user_id" field. -func UserIDGT(v model.InternalID) predicate.SentinelInfo { - vc := int64(v) - return predicate.SentinelInfo(sql.FieldGT(FieldUserID, vc)) -} - -// UserIDGTE applies the GTE predicate on the "user_id" field. -func UserIDGTE(v model.InternalID) predicate.SentinelInfo { - vc := int64(v) - return predicate.SentinelInfo(sql.FieldGTE(FieldUserID, vc)) -} - -// UserIDLT applies the LT predicate on the "user_id" field. -func UserIDLT(v model.InternalID) predicate.SentinelInfo { - vc := int64(v) - return predicate.SentinelInfo(sql.FieldLT(FieldUserID, vc)) -} - -// UserIDLTE applies the LTE predicate on the "user_id" field. -func UserIDLTE(v model.InternalID) predicate.SentinelInfo { - vc := int64(v) - return predicate.SentinelInfo(sql.FieldLTE(FieldUserID, vc)) -} - // URLEQ applies the EQ predicate on the "url" field. func URLEQ(v string) predicate.SentinelInfo { return predicate.SentinelInfo(sql.FieldEQ(FieldURL, v)) diff --git a/internal/data/internal/ent/sentinelinfo_create.go b/internal/data/internal/ent/sentinelinfo_create.go index efeb0199..4681bf8f 100644 --- a/internal/data/internal/ent/sentinelinfo_create.go +++ b/internal/data/internal/ent/sentinelinfo_create.go @@ -24,12 +24,6 @@ type SentinelInfoCreate struct { conflict []sql.ConflictOption } -// SetUserID sets the "user_id" field. -func (sic *SentinelInfoCreate) SetUserID(mi model.InternalID) *SentinelInfoCreate { - sic.mutation.SetUserID(mi) - return sic -} - // SetURL sets the "url" field. func (sic *SentinelInfoCreate) SetURL(s string) *SentinelInfoCreate { sic.mutation.SetURL(s) @@ -90,15 +84,21 @@ func (sic *SentinelInfoCreate) SetNillableCreatedAt(t *time.Time) *SentinelInfoC 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 { +func (sic *SentinelInfoCreate) AddSentinelLibraryIDs(ids ...model.InternalID) *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)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -152,9 +152,6 @@ func (sic *SentinelInfoCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (sic *SentinelInfoCreate) check() error { - if _, ok := sic.mutation.UserID(); !ok { - return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "SentinelInfo.user_id"`)} - } if _, ok := sic.mutation.URL(); !ok { return &ValidationError{Name: "url", err: errors.New(`ent: missing required field "SentinelInfo.url"`)} } @@ -181,8 +178,10 @@ func (sic *SentinelInfoCreate) sqlSave(ctx context.Context) (*SentinelInfo, erro } return nil, err } - id := _spec.ID.Value.(int64) - _node.ID = int(id) + 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 @@ -191,12 +190,12 @@ func (sic *SentinelInfoCreate) sqlSave(ctx context.Context) (*SentinelInfo, erro func (sic *SentinelInfoCreate) createSpec() (*SentinelInfo, *sqlgraph.CreateSpec) { var ( _node = &SentinelInfo{config: sic.config} - _spec = sqlgraph.NewCreateSpec(sentinelinfo.Table, sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt)) + _spec = sqlgraph.NewCreateSpec(sentinelinfo.Table, sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64)) ) _spec.OnConflict = sic.conflict - if value, ok := sic.mutation.UserID(); ok { - _spec.SetField(sentinelinfo.FieldUserID, field.TypeInt64, value) - _node.UserID = value + 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) @@ -230,7 +229,7 @@ func (sic *SentinelInfoCreate) createSpec() (*SentinelInfo, *sqlgraph.CreateSpec Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -245,7 +244,7 @@ func (sic *SentinelInfoCreate) createSpec() (*SentinelInfo, *sqlgraph.CreateSpec // of the `INSERT` statement. For example: // // client.SentinelInfo.Create(). -// SetUserID(v). +// SetURL(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. @@ -254,7 +253,7 @@ func (sic *SentinelInfoCreate) createSpec() (*SentinelInfo, *sqlgraph.CreateSpec // // Override some of the fields with custom // // update values. // Update(func(u *ent.SentinelInfoUpsert) { -// SetUserID(v+v). +// SetURL(v+v). // }). // Exec(ctx) func (sic *SentinelInfoCreate) OnConflict(opts ...sql.ConflictOption) *SentinelInfoUpsertOne { @@ -290,24 +289,6 @@ type ( } ) -// SetUserID sets the "user_id" field. -func (u *SentinelInfoUpsert) SetUserID(v model.InternalID) *SentinelInfoUpsert { - u.Set(sentinelinfo.FieldUserID, v) - return u -} - -// UpdateUserID sets the "user_id" field to the value that was provided on create. -func (u *SentinelInfoUpsert) UpdateUserID() *SentinelInfoUpsert { - u.SetExcluded(sentinelinfo.FieldUserID) - return u -} - -// AddUserID adds v to the "user_id" field. -func (u *SentinelInfoUpsert) AddUserID(v model.InternalID) *SentinelInfoUpsert { - u.Add(sentinelinfo.FieldUserID, v) - return u -} - // SetURL sets the "url" field. func (u *SentinelInfoUpsert) SetURL(v string) *SentinelInfoUpsert { u.Set(sentinelinfo.FieldURL, v) @@ -392,16 +373,24 @@ func (u *SentinelInfoUpsert) UpdateCreatedAt() *SentinelInfoUpsert { return u } -// UpdateNewValues updates the mutable fields using the new values that were set on create. +// 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 } @@ -432,27 +421,6 @@ func (u *SentinelInfoUpsertOne) Update(set func(*SentinelInfoUpsert)) *SentinelI return u } -// SetUserID sets the "user_id" field. -func (u *SentinelInfoUpsertOne) SetUserID(v model.InternalID) *SentinelInfoUpsertOne { - return u.Update(func(s *SentinelInfoUpsert) { - s.SetUserID(v) - }) -} - -// AddUserID adds v to the "user_id" field. -func (u *SentinelInfoUpsertOne) AddUserID(v model.InternalID) *SentinelInfoUpsertOne { - return u.Update(func(s *SentinelInfoUpsert) { - s.AddUserID(v) - }) -} - -// UpdateUserID sets the "user_id" field to the value that was provided on create. -func (u *SentinelInfoUpsertOne) UpdateUserID() *SentinelInfoUpsertOne { - return u.Update(func(s *SentinelInfoUpsert) { - s.UpdateUserID() - }) -} - // SetURL sets the "url" field. func (u *SentinelInfoUpsertOne) SetURL(v string) *SentinelInfoUpsertOne { return u.Update(func(s *SentinelInfoUpsert) { @@ -567,7 +535,7 @@ func (u *SentinelInfoUpsertOne) ExecX(ctx context.Context) { } // Exec executes the UPSERT query and returns the inserted/updated ID. -func (u *SentinelInfoUpsertOne) ID(ctx context.Context) (id int, err error) { +func (u *SentinelInfoUpsertOne) ID(ctx context.Context) (id model.InternalID, err error) { node, err := u.create.Save(ctx) if err != nil { return id, err @@ -576,7 +544,7 @@ func (u *SentinelInfoUpsertOne) ID(ctx context.Context) (id int, err error) { } // IDX is like ID, but panics if an error occurs. -func (u *SentinelInfoUpsertOne) IDX(ctx context.Context) int { +func (u *SentinelInfoUpsertOne) IDX(ctx context.Context) model.InternalID { id, err := u.ID(ctx) if err != nil { panic(err) @@ -631,9 +599,9 @@ func (sicb *SentinelInfoCreateBulk) Save(ctx context.Context) ([]*SentinelInfo, return nil, err } mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { + if specs[i].ID.Value != nil && nodes[i].ID == 0 { id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) + nodes[i].ID = model.InternalID(id) } mutation.done = true return nodes[i], nil @@ -686,7 +654,7 @@ func (sicb *SentinelInfoCreateBulk) ExecX(ctx context.Context) { // // Override some of the fields with custom // // update values. // Update(func(u *ent.SentinelInfoUpsert) { -// SetUserID(v+v). +// SetURL(v+v). // }). // Exec(ctx) func (sicb *SentinelInfoCreateBulk) OnConflict(opts ...sql.ConflictOption) *SentinelInfoUpsertBulk { @@ -721,10 +689,20 @@ type SentinelInfoUpsertBulk struct { // 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 } @@ -755,27 +733,6 @@ func (u *SentinelInfoUpsertBulk) Update(set func(*SentinelInfoUpsert)) *Sentinel return u } -// SetUserID sets the "user_id" field. -func (u *SentinelInfoUpsertBulk) SetUserID(v model.InternalID) *SentinelInfoUpsertBulk { - return u.Update(func(s *SentinelInfoUpsert) { - s.SetUserID(v) - }) -} - -// AddUserID adds v to the "user_id" field. -func (u *SentinelInfoUpsertBulk) AddUserID(v model.InternalID) *SentinelInfoUpsertBulk { - return u.Update(func(s *SentinelInfoUpsert) { - s.AddUserID(v) - }) -} - -// UpdateUserID sets the "user_id" field to the value that was provided on create. -func (u *SentinelInfoUpsertBulk) UpdateUserID() *SentinelInfoUpsertBulk { - return u.Update(func(s *SentinelInfoUpsert) { - s.UpdateUserID() - }) -} - // SetURL sets the "url" field. func (u *SentinelInfoUpsertBulk) SetURL(v string) *SentinelInfoUpsertBulk { return u.Update(func(s *SentinelInfoUpsert) { diff --git a/internal/data/internal/ent/sentinelinfo_delete.go b/internal/data/internal/ent/sentinelinfo_delete.go index bfbe275e..7c1be856 100644 --- a/internal/data/internal/ent/sentinelinfo_delete.go +++ b/internal/data/internal/ent/sentinelinfo_delete.go @@ -40,7 +40,7 @@ func (sid *SentinelInfoDelete) ExecX(ctx context.Context) int { } func (sid *SentinelInfoDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(sentinelinfo.Table, sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt)) + _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 { diff --git a/internal/data/internal/ent/sentinelinfo_query.go b/internal/data/internal/ent/sentinelinfo_query.go index 106a8bee..6355b011 100644 --- a/internal/data/internal/ent/sentinelinfo_query.go +++ b/internal/data/internal/ent/sentinelinfo_query.go @@ -15,6 +15,7 @@ import ( "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. @@ -107,8 +108,8 @@ func (siq *SentinelInfoQuery) FirstX(ctx context.Context) *SentinelInfo { // 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 int, err error) { - var ids []int +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 } @@ -120,7 +121,7 @@ func (siq *SentinelInfoQuery) FirstID(ctx context.Context) (id int, err error) { } // FirstIDX is like FirstID, but panics if an error occurs. -func (siq *SentinelInfoQuery) FirstIDX(ctx context.Context) int { +func (siq *SentinelInfoQuery) FirstIDX(ctx context.Context) model.InternalID { id, err := siq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -158,8 +159,8 @@ func (siq *SentinelInfoQuery) OnlyX(ctx context.Context) *SentinelInfo { // 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 int, err error) { - var ids []int +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 } @@ -175,7 +176,7 @@ func (siq *SentinelInfoQuery) OnlyID(ctx context.Context) (id int, err error) { } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (siq *SentinelInfoQuery) OnlyIDX(ctx context.Context) int { +func (siq *SentinelInfoQuery) OnlyIDX(ctx context.Context) model.InternalID { id, err := siq.OnlyID(ctx) if err != nil { panic(err) @@ -203,7 +204,7 @@ func (siq *SentinelInfoQuery) AllX(ctx context.Context) []*SentinelInfo { } // IDs executes the query and returns a list of SentinelInfo IDs. -func (siq *SentinelInfoQuery) IDs(ctx context.Context) (ids []int, err error) { +func (siq *SentinelInfoQuery) IDs(ctx context.Context) (ids []model.InternalID, err error) { if siq.ctx.Unique == nil && siq.path != nil { siq.Unique(true) } @@ -215,7 +216,7 @@ func (siq *SentinelInfoQuery) IDs(ctx context.Context) (ids []int, err error) { } // IDsX is like IDs, but panics if an error occurs. -func (siq *SentinelInfoQuery) IDsX(ctx context.Context) []int { +func (siq *SentinelInfoQuery) IDsX(ctx context.Context) []model.InternalID { ids, err := siq.IDs(ctx) if err != nil { panic(err) @@ -299,12 +300,12 @@ func (siq *SentinelInfoQuery) WithSentinelLibrary(opts ...func(*SentinelLibraryQ // Example: // // var v []struct { -// UserID model.InternalID `json:"user_id,omitempty"` +// URL string `json:"url,omitempty"` // Count int `json:"count,omitempty"` // } // // client.SentinelInfo.Query(). -// GroupBy(sentinelinfo.FieldUserID). +// GroupBy(sentinelinfo.FieldURL). // Aggregate(ent.Count()). // Scan(ctx, &v) func (siq *SentinelInfoQuery) GroupBy(field string, fields ...string) *SentinelInfoGroupBy { @@ -322,11 +323,11 @@ func (siq *SentinelInfoQuery) GroupBy(field string, fields ...string) *SentinelI // Example: // // var v []struct { -// UserID model.InternalID `json:"user_id,omitempty"` +// URL string `json:"url,omitempty"` // } // // client.SentinelInfo.Query(). -// Select(sentinelinfo.FieldUserID). +// Select(sentinelinfo.FieldURL). // Scan(ctx, &v) func (siq *SentinelInfoQuery) Select(fields ...string) *SentinelInfoSelect { siq.ctx.Fields = append(siq.ctx.Fields, fields...) @@ -407,7 +408,7 @@ func (siq *SentinelInfoQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([ 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[int]*SentinelInfo) + nodeids := make(map[model.InternalID]*SentinelInfo) for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] @@ -446,7 +447,7 @@ func (siq *SentinelInfoQuery) sqlCount(ctx context.Context) (int, error) { } func (siq *SentinelInfoQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(sentinelinfo.Table, sentinelinfo.Columns, sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt)) + _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 diff --git a/internal/data/internal/ent/sentinelinfo_update.go b/internal/data/internal/ent/sentinelinfo_update.go index 735aca98..735b406b 100644 --- a/internal/data/internal/ent/sentinelinfo_update.go +++ b/internal/data/internal/ent/sentinelinfo_update.go @@ -31,27 +31,6 @@ func (siu *SentinelInfoUpdate) Where(ps ...predicate.SentinelInfo) *SentinelInfo return siu } -// SetUserID sets the "user_id" field. -func (siu *SentinelInfoUpdate) SetUserID(mi model.InternalID) *SentinelInfoUpdate { - siu.mutation.ResetUserID() - siu.mutation.SetUserID(mi) - return siu -} - -// SetNillableUserID sets the "user_id" field if the given value is not nil. -func (siu *SentinelInfoUpdate) SetNillableUserID(mi *model.InternalID) *SentinelInfoUpdate { - if mi != nil { - siu.SetUserID(*mi) - } - return siu -} - -// AddUserID adds mi to the "user_id" field. -func (siu *SentinelInfoUpdate) AddUserID(mi model.InternalID) *SentinelInfoUpdate { - siu.mutation.AddUserID(mi) - return siu -} - // SetURL sets the "url" field. func (siu *SentinelInfoUpdate) SetURL(s string) *SentinelInfoUpdate { siu.mutation.SetURL(s) @@ -139,14 +118,14 @@ func (siu *SentinelInfoUpdate) SetNillableCreatedAt(t *time.Time) *SentinelInfoU } // AddSentinelLibraryIDs adds the "sentinel_library" edge to the SentinelLibrary entity by IDs. -func (siu *SentinelInfoUpdate) AddSentinelLibraryIDs(ids ...int) *SentinelInfoUpdate { +func (siu *SentinelInfoUpdate) AddSentinelLibraryIDs(ids ...model.InternalID) *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)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -165,14 +144,14 @@ func (siu *SentinelInfoUpdate) ClearSentinelLibrary() *SentinelInfoUpdate { } // RemoveSentinelLibraryIDs removes the "sentinel_library" edge to SentinelLibrary entities by IDs. -func (siu *SentinelInfoUpdate) RemoveSentinelLibraryIDs(ids ...int) *SentinelInfoUpdate { +func (siu *SentinelInfoUpdate) RemoveSentinelLibraryIDs(ids ...model.InternalID) *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)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -216,7 +195,7 @@ func (siu *SentinelInfoUpdate) defaults() { } func (siu *SentinelInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { - _spec := sqlgraph.NewUpdateSpec(sentinelinfo.Table, sentinelinfo.Columns, sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt)) + _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 { @@ -224,12 +203,6 @@ func (siu *SentinelInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { } } } - if value, ok := siu.mutation.UserID(); ok { - _spec.SetField(sentinelinfo.FieldUserID, field.TypeInt64, value) - } - if value, ok := siu.mutation.AddedUserID(); ok { - _spec.AddField(sentinelinfo.FieldUserID, field.TypeInt64, value) - } if value, ok := siu.mutation.URL(); ok { _spec.SetField(sentinelinfo.FieldURL, field.TypeString, value) } @@ -267,7 +240,7 @@ func (siu *SentinelInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -280,7 +253,7 @@ func (siu *SentinelInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -296,7 +269,7 @@ func (siu *SentinelInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -324,27 +297,6 @@ type SentinelInfoUpdateOne struct { mutation *SentinelInfoMutation } -// SetUserID sets the "user_id" field. -func (siuo *SentinelInfoUpdateOne) SetUserID(mi model.InternalID) *SentinelInfoUpdateOne { - siuo.mutation.ResetUserID() - siuo.mutation.SetUserID(mi) - return siuo -} - -// SetNillableUserID sets the "user_id" field if the given value is not nil. -func (siuo *SentinelInfoUpdateOne) SetNillableUserID(mi *model.InternalID) *SentinelInfoUpdateOne { - if mi != nil { - siuo.SetUserID(*mi) - } - return siuo -} - -// AddUserID adds mi to the "user_id" field. -func (siuo *SentinelInfoUpdateOne) AddUserID(mi model.InternalID) *SentinelInfoUpdateOne { - siuo.mutation.AddUserID(mi) - return siuo -} - // SetURL sets the "url" field. func (siuo *SentinelInfoUpdateOne) SetURL(s string) *SentinelInfoUpdateOne { siuo.mutation.SetURL(s) @@ -432,14 +384,14 @@ func (siuo *SentinelInfoUpdateOne) SetNillableCreatedAt(t *time.Time) *SentinelI } // AddSentinelLibraryIDs adds the "sentinel_library" edge to the SentinelLibrary entity by IDs. -func (siuo *SentinelInfoUpdateOne) AddSentinelLibraryIDs(ids ...int) *SentinelInfoUpdateOne { +func (siuo *SentinelInfoUpdateOne) AddSentinelLibraryIDs(ids ...model.InternalID) *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)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -458,14 +410,14 @@ func (siuo *SentinelInfoUpdateOne) ClearSentinelLibrary() *SentinelInfoUpdateOne } // RemoveSentinelLibraryIDs removes the "sentinel_library" edge to SentinelLibrary entities by IDs. -func (siuo *SentinelInfoUpdateOne) RemoveSentinelLibraryIDs(ids ...int) *SentinelInfoUpdateOne { +func (siuo *SentinelInfoUpdateOne) RemoveSentinelLibraryIDs(ids ...model.InternalID) *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)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -522,7 +474,7 @@ func (siuo *SentinelInfoUpdateOne) defaults() { } func (siuo *SentinelInfoUpdateOne) sqlSave(ctx context.Context) (_node *SentinelInfo, err error) { - _spec := sqlgraph.NewUpdateSpec(sentinelinfo.Table, sentinelinfo.Columns, sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt)) + _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`)} @@ -547,12 +499,6 @@ func (siuo *SentinelInfoUpdateOne) sqlSave(ctx context.Context) (_node *Sentinel } } } - if value, ok := siuo.mutation.UserID(); ok { - _spec.SetField(sentinelinfo.FieldUserID, field.TypeInt64, value) - } - if value, ok := siuo.mutation.AddedUserID(); ok { - _spec.AddField(sentinelinfo.FieldUserID, field.TypeInt64, value) - } if value, ok := siuo.mutation.URL(); ok { _spec.SetField(sentinelinfo.FieldURL, field.TypeString, value) } @@ -590,7 +536,7 @@ func (siuo *SentinelInfoUpdateOne) sqlSave(ctx context.Context) (_node *Sentinel Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -603,7 +549,7 @@ func (siuo *SentinelInfoUpdateOne) sqlSave(ctx context.Context) (_node *Sentinel Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -619,7 +565,7 @@ func (siuo *SentinelInfoUpdateOne) sqlSave(ctx context.Context) (_node *Sentinel Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), }, } for _, k := range nodes { diff --git a/internal/data/internal/ent/sentinellibrary.go b/internal/data/internal/ent/sentinellibrary.go index 585b327d..647261a7 100644 --- a/internal/data/internal/ent/sentinellibrary.go +++ b/internal/data/internal/ent/sentinellibrary.go @@ -11,15 +11,16 @@ import ( "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"` + ID model.InternalID `json:"id,omitempty"` // SentinelInfoID holds the value of the "sentinel_info_id" field. - SentinelInfoID int `json:"sentinel_info_id,omitempty"` + 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. @@ -28,6 +29,8 @@ type SentinelLibrary struct { UpdatedAt time.Time `json:"updated_at,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` + // ReportSequence holds the value of the "report_sequence" field. + ReportSequence int64 `json:"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"` @@ -70,7 +73,7 @@ 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: + case sentinellibrary.FieldID, sentinellibrary.FieldSentinelInfoID, sentinellibrary.FieldReportedID, sentinellibrary.FieldReportSequence: values[i] = new(sql.NullInt64) case sentinellibrary.FieldDownloadBasePath: values[i] = new(sql.NullString) @@ -92,16 +95,16 @@ func (sl *SentinelLibrary) assignValues(columns []string, values []any) error { 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) + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value.Valid { + sl.ID = model.InternalID(value.Int64) } - 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 = int(value.Int64) + sl.SentinelInfoID = model.InternalID(value.Int64) } case sentinellibrary.FieldReportedID: if value, ok := values[i].(*sql.NullInt64); !ok { @@ -127,6 +130,12 @@ func (sl *SentinelLibrary) assignValues(columns []string, values []any) error { } else if value.Valid { sl.CreatedAt = value.Time } + case sentinellibrary.FieldReportSequence: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field report_sequence", values[i]) + } else if value.Valid { + sl.ReportSequence = value.Int64 + } default: sl.selectValues.Set(columns[i], values[i]) } @@ -187,6 +196,9 @@ func (sl *SentinelLibrary) String() string { builder.WriteString(", ") builder.WriteString("created_at=") builder.WriteString(sl.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("report_sequence=") + builder.WriteString(fmt.Sprintf("%v", sl.ReportSequence)) builder.WriteByte(')') return builder.String() } diff --git a/internal/data/internal/ent/sentinellibrary/sentinellibrary.go b/internal/data/internal/ent/sentinellibrary/sentinellibrary.go index 40f3b69d..259daf09 100644 --- a/internal/data/internal/ent/sentinellibrary/sentinellibrary.go +++ b/internal/data/internal/ent/sentinellibrary/sentinellibrary.go @@ -24,6 +24,8 @@ const ( FieldUpdatedAt = "updated_at" // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" + // FieldReportSequence holds the string denoting the report_sequence field in the database. + FieldReportSequence = "report_sequence" // EdgeSentinelInfo holds the string denoting the sentinel_info edge name in mutations. EdgeSentinelInfo = "sentinel_info" // EdgeSentinelAppBinary holds the string denoting the sentinel_app_binary edge name in mutations. @@ -54,6 +56,7 @@ var Columns = []string{ FieldDownloadBasePath, FieldUpdatedAt, FieldCreatedAt, + FieldReportSequence, } // ValidColumn reports if the column name is valid (part of the table columns). @@ -108,6 +111,11 @@ func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() } +// ByReportSequence orders the results by the report_sequence field. +func ByReportSequence(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldReportSequence, opts...).ToFunc() +} + // BySentinelInfoField orders the results by sentinel_info field. func BySentinelInfoField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { diff --git a/internal/data/internal/ent/sentinellibrary/where.go b/internal/data/internal/ent/sentinellibrary/where.go index 8c5323b0..0d903971 100644 --- a/internal/data/internal/ent/sentinellibrary/where.go +++ b/internal/data/internal/ent/sentinellibrary/where.go @@ -8,56 +8,58 @@ import ( "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 { +func ID(id model.InternalID) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldEQ(FieldID, id)) } // IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.SentinelLibrary { +func IDEQ(id model.InternalID) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldEQ(FieldID, id)) } // IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.SentinelLibrary { +func IDNEQ(id model.InternalID) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldNEQ(FieldID, id)) } // IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.SentinelLibrary { +func IDIn(ids ...model.InternalID) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldIn(FieldID, ids...)) } // IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.SentinelLibrary { +func IDNotIn(ids ...model.InternalID) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldNotIn(FieldID, ids...)) } // IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.SentinelLibrary { +func IDGT(id model.InternalID) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldGT(FieldID, id)) } // IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.SentinelLibrary { +func IDGTE(id model.InternalID) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldGTE(FieldID, id)) } // IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.SentinelLibrary { +func IDLT(id model.InternalID) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldLT(FieldID, id)) } // IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.SentinelLibrary { +func IDLTE(id model.InternalID) 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 int) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldEQ(FieldSentinelInfoID, v)) +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. @@ -80,24 +82,39 @@ func CreatedAt(v time.Time) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldEQ(FieldCreatedAt, v)) } +// ReportSequence applies equality check predicate on the "report_sequence" field. It's identical to ReportSequenceEQ. +func ReportSequence(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldReportSequence, v)) +} + // SentinelInfoIDEQ applies the EQ predicate on the "sentinel_info_id" field. -func SentinelInfoIDEQ(v int) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldEQ(FieldSentinelInfoID, v)) +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 int) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldNEQ(FieldSentinelInfoID, v)) +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 ...int) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldIn(FieldSentinelInfoID, vs...)) +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 ...int) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldNotIn(FieldSentinelInfoID, vs...)) +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. @@ -285,6 +302,46 @@ func CreatedAtLTE(v time.Time) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldLTE(FieldCreatedAt, v)) } +// ReportSequenceEQ applies the EQ predicate on the "report_sequence" field. +func ReportSequenceEQ(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldEQ(FieldReportSequence, v)) +} + +// ReportSequenceNEQ applies the NEQ predicate on the "report_sequence" field. +func ReportSequenceNEQ(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNEQ(FieldReportSequence, v)) +} + +// ReportSequenceIn applies the In predicate on the "report_sequence" field. +func ReportSequenceIn(vs ...int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldIn(FieldReportSequence, vs...)) +} + +// ReportSequenceNotIn applies the NotIn predicate on the "report_sequence" field. +func ReportSequenceNotIn(vs ...int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldNotIn(FieldReportSequence, vs...)) +} + +// ReportSequenceGT applies the GT predicate on the "report_sequence" field. +func ReportSequenceGT(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGT(FieldReportSequence, v)) +} + +// ReportSequenceGTE applies the GTE predicate on the "report_sequence" field. +func ReportSequenceGTE(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGTE(FieldReportSequence, v)) +} + +// ReportSequenceLT applies the LT predicate on the "report_sequence" field. +func ReportSequenceLT(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLT(FieldReportSequence, v)) +} + +// ReportSequenceLTE applies the LTE predicate on the "report_sequence" field. +func ReportSequenceLTE(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldLTE(FieldReportSequence, v)) +} + // HasSentinelInfo applies the HasEdge predicate on the "sentinel_info" edge. func HasSentinelInfo() predicate.SentinelLibrary { return predicate.SentinelLibrary(func(s *sql.Selector) { diff --git a/internal/data/internal/ent/sentinellibrary_create.go b/internal/data/internal/ent/sentinellibrary_create.go index 048efe6c..db1e652b 100644 --- a/internal/data/internal/ent/sentinellibrary_create.go +++ b/internal/data/internal/ent/sentinellibrary_create.go @@ -14,6 +14,7 @@ import ( "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" "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. @@ -25,8 +26,8 @@ type SentinelLibraryCreate struct { } // SetSentinelInfoID sets the "sentinel_info_id" field. -func (slc *SentinelLibraryCreate) SetSentinelInfoID(i int) *SentinelLibraryCreate { - slc.mutation.SetSentinelInfoID(i) +func (slc *SentinelLibraryCreate) SetSentinelInfoID(mi model.InternalID) *SentinelLibraryCreate { + slc.mutation.SetSentinelInfoID(mi) return slc } @@ -70,20 +71,32 @@ func (slc *SentinelLibraryCreate) SetNillableCreatedAt(t *time.Time) *SentinelLi return slc } +// SetReportSequence sets the "report_sequence" field. +func (slc *SentinelLibraryCreate) SetReportSequence(i int64) *SentinelLibraryCreate { + slc.mutation.SetReportSequence(i) + return slc +} + +// SetID sets the "id" field. +func (slc *SentinelLibraryCreate) SetID(mi model.InternalID) *SentinelLibraryCreate { + slc.mutation.SetID(mi) + return slc +} + // SetSentinelInfo sets the "sentinel_info" edge to the SentinelInfo entity. func (slc *SentinelLibraryCreate) SetSentinelInfo(s *SentinelInfo) *SentinelLibraryCreate { return slc.SetSentinelInfoID(s.ID) } // AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (slc *SentinelLibraryCreate) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryCreate { +func (slc *SentinelLibraryCreate) AddSentinelAppBinaryIDs(ids ...model.InternalID) *SentinelLibraryCreate { slc.mutation.AddSentinelAppBinaryIDs(ids...) return slc } // AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. func (slc *SentinelLibraryCreate) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryCreate { - ids := make([]int, len(s)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -152,6 +165,9 @@ func (slc *SentinelLibraryCreate) check() error { 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.ReportSequence(); !ok { + return &ValidationError{Name: "report_sequence", err: errors.New(`ent: missing required field "SentinelLibrary.report_sequence"`)} + } if len(slc.mutation.SentinelInfoIDs()) == 0 { return &ValidationError{Name: "sentinel_info", err: errors.New(`ent: missing required edge "SentinelLibrary.sentinel_info"`)} } @@ -169,8 +185,10 @@ func (slc *SentinelLibraryCreate) sqlSave(ctx context.Context) (*SentinelLibrary } return nil, err } - id := _spec.ID.Value.(int64) - _node.ID = int(id) + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = model.InternalID(id) + } slc.mutation.id = &_node.ID slc.mutation.done = true return _node, nil @@ -179,9 +197,13 @@ func (slc *SentinelLibraryCreate) sqlSave(ctx context.Context) (*SentinelLibrary 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 = sqlgraph.NewCreateSpec(sentinellibrary.Table, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64)) ) _spec.OnConflict = slc.conflict + if id, ok := slc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } if value, ok := slc.mutation.ReportedID(); ok { _spec.SetField(sentinellibrary.FieldReportedID, field.TypeInt64, value) _node.ReportedID = value @@ -198,6 +220,10 @@ func (slc *SentinelLibraryCreate) createSpec() (*SentinelLibrary, *sqlgraph.Crea _spec.SetField(sentinellibrary.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } + if value, ok := slc.mutation.ReportSequence(); ok { + _spec.SetField(sentinellibrary.FieldReportSequence, field.TypeInt64, value) + _node.ReportSequence = value + } if nodes := slc.mutation.SentinelInfoIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -206,7 +232,7 @@ func (slc *SentinelLibraryCreate) createSpec() (*SentinelLibrary, *sqlgraph.Crea Columns: []string{sentinellibrary.SentinelInfoColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -223,7 +249,7 @@ func (slc *SentinelLibraryCreate) createSpec() (*SentinelLibrary, *sqlgraph.Crea Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -284,7 +310,7 @@ type ( ) // SetSentinelInfoID sets the "sentinel_info_id" field. -func (u *SentinelLibraryUpsert) SetSentinelInfoID(v int) *SentinelLibraryUpsert { +func (u *SentinelLibraryUpsert) SetSentinelInfoID(v model.InternalID) *SentinelLibraryUpsert { u.Set(sentinellibrary.FieldSentinelInfoID, v) return u } @@ -349,16 +375,42 @@ func (u *SentinelLibraryUpsert) UpdateCreatedAt() *SentinelLibraryUpsert { return u } -// UpdateNewValues updates the mutable fields using the new values that were set on create. +// SetReportSequence sets the "report_sequence" field. +func (u *SentinelLibraryUpsert) SetReportSequence(v int64) *SentinelLibraryUpsert { + u.Set(sentinellibrary.FieldReportSequence, v) + return u +} + +// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. +func (u *SentinelLibraryUpsert) UpdateReportSequence() *SentinelLibraryUpsert { + u.SetExcluded(sentinellibrary.FieldReportSequence) + return u +} + +// AddReportSequence adds v to the "report_sequence" field. +func (u *SentinelLibraryUpsert) AddReportSequence(v int64) *SentinelLibraryUpsert { + u.Add(sentinellibrary.FieldReportSequence, 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.SentinelLibrary.Create(). // OnConflict( // sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(sentinellibrary.FieldID) +// }), // ). // Exec(ctx) func (u *SentinelLibraryUpsertOne) UpdateNewValues() *SentinelLibraryUpsertOne { 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(sentinellibrary.FieldID) + } + })) return u } @@ -390,7 +442,7 @@ func (u *SentinelLibraryUpsertOne) Update(set func(*SentinelLibraryUpsert)) *Sen } // SetSentinelInfoID sets the "sentinel_info_id" field. -func (u *SentinelLibraryUpsertOne) SetSentinelInfoID(v int) *SentinelLibraryUpsertOne { +func (u *SentinelLibraryUpsertOne) SetSentinelInfoID(v model.InternalID) *SentinelLibraryUpsertOne { return u.Update(func(s *SentinelLibraryUpsert) { s.SetSentinelInfoID(v) }) @@ -466,6 +518,27 @@ func (u *SentinelLibraryUpsertOne) UpdateCreatedAt() *SentinelLibraryUpsertOne { }) } +// SetReportSequence sets the "report_sequence" field. +func (u *SentinelLibraryUpsertOne) SetReportSequence(v int64) *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetReportSequence(v) + }) +} + +// AddReportSequence adds v to the "report_sequence" field. +func (u *SentinelLibraryUpsertOne) AddReportSequence(v int64) *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.AddReportSequence(v) + }) +} + +// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. +func (u *SentinelLibraryUpsertOne) UpdateReportSequence() *SentinelLibraryUpsertOne { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateReportSequence() + }) +} + // Exec executes the query. func (u *SentinelLibraryUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { @@ -482,7 +555,7 @@ func (u *SentinelLibraryUpsertOne) ExecX(ctx context.Context) { } // Exec executes the UPSERT query and returns the inserted/updated ID. -func (u *SentinelLibraryUpsertOne) ID(ctx context.Context) (id int, err error) { +func (u *SentinelLibraryUpsertOne) ID(ctx context.Context) (id model.InternalID, err error) { node, err := u.create.Save(ctx) if err != nil { return id, err @@ -491,7 +564,7 @@ func (u *SentinelLibraryUpsertOne) ID(ctx context.Context) (id int, err error) { } // IDX is like ID, but panics if an error occurs. -func (u *SentinelLibraryUpsertOne) IDX(ctx context.Context) int { +func (u *SentinelLibraryUpsertOne) IDX(ctx context.Context) model.InternalID { id, err := u.ID(ctx) if err != nil { panic(err) @@ -546,9 +619,9 @@ func (slcb *SentinelLibraryCreateBulk) Save(ctx context.Context) ([]*SentinelLib return nil, err } mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { + if specs[i].ID.Value != nil && nodes[i].ID == 0 { id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) + nodes[i].ID = model.InternalID(id) } mutation.done = true return nodes[i], nil @@ -636,10 +709,20 @@ type SentinelLibraryUpsertBulk struct { // client.SentinelLibrary.Create(). // OnConflict( // sql.ResolveWithNewValues(), +// sql.ResolveWith(func(u *sql.UpdateSet) { +// u.SetIgnore(sentinellibrary.FieldID) +// }), // ). // Exec(ctx) func (u *SentinelLibraryUpsertBulk) UpdateNewValues() *SentinelLibraryUpsertBulk { 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(sentinellibrary.FieldID) + } + } + })) return u } @@ -671,7 +754,7 @@ func (u *SentinelLibraryUpsertBulk) Update(set func(*SentinelLibraryUpsert)) *Se } // SetSentinelInfoID sets the "sentinel_info_id" field. -func (u *SentinelLibraryUpsertBulk) SetSentinelInfoID(v int) *SentinelLibraryUpsertBulk { +func (u *SentinelLibraryUpsertBulk) SetSentinelInfoID(v model.InternalID) *SentinelLibraryUpsertBulk { return u.Update(func(s *SentinelLibraryUpsert) { s.SetSentinelInfoID(v) }) @@ -747,6 +830,27 @@ func (u *SentinelLibraryUpsertBulk) UpdateCreatedAt() *SentinelLibraryUpsertBulk }) } +// SetReportSequence sets the "report_sequence" field. +func (u *SentinelLibraryUpsertBulk) SetReportSequence(v int64) *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.SetReportSequence(v) + }) +} + +// AddReportSequence adds v to the "report_sequence" field. +func (u *SentinelLibraryUpsertBulk) AddReportSequence(v int64) *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.AddReportSequence(v) + }) +} + +// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. +func (u *SentinelLibraryUpsertBulk) UpdateReportSequence() *SentinelLibraryUpsertBulk { + return u.Update(func(s *SentinelLibraryUpsert) { + s.UpdateReportSequence() + }) +} + // Exec executes the query. func (u *SentinelLibraryUpsertBulk) Exec(ctx context.Context) error { if u.create.err != nil { diff --git a/internal/data/internal/ent/sentinellibrary_delete.go b/internal/data/internal/ent/sentinellibrary_delete.go index bf19e24f..cba4b668 100644 --- a/internal/data/internal/ent/sentinellibrary_delete.go +++ b/internal/data/internal/ent/sentinellibrary_delete.go @@ -40,7 +40,7 @@ func (sld *SentinelLibraryDelete) ExecX(ctx context.Context) int { } func (sld *SentinelLibraryDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(sentinellibrary.Table, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt)) + _spec := sqlgraph.NewDeleteSpec(sentinellibrary.Table, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64)) if ps := sld.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { diff --git a/internal/data/internal/ent/sentinellibrary_query.go b/internal/data/internal/ent/sentinellibrary_query.go index fc81eb1b..cffc3fba 100644 --- a/internal/data/internal/ent/sentinellibrary_query.go +++ b/internal/data/internal/ent/sentinellibrary_query.go @@ -16,6 +16,7 @@ import ( "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" "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. @@ -131,8 +132,8 @@ func (slq *SentinelLibraryQuery) FirstX(ctx context.Context) *SentinelLibrary { // 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 +func (slq *SentinelLibraryQuery) FirstID(ctx context.Context) (id model.InternalID, err error) { + var ids []model.InternalID if ids, err = slq.Limit(1).IDs(setContextOp(ctx, slq.ctx, ent.OpQueryFirstID)); err != nil { return } @@ -144,7 +145,7 @@ func (slq *SentinelLibraryQuery) FirstID(ctx context.Context) (id int, err error } // FirstIDX is like FirstID, but panics if an error occurs. -func (slq *SentinelLibraryQuery) FirstIDX(ctx context.Context) int { +func (slq *SentinelLibraryQuery) FirstIDX(ctx context.Context) model.InternalID { id, err := slq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -182,8 +183,8 @@ func (slq *SentinelLibraryQuery) OnlyX(ctx context.Context) *SentinelLibrary { // 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 +func (slq *SentinelLibraryQuery) OnlyID(ctx context.Context) (id model.InternalID, err error) { + var ids []model.InternalID if ids, err = slq.Limit(2).IDs(setContextOp(ctx, slq.ctx, ent.OpQueryOnlyID)); err != nil { return } @@ -199,7 +200,7 @@ func (slq *SentinelLibraryQuery) OnlyID(ctx context.Context) (id int, err error) } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (slq *SentinelLibraryQuery) OnlyIDX(ctx context.Context) int { +func (slq *SentinelLibraryQuery) OnlyIDX(ctx context.Context) model.InternalID { id, err := slq.OnlyID(ctx) if err != nil { panic(err) @@ -227,7 +228,7 @@ func (slq *SentinelLibraryQuery) AllX(ctx context.Context) []*SentinelLibrary { } // IDs executes the query and returns a list of SentinelLibrary IDs. -func (slq *SentinelLibraryQuery) IDs(ctx context.Context) (ids []int, err error) { +func (slq *SentinelLibraryQuery) IDs(ctx context.Context) (ids []model.InternalID, err error) { if slq.ctx.Unique == nil && slq.path != nil { slq.Unique(true) } @@ -239,7 +240,7 @@ func (slq *SentinelLibraryQuery) IDs(ctx context.Context) (ids []int, err error) } // IDsX is like IDs, but panics if an error occurs. -func (slq *SentinelLibraryQuery) IDsX(ctx context.Context) []int { +func (slq *SentinelLibraryQuery) IDsX(ctx context.Context) []model.InternalID { ids, err := slq.IDs(ctx) if err != nil { panic(err) @@ -335,7 +336,7 @@ func (slq *SentinelLibraryQuery) WithSentinelAppBinary(opts ...func(*SentinelApp // Example: // // var v []struct { -// SentinelInfoID int `json:"sentinel_info_id,omitempty"` +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` // Count int `json:"count,omitempty"` // } // @@ -358,7 +359,7 @@ func (slq *SentinelLibraryQuery) GroupBy(field string, fields ...string) *Sentin // Example: // // var v []struct { -// SentinelInfoID int `json:"sentinel_info_id,omitempty"` +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` // } // // client.SentinelLibrary.Query(). @@ -449,8 +450,8 @@ func (slq *SentinelLibraryQuery) sqlAll(ctx context.Context, hooks ...queryHook) } func (slq *SentinelLibraryQuery) loadSentinelInfo(ctx context.Context, query *SentinelInfoQuery, nodes []*SentinelLibrary, init func(*SentinelLibrary), assign func(*SentinelLibrary, *SentinelInfo)) error { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*SentinelLibrary) + 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 { @@ -479,7 +480,7 @@ func (slq *SentinelLibraryQuery) loadSentinelInfo(ctx context.Context, query *Se } func (slq *SentinelLibraryQuery) loadSentinelAppBinary(ctx context.Context, query *SentinelAppBinaryQuery, nodes []*SentinelLibrary, init func(*SentinelLibrary), assign func(*SentinelLibrary, *SentinelAppBinary)) error { fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*SentinelLibrary) + nodeids := make(map[model.InternalID]*SentinelLibrary) for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] @@ -518,7 +519,7 @@ func (slq *SentinelLibraryQuery) sqlCount(ctx context.Context) (int, error) { } func (slq *SentinelLibraryQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(sentinellibrary.Table, sentinellibrary.Columns, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt)) + _spec := sqlgraph.NewQuerySpec(sentinellibrary.Table, sentinellibrary.Columns, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64)) _spec.From = slq.sql if unique := slq.ctx.Unique; unique != nil { _spec.Unique = *unique diff --git a/internal/data/internal/ent/sentinellibrary_update.go b/internal/data/internal/ent/sentinellibrary_update.go index b4f49d65..ca18d291 100644 --- a/internal/data/internal/ent/sentinellibrary_update.go +++ b/internal/data/internal/ent/sentinellibrary_update.go @@ -15,6 +15,7 @@ import ( "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" "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. @@ -31,15 +32,15 @@ func (slu *SentinelLibraryUpdate) Where(ps ...predicate.SentinelLibrary) *Sentin } // SetSentinelInfoID sets the "sentinel_info_id" field. -func (slu *SentinelLibraryUpdate) SetSentinelInfoID(i int) *SentinelLibraryUpdate { - slu.mutation.SetSentinelInfoID(i) +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(i *int) *SentinelLibraryUpdate { - if i != nil { - slu.SetSentinelInfoID(*i) +func (slu *SentinelLibraryUpdate) SetNillableSentinelInfoID(mi *model.InternalID) *SentinelLibraryUpdate { + if mi != nil { + slu.SetSentinelInfoID(*mi) } return slu } @@ -99,20 +100,41 @@ func (slu *SentinelLibraryUpdate) SetNillableCreatedAt(t *time.Time) *SentinelLi return slu } +// SetReportSequence sets the "report_sequence" field. +func (slu *SentinelLibraryUpdate) SetReportSequence(i int64) *SentinelLibraryUpdate { + slu.mutation.ResetReportSequence() + slu.mutation.SetReportSequence(i) + return slu +} + +// SetNillableReportSequence sets the "report_sequence" field if the given value is not nil. +func (slu *SentinelLibraryUpdate) SetNillableReportSequence(i *int64) *SentinelLibraryUpdate { + if i != nil { + slu.SetReportSequence(*i) + } + return slu +} + +// AddReportSequence adds i to the "report_sequence" field. +func (slu *SentinelLibraryUpdate) AddReportSequence(i int64) *SentinelLibraryUpdate { + slu.mutation.AddReportSequence(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) } // AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (slu *SentinelLibraryUpdate) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdate { +func (slu *SentinelLibraryUpdate) AddSentinelAppBinaryIDs(ids ...model.InternalID) *SentinelLibraryUpdate { slu.mutation.AddSentinelAppBinaryIDs(ids...) return slu } // AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. func (slu *SentinelLibraryUpdate) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdate { - ids := make([]int, len(s)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -137,14 +159,14 @@ func (slu *SentinelLibraryUpdate) ClearSentinelAppBinary() *SentinelLibraryUpdat } // RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to SentinelAppBinary entities by IDs. -func (slu *SentinelLibraryUpdate) RemoveSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdate { +func (slu *SentinelLibraryUpdate) RemoveSentinelAppBinaryIDs(ids ...model.InternalID) *SentinelLibraryUpdate { slu.mutation.RemoveSentinelAppBinaryIDs(ids...) return slu } // RemoveSentinelAppBinary removes "sentinel_app_binary" edges to SentinelAppBinary entities. func (slu *SentinelLibraryUpdate) RemoveSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdate { - ids := make([]int, len(s)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -199,7 +221,7 @@ 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)) + _spec := sqlgraph.NewUpdateSpec(sentinellibrary.Table, sentinellibrary.Columns, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64)) if ps := slu.mutation.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { for i := range ps { @@ -222,6 +244,12 @@ func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error if value, ok := slu.mutation.CreatedAt(); ok { _spec.SetField(sentinellibrary.FieldCreatedAt, field.TypeTime, value) } + if value, ok := slu.mutation.ReportSequence(); ok { + _spec.SetField(sentinellibrary.FieldReportSequence, field.TypeInt64, value) + } + if value, ok := slu.mutation.AddedReportSequence(); ok { + _spec.AddField(sentinellibrary.FieldReportSequence, field.TypeInt64, value) + } if slu.mutation.SentinelInfoCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -230,7 +258,7 @@ func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error Columns: []string{sentinellibrary.SentinelInfoColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -243,7 +271,7 @@ func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error Columns: []string{sentinellibrary.SentinelInfoColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -259,7 +287,7 @@ func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -272,7 +300,7 @@ func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -288,7 +316,7 @@ func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -317,15 +345,15 @@ type SentinelLibraryUpdateOne struct { } // SetSentinelInfoID sets the "sentinel_info_id" field. -func (sluo *SentinelLibraryUpdateOne) SetSentinelInfoID(i int) *SentinelLibraryUpdateOne { - sluo.mutation.SetSentinelInfoID(i) +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(i *int) *SentinelLibraryUpdateOne { - if i != nil { - sluo.SetSentinelInfoID(*i) +func (sluo *SentinelLibraryUpdateOne) SetNillableSentinelInfoID(mi *model.InternalID) *SentinelLibraryUpdateOne { + if mi != nil { + sluo.SetSentinelInfoID(*mi) } return sluo } @@ -385,20 +413,41 @@ func (sluo *SentinelLibraryUpdateOne) SetNillableCreatedAt(t *time.Time) *Sentin return sluo } +// SetReportSequence sets the "report_sequence" field. +func (sluo *SentinelLibraryUpdateOne) SetReportSequence(i int64) *SentinelLibraryUpdateOne { + sluo.mutation.ResetReportSequence() + sluo.mutation.SetReportSequence(i) + return sluo +} + +// SetNillableReportSequence sets the "report_sequence" field if the given value is not nil. +func (sluo *SentinelLibraryUpdateOne) SetNillableReportSequence(i *int64) *SentinelLibraryUpdateOne { + if i != nil { + sluo.SetReportSequence(*i) + } + return sluo +} + +// AddReportSequence adds i to the "report_sequence" field. +func (sluo *SentinelLibraryUpdateOne) AddReportSequence(i int64) *SentinelLibraryUpdateOne { + sluo.mutation.AddReportSequence(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) } // AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (sluo *SentinelLibraryUpdateOne) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdateOne { +func (sluo *SentinelLibraryUpdateOne) AddSentinelAppBinaryIDs(ids ...model.InternalID) *SentinelLibraryUpdateOne { sluo.mutation.AddSentinelAppBinaryIDs(ids...) return sluo } // AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. func (sluo *SentinelLibraryUpdateOne) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdateOne { - ids := make([]int, len(s)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -423,14 +472,14 @@ func (sluo *SentinelLibraryUpdateOne) ClearSentinelAppBinary() *SentinelLibraryU } // RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to SentinelAppBinary entities by IDs. -func (sluo *SentinelLibraryUpdateOne) RemoveSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdateOne { +func (sluo *SentinelLibraryUpdateOne) RemoveSentinelAppBinaryIDs(ids ...model.InternalID) *SentinelLibraryUpdateOne { sluo.mutation.RemoveSentinelAppBinaryIDs(ids...) return sluo } // RemoveSentinelAppBinary removes "sentinel_app_binary" edges to SentinelAppBinary entities. func (sluo *SentinelLibraryUpdateOne) RemoveSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdateOne { - ids := make([]int, len(s)) + ids := make([]model.InternalID, len(s)) for i := range s { ids[i] = s[i].ID } @@ -498,7 +547,7 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti if err := sluo.check(); err != nil { return _node, err } - _spec := sqlgraph.NewUpdateSpec(sentinellibrary.Table, sentinellibrary.Columns, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt)) + _spec := sqlgraph.NewUpdateSpec(sentinellibrary.Table, sentinellibrary.Columns, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64)) id, ok := sluo.mutation.ID() if !ok { return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SentinelLibrary.id" for update`)} @@ -538,6 +587,12 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti if value, ok := sluo.mutation.CreatedAt(); ok { _spec.SetField(sentinellibrary.FieldCreatedAt, field.TypeTime, value) } + if value, ok := sluo.mutation.ReportSequence(); ok { + _spec.SetField(sentinellibrary.FieldReportSequence, field.TypeInt64, value) + } + if value, ok := sluo.mutation.AddedReportSequence(); ok { + _spec.AddField(sentinellibrary.FieldReportSequence, field.TypeInt64, value) + } if sluo.mutation.SentinelInfoCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -546,7 +601,7 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti Columns: []string{sentinellibrary.SentinelInfoColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -559,7 +614,7 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti Columns: []string{sentinellibrary.SentinelInfoColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelinfo.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -575,7 +630,7 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -588,7 +643,7 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } for _, k := range nodes { @@ -604,7 +659,7 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), }, } for _, k := range nodes { diff --git a/internal/model/modelgebura/modelgebura.go b/internal/model/modelgebura/modelgebura.go index bc14da83..f1887425 100644 --- a/internal/model/modelgebura/modelgebura.go +++ b/internal/model/modelgebura/modelgebura.go @@ -110,7 +110,7 @@ type AppCategory struct { //nolint:stylecheck // no check for Url type SentinelInfo struct { - UserID model.InternalID + ID model.InternalID Url string AlternativeUrls []string GetTokenPath string @@ -119,23 +119,28 @@ type SentinelInfo struct { } type SentinelLibrary struct { + ID model.InternalID ReportedID int64 DownloadBasePath string AppBinaries []*SentinelAppBinary + ReportedSequence int64 } type SentinelAppBinary struct { - GeneratedID string - SizeBytes int64 - NeedToken bool - Files []*SentinelAppBinaryFile - Name string - Version string - Developer string - Publisher string + ID model.InternalID + GeneratedID string + SizeBytes int64 + NeedToken bool + Files []*SentinelAppBinaryFile + Name string + Version string + Developer string + Publisher string + ReportedSequence int64 } type SentinelAppBinaryFile struct { + ID model.InternalID Name string SizeBytes int64 Sha256 []byte 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..7a6b5dbf --- /dev/null +++ b/internal/service/sentinel/converter/generated.go @@ -0,0 +1,82 @@ +// 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.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 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..350d817c --- /dev/null +++ b/internal/service/sentinel/converter/pb_to_biz.go @@ -0,0 +1,37 @@ +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:ignore ID + // goverter:map Id ReportedID + // goverter:ignore AppBinaries + // goverter:ignore ReportedSequence + ToBizSentinelLibrary(*sentinel.SentinelLibrary) *modelgebura.SentinelLibrary + // goverter:ignore ID + // goverter:map SentinelGeneratedId GeneratedID + // goverter:ignore ReportedSequence + ToBizSentinelAppBinary(*sentinel.SentinelLibraryAppBinary) *modelgebura.SentinelAppBinary + // goverter:ignore ID + 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..b5d1aa00 --- /dev/null +++ b/internal/service/sentinel/gebura.go @@ -0,0 +1,27 @@ +package sentinel + +import ( + "context" + + "github.com/tuihub/librarian/internal/service/sentinel/converter" + pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1/sentinel" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (s *LibrarianSentinelService) ReportSentinelInformation( + ctx context.Context, req *pb.ReportSentinelInformationRequest, +) (*pb.ReportSentinelInformationResponse, error) { + err := s.g.UpdateSentinelInfo(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) { + return nil, status.Errorf(codes.Unimplemented, "method ReportAppBinaries not implemented") +} 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 From f4be3315b4b6b3b3e927698a9f57e70cce62f9c1 Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Wed, 9 Apr 2025 15:13:00 +0800 Subject: [PATCH 07/16] chore(sentinel): rename update to upsert --- internal/biz/bizgebura/sentinel.go | 2 +- internal/service/sentinel/gebura.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/biz/bizgebura/sentinel.go b/internal/biz/bizgebura/sentinel.go index 85927553..facf59d4 100644 --- a/internal/biz/bizgebura/sentinel.go +++ b/internal/biz/bizgebura/sentinel.go @@ -10,7 +10,7 @@ import ( pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1" ) -func (g *Gebura) UpdateSentinelInfo( +func (g *Gebura) UpsertSentinelInfo( ctx context.Context, info *modelgebura.SentinelInfo, ) error { claims := libauth.FromContextAssertUserType(ctx, model.UserTypeSentinel) diff --git a/internal/service/sentinel/gebura.go b/internal/service/sentinel/gebura.go index b5d1aa00..cd36e072 100644 --- a/internal/service/sentinel/gebura.go +++ b/internal/service/sentinel/gebura.go @@ -13,7 +13,7 @@ import ( func (s *LibrarianSentinelService) ReportSentinelInformation( ctx context.Context, req *pb.ReportSentinelInformationRequest, ) (*pb.ReportSentinelInformationResponse, error) { - err := s.g.UpdateSentinelInfo(ctx, converter.ToBizSentinelInfo(req)) + err := s.g.UpsertSentinelInfo(ctx, converter.ToBizSentinelInfo(req)) if err != nil { return nil, err } From c3a11594ea20f1046c46d2d4c355cd4dbfcfbaf3 Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Wed, 9 Apr 2025 16:18:47 +0800 Subject: [PATCH 08/16] feat(sentinel): impl ReportAppBinaries --- internal/biz/bizgebura/sentinel.go | 28 +++++ internal/data/gebura.go | 104 ++++++++++++++++++ internal/data/internal/ent/migrate/schema.go | 10 ++ .../ent/schema/sentinel_app_binary.go | 1 + .../internal/ent/schema/sentinel_library.go | 1 + internal/model/modelgebura/modelgebura.go | 21 ++-- .../service/sentinel/converter/generated.go | 11 ++ .../service/sentinel/converter/pb_to_biz.go | 1 + internal/service/sentinel/gebura.go | 9 +- 9 files changed, 172 insertions(+), 14 deletions(-) diff --git a/internal/biz/bizgebura/sentinel.go b/internal/biz/bizgebura/sentinel.go index facf59d4..0281859e 100644 --- a/internal/biz/bizgebura/sentinel.go +++ b/internal/biz/bizgebura/sentinel.go @@ -31,3 +31,31 @@ func (g *Gebura) UpsertSentinelInfo( } 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 + var err error + for _, ab := range abs { + ab.ID, err = g.id.New() + if err != nil { + return pb.ErrorErrorReasonUnspecified("%s", err.Error()) + } + for _, f := range ab.Files { + f.ID, err = g.id.New() + if err != nil { + return pb.ErrorErrorReasonUnspecified("%s", err.Error()) + } + } + } + err = g.repo.UpsertAppBinaries(ctx, sentinelID, abs) + if err != nil { + return pb.ErrorErrorReasonUnspecified("%s", err.Error()) + } + return nil +} diff --git a/internal/data/gebura.go b/internal/data/gebura.go index 52f28034..258e6ac8 100644 --- a/internal/data/gebura.go +++ b/internal/data/gebura.go @@ -11,6 +11,7 @@ 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/sentinelinfo" "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" "github.com/tuihub/librarian/internal/data/internal/ent/user" @@ -18,6 +19,7 @@ import ( "github.com/tuihub/librarian/internal/model/modelgebura" "entgo.io/ent/dialect/sql" + "github.com/samber/lo" ) type GeburaRepo struct { @@ -679,3 +681,105 @@ func (g *GeburaRepo) UpsertSentinelInfo( 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 { + sInfo, err := tx.SentinelInfo.Query(). + Where(sentinelinfo.IDEQ(sentinelID)). + WithSentinelLibrary(). + Only(ctx) + if err != nil { + return err + } + slibReportedIDs := lo.Map(sInfo.Edges.SentinelLibrary, func(lib *ent.SentinelLibrary, _ int) int64 { + return lib.ReportedID + }) + slibReportedIDEntMap := lo.Associate( + sInfo.Edges.SentinelLibrary, func(lib *ent.SentinelLibrary, + ) (int64, *ent.SentinelLibrary) { + return lib.ReportedID, lib + }) + // remove all existing binary files + _, err = tx.SentinelAppBinary.Delete().Where( + sentinelappbinary.HasSentinelLibraryWith( + sentinellibrary.SentinelInfoIDEQ(sentinelID), + sentinellibrary.ReportedIDIn(slibReportedIDs...), + ), + ).Exec(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(). + SetID(ab.ID). + SetSentinelLibraryID(slibReportedIDEntMap[ab.SentinelLibraryID].ID). + SetGeneratedID(ab.GeneratedID). + SetSizeBytes(ab.SizeBytes). + SetNeedToken(ab.NeedToken). + SetName(ab.Name). + SetVersion(ab.Version). + SetDeveloper(ab.Developer). + SetPublisher(ab.Publisher). + SetReportSequence(slibReportedIDEntMap[ab.SentinelLibraryID].ReportSequence)) + } + err = tx.SentinelAppBinary.CreateBulk(newAbs...). + OnConflict( + sql.ConflictColumns( + sentinelappbinary.FieldSentinelLibraryID, + sentinelappbinary.FieldGeneratedID, + ), + resolveWithIgnores([]string{ + sentinellibrary.FieldID, + }), + ). + UpdateNewValues(). + Exec(ctx) + if err != nil { + return err + } + // insert all binary files + slibIDs := lo.Map(sInfo.Edges.SentinelLibrary, func(lib *ent.SentinelLibrary, _ int) model.InternalID { + return lib.ID + }) + abGeneratedIDs := lo.Map(abs, func(ab *modelgebura.SentinelAppBinary, _ int) string { + return ab.GeneratedID + }) + dbAbs, err := tx.SentinelAppBinary.Query(). + Where( + sentinelappbinary.SentinelLibraryIDIn(slibIDs...), + sentinelappbinary.GeneratedIDIn(abGeneratedIDs...), + ). + All(ctx) + if err != nil { + return err + } + dbAbGeneratedIDIDMap := lo.Associate(dbAbs, func(ab *ent.SentinelAppBinary) (string, model.InternalID) { + return ab.GeneratedID, ab.ID + }) + for _, ab := range abs { + abfs := make([]*ent.SentinelAppBinaryFileCreate, 0, len(ab.Files)) + for _, f := range ab.Files { + abfs = append(abfs, tx.SentinelAppBinaryFile.Create(). + SetID(f.ID). + SetSentinelAppBinaryID(dbAbGeneratedIDIDMap[ab.GeneratedID]). + SetName(f.Name). + SetSizeBytes(f.SizeBytes). + SetSha256(f.Sha256). + SetServerFilePath(f.ServerFilePath). + SetChunksInfo(f.ChunksInfo)) + } + err = tx.SentinelAppBinaryFile.CreateBulk(abfs...). + Exec(ctx) + if err != nil { + return err + } + } + return nil + }) +} diff --git a/internal/data/internal/ent/migrate/schema.go b/internal/data/internal/ent/migrate/schema.go index 868d5b09..c9122107 100644 --- a/internal/data/internal/ent/migrate/schema.go +++ b/internal/data/internal/ent/migrate/schema.go @@ -776,6 +776,11 @@ var ( Unique: false, Columns: []*schema.Column{SentinelAppBinariesColumns[1]}, }, + { + Name: "sentinelappbinary_report_sequence", + Unique: false, + Columns: []*schema.Column{SentinelAppBinariesColumns[10]}, + }, }, } // SentinelAppBinaryFilesColumns holds the columns for the "sentinel_app_binary_files" table. @@ -856,6 +861,11 @@ var ( Unique: true, Columns: []*schema.Column{SentinelLibrariesColumns[6], SentinelLibrariesColumns[1]}, }, + { + Name: "sentinellibrary_report_sequence", + Unique: false, + Columns: []*schema.Column{SentinelLibrariesColumns[5]}, + }, }, } // SessionsColumns holds the columns for the "sessions" table. diff --git a/internal/data/internal/ent/schema/sentinel_app_binary.go b/internal/data/internal/ent/schema/sentinel_app_binary.go index 91fdcfd8..f5e3b369 100644 --- a/internal/data/internal/ent/schema/sentinel_app_binary.go +++ b/internal/data/internal/ent/schema/sentinel_app_binary.go @@ -39,6 +39,7 @@ func (SentinelAppBinary) Indexes() []ent.Index { index.Fields("sentinel_library_id", "generated_id"). Unique(), index.Fields("generated_id"), + index.Fields("report_sequence"), } } diff --git a/internal/data/internal/ent/schema/sentinel_library.go b/internal/data/internal/ent/schema/sentinel_library.go index 56f3039b..ccc0f530 100644 --- a/internal/data/internal/ent/schema/sentinel_library.go +++ b/internal/data/internal/ent/schema/sentinel_library.go @@ -33,6 +33,7 @@ func (SentinelLibrary) Indexes() []ent.Index { return []ent.Index{ index.Fields("sentinel_info_id", "reported_id"). Unique(), + index.Fields("report_sequence"), } } diff --git a/internal/model/modelgebura/modelgebura.go b/internal/model/modelgebura/modelgebura.go index f1887425..58d0e8bb 100644 --- a/internal/model/modelgebura/modelgebura.go +++ b/internal/model/modelgebura/modelgebura.go @@ -127,16 +127,17 @@ type SentinelLibrary struct { } type SentinelAppBinary struct { - ID model.InternalID - GeneratedID string - SizeBytes int64 - NeedToken bool - Files []*SentinelAppBinaryFile - Name string - Version string - Developer string - Publisher string - ReportedSequence int64 + ID model.InternalID + SentinelLibraryID int64 + GeneratedID string + SizeBytes int64 + NeedToken bool + Files []*SentinelAppBinaryFile + Name string + Version string + Developer string + Publisher string + ReportedSequence int64 } type SentinelAppBinaryFile struct { diff --git a/internal/service/sentinel/converter/generated.go b/internal/service/sentinel/converter/generated.go index 7a6b5dbf..a4fb4009 100644 --- a/internal/service/sentinel/converter/generated.go +++ b/internal/service/sentinel/converter/generated.go @@ -12,6 +12,7 @@ func ToBizSentinelAppBinary(source *sentinel.SentinelLibraryAppBinary) *modelgeb 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 @@ -47,6 +48,16 @@ func ToBizSentinelAppBinaryFile(source *sentinel.SentinelLibraryAppBinaryFile) * } 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 { diff --git a/internal/service/sentinel/converter/pb_to_biz.go b/internal/service/sentinel/converter/pb_to_biz.go index 350d817c..7529a6b1 100644 --- a/internal/service/sentinel/converter/pb_to_biz.go +++ b/internal/service/sentinel/converter/pb_to_biz.go @@ -25,6 +25,7 @@ type toBizConverter interface { //nolint:unused // used by generator // goverter:map SentinelGeneratedId GeneratedID // goverter:ignore ReportedSequence ToBizSentinelAppBinary(*sentinel.SentinelLibraryAppBinary) *modelgebura.SentinelAppBinary + ToBizSentinelAppBinaryList([]*sentinel.SentinelLibraryAppBinary) []*modelgebura.SentinelAppBinary // goverter:ignore ID ToBizSentinelAppBinaryFile(*sentinel.SentinelLibraryAppBinaryFile) *modelgebura.SentinelAppBinaryFile } diff --git a/internal/service/sentinel/gebura.go b/internal/service/sentinel/gebura.go index cd36e072..c939868a 100644 --- a/internal/service/sentinel/gebura.go +++ b/internal/service/sentinel/gebura.go @@ -5,9 +5,6 @@ import ( "github.com/tuihub/librarian/internal/service/sentinel/converter" pb "github.com/tuihub/protos/pkg/librarian/sephirah/v1/sentinel" - - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" ) func (s *LibrarianSentinelService) ReportSentinelInformation( @@ -23,5 +20,9 @@ func (s *LibrarianSentinelService) ReportSentinelInformation( func (s *LibrarianSentinelService) ReportAppBinaries( ctx context.Context, req *pb.ReportAppBinariesRequest, ) (*pb.ReportAppBinariesResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method ReportAppBinaries not implemented") + err := s.g.UpsertAppBinaries(ctx, converter.ToBizSentinelAppBinaryList(req.GetAppBinaries())) + if err != nil { + return nil, err + } + return &pb.ReportAppBinariesResponse{}, nil } From f5fa8b870ef060aec4780eee03e8c8ec5cb399ac Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Wed, 9 Apr 2025 16:19:26 +0800 Subject: [PATCH 09/16] chore(sentinel): change oldLibsMap to lo --- internal/data/gebura.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/data/gebura.go b/internal/data/gebura.go index 258e6ac8..abf1962f 100644 --- a/internal/data/gebura.go +++ b/internal/data/gebura.go @@ -648,10 +648,9 @@ func (g *GeburaRepo) UpsertSentinelInfo( if err != nil { return err } - oldLibsMap := make(map[int64]*ent.SentinelLibrary, len(oldLibs)) - for _, lib := range oldLibs { - oldLibsMap[lib.ReportedID] = lib - } + oldLibsMap := lo.Associate(oldLibs, func(lib *ent.SentinelLibrary) (int64, *ent.SentinelLibrary) { + return lib.ReportedID, lib + }) newLibs := make([]*ent.SentinelLibraryCreate, 0, len(info.Libraries)) for _, lib := range info.Libraries { var reportSeq int64 From a4c1e1f7e86141e0a52ffbb417f453f6af9f4757 Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Wed, 9 Apr 2025 19:38:36 +0800 Subject: [PATCH 10/16] fix(sentinel): typo --- internal/data/gebura.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/data/gebura.go b/internal/data/gebura.go index abf1962f..81380f23 100644 --- a/internal/data/gebura.go +++ b/internal/data/gebura.go @@ -734,7 +734,7 @@ func (g *GeburaRepo) UpsertAppBinaries( sentinelappbinary.FieldGeneratedID, ), resolveWithIgnores([]string{ - sentinellibrary.FieldID, + sentinelappbinary.FieldID, }), ). UpdateNewValues(). From abe141ff1b6f457f3b0b7f523f2b2b53d8c7de12 Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Thu, 10 Apr 2025 10:20:08 +0800 Subject: [PATCH 11/16] feat(sentinel): change model --- internal/data/internal/ent/client.go | 24 +- internal/data/internal/ent/migrate/schema.go | 32 +- internal/data/internal/ent/mutation.go | 626 ++++++++++++------ internal/data/internal/ent/runtime.go | 12 +- .../ent/schema/sentinel_app_binary.go | 9 +- .../ent/schema/sentinel_app_binary_file.go | 10 +- .../data/internal/ent/schema/sentinel_info.go | 2 + .../internal/ent/schema/sentinel_library.go | 5 +- .../data/internal/ent/sentinelappbinary.go | 31 +- .../sentinelappbinary/sentinelappbinary.go | 12 +- .../internal/ent/sentinelappbinary/where.go | 104 ++- .../internal/ent/sentinelappbinary_create.go | 135 ++-- .../internal/ent/sentinelappbinary_delete.go | 2 +- .../internal/ent/sentinelappbinary_query.go | 29 +- .../internal/ent/sentinelappbinary_update.go | 117 ++-- .../internal/ent/sentinelappbinaryfile.go | 28 +- .../sentinelappbinaryfile.go | 8 + .../ent/sentinelappbinaryfile/where.go | 95 ++- .../ent/sentinelappbinaryfile_create.go | 126 ++-- .../ent/sentinelappbinaryfile_delete.go | 2 +- .../ent/sentinelappbinaryfile_query.go | 27 +- .../ent/sentinelappbinaryfile_update.go | 87 ++- internal/data/internal/ent/sentinelinfo.go | 24 +- .../internal/ent/sentinelinfo/sentinelinfo.go | 16 + .../data/internal/ent/sentinelinfo/where.go | 90 +++ .../data/internal/ent/sentinelinfo_create.go | 152 ++++- .../data/internal/ent/sentinelinfo_update.go | 137 +++- internal/data/internal/ent/sentinellibrary.go | 26 +- .../ent/sentinellibrary/sentinellibrary.go | 12 +- .../internal/ent/sentinellibrary/where.go | 72 +- .../internal/ent/sentinellibrary_create.go | 122 ++-- .../internal/ent/sentinellibrary_delete.go | 2 +- .../internal/ent/sentinellibrary_query.go | 20 +- .../internal/ent/sentinellibrary_update.go | 88 +-- internal/model/modelgebura/modelgebura.go | 5 - .../service/sentinel/converter/pb_to_biz.go | 5 - 36 files changed, 1493 insertions(+), 801 deletions(-) diff --git a/internal/data/internal/ent/client.go b/internal/data/internal/ent/client.go index a1c2bc26..f59409e7 100644 --- a/internal/data/internal/ent/client.go +++ b/internal/data/internal/ent/client.go @@ -4269,7 +4269,7 @@ func (c *SentinelAppBinaryClient) UpdateOne(sab *SentinelAppBinary) *SentinelApp } // UpdateOneID returns an update builder for the given id. -func (c *SentinelAppBinaryClient) UpdateOneID(id model.InternalID) *SentinelAppBinaryUpdateOne { +func (c *SentinelAppBinaryClient) UpdateOneID(id int) *SentinelAppBinaryUpdateOne { mutation := newSentinelAppBinaryMutation(c.config, OpUpdateOne, withSentinelAppBinaryID(id)) return &SentinelAppBinaryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } @@ -4286,7 +4286,7 @@ func (c *SentinelAppBinaryClient) DeleteOne(sab *SentinelAppBinary) *SentinelApp } // DeleteOneID returns a builder for deleting the given entity by its id. -func (c *SentinelAppBinaryClient) DeleteOneID(id model.InternalID) *SentinelAppBinaryDeleteOne { +func (c *SentinelAppBinaryClient) DeleteOneID(id int) *SentinelAppBinaryDeleteOne { builder := c.Delete().Where(sentinelappbinary.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne @@ -4303,12 +4303,12 @@ func (c *SentinelAppBinaryClient) Query() *SentinelAppBinaryQuery { } // Get returns a SentinelAppBinary entity by its id. -func (c *SentinelAppBinaryClient) Get(ctx context.Context, id model.InternalID) (*SentinelAppBinary, error) { +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 model.InternalID) *SentinelAppBinary { +func (c *SentinelAppBinaryClient) GetX(ctx context.Context, id int) *SentinelAppBinary { obj, err := c.Get(ctx, id) if err != nil { panic(err) @@ -4434,7 +4434,7 @@ func (c *SentinelAppBinaryFileClient) UpdateOne(sabf *SentinelAppBinaryFile) *Se } // UpdateOneID returns an update builder for the given id. -func (c *SentinelAppBinaryFileClient) UpdateOneID(id model.InternalID) *SentinelAppBinaryFileUpdateOne { +func (c *SentinelAppBinaryFileClient) UpdateOneID(id int) *SentinelAppBinaryFileUpdateOne { mutation := newSentinelAppBinaryFileMutation(c.config, OpUpdateOne, withSentinelAppBinaryFileID(id)) return &SentinelAppBinaryFileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } @@ -4451,7 +4451,7 @@ func (c *SentinelAppBinaryFileClient) DeleteOne(sabf *SentinelAppBinaryFile) *Se } // DeleteOneID returns a builder for deleting the given entity by its id. -func (c *SentinelAppBinaryFileClient) DeleteOneID(id model.InternalID) *SentinelAppBinaryFileDeleteOne { +func (c *SentinelAppBinaryFileClient) DeleteOneID(id int) *SentinelAppBinaryFileDeleteOne { builder := c.Delete().Where(sentinelappbinaryfile.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne @@ -4468,12 +4468,12 @@ func (c *SentinelAppBinaryFileClient) Query() *SentinelAppBinaryFileQuery { } // Get returns a SentinelAppBinaryFile entity by its id. -func (c *SentinelAppBinaryFileClient) Get(ctx context.Context, id model.InternalID) (*SentinelAppBinaryFile, error) { +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 model.InternalID) *SentinelAppBinaryFile { +func (c *SentinelAppBinaryFileClient) GetX(ctx context.Context, id int) *SentinelAppBinaryFile { obj, err := c.Get(ctx, id) if err != nil { panic(err) @@ -4732,7 +4732,7 @@ func (c *SentinelLibraryClient) UpdateOne(sl *SentinelLibrary) *SentinelLibraryU } // UpdateOneID returns an update builder for the given id. -func (c *SentinelLibraryClient) UpdateOneID(id model.InternalID) *SentinelLibraryUpdateOne { +func (c *SentinelLibraryClient) UpdateOneID(id int) *SentinelLibraryUpdateOne { mutation := newSentinelLibraryMutation(c.config, OpUpdateOne, withSentinelLibraryID(id)) return &SentinelLibraryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } @@ -4749,7 +4749,7 @@ func (c *SentinelLibraryClient) DeleteOne(sl *SentinelLibrary) *SentinelLibraryD } // DeleteOneID returns a builder for deleting the given entity by its id. -func (c *SentinelLibraryClient) DeleteOneID(id model.InternalID) *SentinelLibraryDeleteOne { +func (c *SentinelLibraryClient) DeleteOneID(id int) *SentinelLibraryDeleteOne { builder := c.Delete().Where(sentinellibrary.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne @@ -4766,12 +4766,12 @@ func (c *SentinelLibraryClient) Query() *SentinelLibraryQuery { } // Get returns a SentinelLibrary entity by its id. -func (c *SentinelLibraryClient) Get(ctx context.Context, id model.InternalID) (*SentinelLibrary, error) { +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 model.InternalID) *SentinelLibrary { +func (c *SentinelLibraryClient) GetX(ctx context.Context, id int) *SentinelLibrary { obj, err := c.Get(ctx, id) if err != nil { panic(err) diff --git a/internal/data/internal/ent/migrate/schema.go b/internal/data/internal/ent/migrate/schema.go index c9122107..e160eecd 100644 --- a/internal/data/internal/ent/migrate/schema.go +++ b/internal/data/internal/ent/migrate/schema.go @@ -739,7 +739,7 @@ var ( } // SentinelAppBinariesColumns holds the columns for the "sentinel_app_binaries" table. SentinelAppBinariesColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt64}, + {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "generated_id", Type: field.TypeString}, {Name: "size_bytes", Type: field.TypeInt64}, {Name: "need_token", Type: field.TypeBool}, @@ -749,8 +749,8 @@ var ( {Name: "publisher", Type: field.TypeString, Nullable: true}, {Name: "updated_at", Type: field.TypeTime}, {Name: "created_at", Type: field.TypeTime}, - {Name: "report_sequence", Type: field.TypeInt64}, - {Name: "sentinel_library_id", Type: field.TypeInt64}, + {Name: "app_binary_report_sequence", Type: field.TypeInt64}, + {Name: "sentinel_library_id", Type: field.TypeInt}, } // SentinelAppBinariesTable holds the schema information for the "sentinel_app_binaries" table. SentinelAppBinariesTable = &schema.Table{ @@ -777,7 +777,7 @@ var ( Columns: []*schema.Column{SentinelAppBinariesColumns[1]}, }, { - Name: "sentinelappbinary_report_sequence", + Name: "sentinelappbinary_app_binary_report_sequence", Unique: false, Columns: []*schema.Column{SentinelAppBinariesColumns[10]}, }, @@ -785,7 +785,7 @@ var ( } // SentinelAppBinaryFilesColumns holds the columns for the "sentinel_app_binary_files" table. SentinelAppBinaryFilesColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt64}, + {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "name", Type: field.TypeString}, {Name: "size_bytes", Type: field.TypeInt64}, {Name: "sha256", Type: field.TypeBytes}, @@ -793,7 +793,8 @@ var ( {Name: "chunks_info", Type: field.TypeString, Nullable: true}, {Name: "updated_at", Type: field.TypeTime}, {Name: "created_at", Type: field.TypeTime}, - {Name: "sentinel_app_binary_id", Type: field.TypeInt64}, + {Name: "app_binary_report_sequence", Type: field.TypeInt64}, + {Name: "sentinel_app_binary_id", Type: field.TypeInt}, } // SentinelAppBinaryFilesTable holds the schema information for the "sentinel_app_binary_files" table. SentinelAppBinaryFilesTable = &schema.Table{ @@ -803,16 +804,21 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "sentinel_app_binary_files_sentinel_app_binaries_sentinel_app_binary", - Columns: []*schema.Column{SentinelAppBinaryFilesColumns[8]}, + Columns: []*schema.Column{SentinelAppBinaryFilesColumns[9]}, RefColumns: []*schema.Column{SentinelAppBinariesColumns[0]}, OnDelete: schema.NoAction, }, }, Indexes: []*schema.Index{ { - Name: "sentinelappbinaryfile_sentinel_app_binary_id_name", + Name: "sentinelappbinaryfile_sentinel_app_binary_id_server_file_path", + Unique: true, + Columns: []*schema.Column{SentinelAppBinaryFilesColumns[9], SentinelAppBinaryFilesColumns[4]}, + }, + { + Name: "sentinelappbinaryfile_app_binary_report_sequence", Unique: false, - Columns: []*schema.Column{SentinelAppBinaryFilesColumns[8], SentinelAppBinaryFilesColumns[1]}, + Columns: []*schema.Column{SentinelAppBinaryFilesColumns[8]}, }, }, } @@ -825,6 +831,8 @@ var ( {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{ @@ -834,12 +842,12 @@ var ( } // SentinelLibrariesColumns holds the columns for the "sentinel_libraries" table. SentinelLibrariesColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt64}, + {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: "report_sequence", Type: field.TypeInt64}, + {Name: "library_report_sequence", Type: field.TypeInt64}, {Name: "sentinel_info_id", Type: field.TypeInt64}, } // SentinelLibrariesTable holds the schema information for the "sentinel_libraries" table. @@ -862,7 +870,7 @@ var ( Columns: []*schema.Column{SentinelLibrariesColumns[6], SentinelLibrariesColumns[1]}, }, { - Name: "sentinellibrary_report_sequence", + Name: "sentinellibrary_library_report_sequence", Unique: false, Columns: []*schema.Column{SentinelLibrariesColumns[5]}, }, diff --git a/internal/data/internal/ent/mutation.go b/internal/data/internal/ent/mutation.go index 9d7cc046..b997a77a 100644 --- a/internal/data/internal/ent/mutation.go +++ b/internal/data/internal/ent/mutation.go @@ -21858,7 +21858,7 @@ type SentinelAppBinaryMutation struct { config op Op typ string - id *model.InternalID + id *int generated_id *string size_bytes *int64 addsize_bytes *int64 @@ -21869,13 +21869,13 @@ type SentinelAppBinaryMutation struct { publisher *string updated_at *time.Time created_at *time.Time - report_sequence *int64 - addreport_sequence *int64 + app_binary_report_sequence *int64 + addapp_binary_report_sequence *int64 clearedFields map[string]struct{} - sentinel_library *model.InternalID + sentinel_library *int clearedsentinel_library bool - sentinel_app_binary_file map[model.InternalID]struct{} - removedsentinel_app_binary_file map[model.InternalID]struct{} + sentinel_app_binary_file map[int]struct{} + removedsentinel_app_binary_file map[int]struct{} clearedsentinel_app_binary_file bool done bool oldValue func(context.Context) (*SentinelAppBinary, error) @@ -21902,7 +21902,7 @@ func newSentinelAppBinaryMutation(c config, op Op, opts ...sentinelappbinaryOpti } // withSentinelAppBinaryID sets the ID field of the mutation. -func withSentinelAppBinaryID(id model.InternalID) sentinelappbinaryOption { +func withSentinelAppBinaryID(id int) sentinelappbinaryOption { return func(m *SentinelAppBinaryMutation) { var ( err error @@ -21952,15 +21952,9 @@ func (m SentinelAppBinaryMutation) Tx() (*Tx, error) { return tx, nil } -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of SentinelAppBinary entities. -func (m *SentinelAppBinaryMutation) 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 *SentinelAppBinaryMutation) ID() (id model.InternalID, exists bool) { +func (m *SentinelAppBinaryMutation) ID() (id int, exists bool) { if m.id == nil { return } @@ -21971,12 +21965,12 @@ func (m *SentinelAppBinaryMutation) ID() (id model.InternalID, exists bool) { // 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) ([]model.InternalID, error) { +func (m *SentinelAppBinaryMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { - return []model.InternalID{id}, nil + return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): @@ -21987,12 +21981,12 @@ func (m *SentinelAppBinaryMutation) IDs(ctx context.Context) ([]model.InternalID } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (m *SentinelAppBinaryMutation) SetSentinelLibraryID(mi model.InternalID) { - m.sentinel_library = &mi +func (m *SentinelAppBinaryMutation) SetSentinelLibraryID(i int) { + m.sentinel_library = &i } // SentinelLibraryID returns the value of the "sentinel_library_id" field in the mutation. -func (m *SentinelAppBinaryMutation) SentinelLibraryID() (r model.InternalID, exists bool) { +func (m *SentinelAppBinaryMutation) SentinelLibraryID() (r int, exists bool) { v := m.sentinel_library if v == nil { return @@ -22003,7 +21997,7 @@ func (m *SentinelAppBinaryMutation) SentinelLibraryID() (r model.InternalID, exi // OldSentinelLibraryID returns the old "sentinel_library_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) OldSentinelLibraryID(ctx context.Context) (v model.InternalID, err error) { +func (m *SentinelAppBinaryMutation) OldSentinelLibraryID(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSentinelLibraryID is only allowed on UpdateOne operations") } @@ -22418,60 +22412,60 @@ func (m *SentinelAppBinaryMutation) ResetCreatedAt() { m.created_at = nil } -// SetReportSequence sets the "report_sequence" field. -func (m *SentinelAppBinaryMutation) SetReportSequence(i int64) { - m.report_sequence = &i - m.addreport_sequence = 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 } -// ReportSequence returns the value of the "report_sequence" field in the mutation. -func (m *SentinelAppBinaryMutation) ReportSequence() (r int64, exists bool) { - v := m.report_sequence +// 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 } -// OldReportSequence returns the old "report_sequence" field's value of the SentinelAppBinary entity. +// 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) OldReportSequence(ctx context.Context) (v int64, err error) { +func (m *SentinelAppBinaryMutation) OldAppBinaryReportSequence(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldReportSequence is only allowed on UpdateOne operations") + return v, errors.New("OldAppBinaryReportSequence is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldReportSequence requires an ID field in the mutation") + 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 OldReportSequence: %w", err) + return v, fmt.Errorf("querying old value for OldAppBinaryReportSequence: %w", err) } - return oldValue.ReportSequence, nil + return oldValue.AppBinaryReportSequence, nil } -// AddReportSequence adds i to the "report_sequence" field. -func (m *SentinelAppBinaryMutation) AddReportSequence(i int64) { - if m.addreport_sequence != nil { - *m.addreport_sequence += i +// 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.addreport_sequence = &i + m.addapp_binary_report_sequence = &i } } -// AddedReportSequence returns the value that was added to the "report_sequence" field in this mutation. -func (m *SentinelAppBinaryMutation) AddedReportSequence() (r int64, exists bool) { - v := m.addreport_sequence +// 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 } -// ResetReportSequence resets all changes to the "report_sequence" field. -func (m *SentinelAppBinaryMutation) ResetReportSequence() { - m.report_sequence = nil - m.addreport_sequence = nil +// 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 } // ClearSentinelLibrary clears the "sentinel_library" edge to the SentinelLibrary entity. @@ -22488,7 +22482,7 @@ func (m *SentinelAppBinaryMutation) SentinelLibraryCleared() bool { // SentinelLibraryIDs returns the "sentinel_library" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // SentinelLibraryID instead. It exists only for internal usage by the builders. -func (m *SentinelAppBinaryMutation) SentinelLibraryIDs() (ids []model.InternalID) { +func (m *SentinelAppBinaryMutation) SentinelLibraryIDs() (ids []int) { if id := m.sentinel_library; id != nil { ids = append(ids, *id) } @@ -22502,9 +22496,9 @@ func (m *SentinelAppBinaryMutation) ResetSentinelLibrary() { } // AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by ids. -func (m *SentinelAppBinaryMutation) AddSentinelAppBinaryFileIDs(ids ...model.InternalID) { +func (m *SentinelAppBinaryMutation) AddSentinelAppBinaryFileIDs(ids ...int) { if m.sentinel_app_binary_file == nil { - m.sentinel_app_binary_file = make(map[model.InternalID]struct{}) + m.sentinel_app_binary_file = make(map[int]struct{}) } for i := range ids { m.sentinel_app_binary_file[ids[i]] = struct{}{} @@ -22522,9 +22516,9 @@ func (m *SentinelAppBinaryMutation) SentinelAppBinaryFileCleared() bool { } // RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (m *SentinelAppBinaryMutation) RemoveSentinelAppBinaryFileIDs(ids ...model.InternalID) { +func (m *SentinelAppBinaryMutation) RemoveSentinelAppBinaryFileIDs(ids ...int) { if m.removedsentinel_app_binary_file == nil { - m.removedsentinel_app_binary_file = make(map[model.InternalID]struct{}) + m.removedsentinel_app_binary_file = make(map[int]struct{}) } for i := range ids { delete(m.sentinel_app_binary_file, ids[i]) @@ -22533,7 +22527,7 @@ func (m *SentinelAppBinaryMutation) RemoveSentinelAppBinaryFileIDs(ids ...model. } // RemovedSentinelAppBinaryFile returns the removed IDs of the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity. -func (m *SentinelAppBinaryMutation) RemovedSentinelAppBinaryFileIDs() (ids []model.InternalID) { +func (m *SentinelAppBinaryMutation) RemovedSentinelAppBinaryFileIDs() (ids []int) { for id := range m.removedsentinel_app_binary_file { ids = append(ids, id) } @@ -22541,7 +22535,7 @@ func (m *SentinelAppBinaryMutation) RemovedSentinelAppBinaryFileIDs() (ids []mod } // SentinelAppBinaryFileIDs returns the "sentinel_app_binary_file" edge IDs in the mutation. -func (m *SentinelAppBinaryMutation) SentinelAppBinaryFileIDs() (ids []model.InternalID) { +func (m *SentinelAppBinaryMutation) SentinelAppBinaryFileIDs() (ids []int) { for id := range m.sentinel_app_binary_file { ids = append(ids, id) } @@ -22620,8 +22614,8 @@ func (m *SentinelAppBinaryMutation) Fields() []string { if m.created_at != nil { fields = append(fields, sentinelappbinary.FieldCreatedAt) } - if m.report_sequence != nil { - fields = append(fields, sentinelappbinary.FieldReportSequence) + if m.app_binary_report_sequence != nil { + fields = append(fields, sentinelappbinary.FieldAppBinaryReportSequence) } return fields } @@ -22651,8 +22645,8 @@ func (m *SentinelAppBinaryMutation) Field(name string) (ent.Value, bool) { return m.UpdatedAt() case sentinelappbinary.FieldCreatedAt: return m.CreatedAt() - case sentinelappbinary.FieldReportSequence: - return m.ReportSequence() + case sentinelappbinary.FieldAppBinaryReportSequence: + return m.AppBinaryReportSequence() } return nil, false } @@ -22682,8 +22676,8 @@ func (m *SentinelAppBinaryMutation) OldField(ctx context.Context, name string) ( return m.OldUpdatedAt(ctx) case sentinelappbinary.FieldCreatedAt: return m.OldCreatedAt(ctx) - case sentinelappbinary.FieldReportSequence: - return m.OldReportSequence(ctx) + case sentinelappbinary.FieldAppBinaryReportSequence: + return m.OldAppBinaryReportSequence(ctx) } return nil, fmt.Errorf("unknown SentinelAppBinary field %s", name) } @@ -22694,7 +22688,7 @@ func (m *SentinelAppBinaryMutation) OldField(ctx context.Context, name string) ( func (m *SentinelAppBinaryMutation) SetField(name string, value ent.Value) error { switch name { case sentinelappbinary.FieldSentinelLibraryID: - v, ok := value.(model.InternalID) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -22763,12 +22757,12 @@ func (m *SentinelAppBinaryMutation) SetField(name string, value ent.Value) error } m.SetCreatedAt(v) return nil - case sentinelappbinary.FieldReportSequence: + case sentinelappbinary.FieldAppBinaryReportSequence: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetReportSequence(v) + m.SetAppBinaryReportSequence(v) return nil } return fmt.Errorf("unknown SentinelAppBinary field %s", name) @@ -22781,8 +22775,8 @@ func (m *SentinelAppBinaryMutation) AddedFields() []string { if m.addsize_bytes != nil { fields = append(fields, sentinelappbinary.FieldSizeBytes) } - if m.addreport_sequence != nil { - fields = append(fields, sentinelappbinary.FieldReportSequence) + if m.addapp_binary_report_sequence != nil { + fields = append(fields, sentinelappbinary.FieldAppBinaryReportSequence) } return fields } @@ -22794,8 +22788,8 @@ func (m *SentinelAppBinaryMutation) AddedField(name string) (ent.Value, bool) { switch name { case sentinelappbinary.FieldSizeBytes: return m.AddedSizeBytes() - case sentinelappbinary.FieldReportSequence: - return m.AddedReportSequence() + case sentinelappbinary.FieldAppBinaryReportSequence: + return m.AddedAppBinaryReportSequence() } return nil, false } @@ -22812,12 +22806,12 @@ func (m *SentinelAppBinaryMutation) AddField(name string, value ent.Value) error } m.AddSizeBytes(v) return nil - case sentinelappbinary.FieldReportSequence: + case sentinelappbinary.FieldAppBinaryReportSequence: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.AddReportSequence(v) + m.AddAppBinaryReportSequence(v) return nil } return fmt.Errorf("unknown SentinelAppBinary numeric field %s", name) @@ -22903,8 +22897,8 @@ func (m *SentinelAppBinaryMutation) ResetField(name string) error { case sentinelappbinary.FieldCreatedAt: m.ResetCreatedAt() return nil - case sentinelappbinary.FieldReportSequence: - m.ResetReportSequence() + case sentinelappbinary.FieldAppBinaryReportSequence: + m.ResetAppBinaryReportSequence() return nil } return fmt.Errorf("unknown SentinelAppBinary field %s", name) @@ -23015,23 +23009,25 @@ func (m *SentinelAppBinaryMutation) ResetEdge(name string) error { // SentinelAppBinaryFileMutation represents an operation that mutates the SentinelAppBinaryFile nodes in the graph. type SentinelAppBinaryFileMutation struct { config - op Op - typ string - id *model.InternalID - 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 - clearedFields map[string]struct{} - sentinel_app_binary *model.InternalID - clearedsentinel_app_binary bool - done bool - oldValue func(context.Context) (*SentinelAppBinaryFile, error) - predicates []predicate.SentinelAppBinaryFile + op Op + typ string + id *int + 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{} + sentinel_app_binary *int + clearedsentinel_app_binary bool + done bool + oldValue func(context.Context) (*SentinelAppBinaryFile, error) + predicates []predicate.SentinelAppBinaryFile } var _ ent.Mutation = (*SentinelAppBinaryFileMutation)(nil) @@ -23054,7 +23050,7 @@ func newSentinelAppBinaryFileMutation(c config, op Op, opts ...sentinelappbinary } // withSentinelAppBinaryFileID sets the ID field of the mutation. -func withSentinelAppBinaryFileID(id model.InternalID) sentinelappbinaryfileOption { +func withSentinelAppBinaryFileID(id int) sentinelappbinaryfileOption { return func(m *SentinelAppBinaryFileMutation) { var ( err error @@ -23104,15 +23100,9 @@ func (m SentinelAppBinaryFileMutation) Tx() (*Tx, error) { return tx, nil } -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of SentinelAppBinaryFile entities. -func (m *SentinelAppBinaryFileMutation) 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 *SentinelAppBinaryFileMutation) ID() (id model.InternalID, exists bool) { +func (m *SentinelAppBinaryFileMutation) ID() (id int, exists bool) { if m.id == nil { return } @@ -23123,12 +23113,12 @@ func (m *SentinelAppBinaryFileMutation) ID() (id model.InternalID, exists bool) // 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) ([]model.InternalID, error) { +func (m *SentinelAppBinaryFileMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { - return []model.InternalID{id}, nil + return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): @@ -23139,12 +23129,12 @@ func (m *SentinelAppBinaryFileMutation) IDs(ctx context.Context) ([]model.Intern } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (m *SentinelAppBinaryFileMutation) SetSentinelAppBinaryID(mi model.InternalID) { - m.sentinel_app_binary = &mi +func (m *SentinelAppBinaryFileMutation) SetSentinelAppBinaryID(i int) { + m.sentinel_app_binary = &i } // SentinelAppBinaryID returns the value of the "sentinel_app_binary_id" field in the mutation. -func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryID() (r model.InternalID, exists bool) { +func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryID() (r int, exists bool) { v := m.sentinel_app_binary if v == nil { return @@ -23155,7 +23145,7 @@ func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryID() (r model.InternalI // OldSentinelAppBinaryID returns the old "sentinel_app_binary_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) OldSentinelAppBinaryID(ctx context.Context) (v model.InternalID, err error) { +func (m *SentinelAppBinaryFileMutation) OldSentinelAppBinaryID(ctx context.Context) (v int, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSentinelAppBinaryID is only allowed on UpdateOne operations") } @@ -23459,6 +23449,62 @@ 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 +} + // ClearSentinelAppBinary clears the "sentinel_app_binary" edge to the SentinelAppBinary entity. func (m *SentinelAppBinaryFileMutation) ClearSentinelAppBinary() { m.clearedsentinel_app_binary = true @@ -23473,7 +23519,7 @@ func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryCleared() bool { // SentinelAppBinaryIDs returns the "sentinel_app_binary" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // SentinelAppBinaryID instead. It exists only for internal usage by the builders. -func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryIDs() (ids []model.InternalID) { +func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryIDs() (ids []int) { if id := m.sentinel_app_binary; id != nil { ids = append(ids, *id) } @@ -23520,7 +23566,7 @@ func (m *SentinelAppBinaryFileMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *SentinelAppBinaryFileMutation) Fields() []string { - fields := make([]string, 0, 8) + fields := make([]string, 0, 9) if m.sentinel_app_binary != nil { fields = append(fields, sentinelappbinaryfile.FieldSentinelAppBinaryID) } @@ -23545,6 +23591,9 @@ func (m *SentinelAppBinaryFileMutation) Fields() []string { if m.created_at != nil { fields = append(fields, sentinelappbinaryfile.FieldCreatedAt) } + if m.app_binary_report_sequence != nil { + fields = append(fields, sentinelappbinaryfile.FieldAppBinaryReportSequence) + } return fields } @@ -23569,6 +23618,8 @@ func (m *SentinelAppBinaryFileMutation) Field(name string) (ent.Value, bool) { return m.UpdatedAt() case sentinelappbinaryfile.FieldCreatedAt: return m.CreatedAt() + case sentinelappbinaryfile.FieldAppBinaryReportSequence: + return m.AppBinaryReportSequence() } return nil, false } @@ -23594,6 +23645,8 @@ func (m *SentinelAppBinaryFileMutation) OldField(ctx context.Context, name strin 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) } @@ -23604,7 +23657,7 @@ func (m *SentinelAppBinaryFileMutation) OldField(ctx context.Context, name strin func (m *SentinelAppBinaryFileMutation) SetField(name string, value ent.Value) error { switch name { case sentinelappbinaryfile.FieldSentinelAppBinaryID: - v, ok := value.(model.InternalID) + v, ok := value.(int) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } @@ -23659,6 +23712,13 @@ func (m *SentinelAppBinaryFileMutation) SetField(name string, value ent.Value) e } 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) } @@ -23670,6 +23730,9 @@ func (m *SentinelAppBinaryFileMutation) AddedFields() []string { if m.addsize_bytes != nil { fields = append(fields, sentinelappbinaryfile.FieldSizeBytes) } + if m.addapp_binary_report_sequence != nil { + fields = append(fields, sentinelappbinaryfile.FieldAppBinaryReportSequence) + } return fields } @@ -23680,6 +23743,8 @@ func (m *SentinelAppBinaryFileMutation) AddedField(name string) (ent.Value, bool switch name { case sentinelappbinaryfile.FieldSizeBytes: return m.AddedSizeBytes() + case sentinelappbinaryfile.FieldAppBinaryReportSequence: + return m.AddedAppBinaryReportSequence() } return nil, false } @@ -23696,6 +23761,13 @@ func (m *SentinelAppBinaryFileMutation) AddField(name string, value ent.Value) e } 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) } @@ -23756,6 +23828,9 @@ func (m *SentinelAppBinaryFileMutation) ResetField(name string) error { case sentinelappbinaryfile.FieldCreatedAt: m.ResetCreatedAt() return nil + case sentinelappbinaryfile.FieldAppBinaryReportSequence: + m.ResetAppBinaryReportSequence() + return nil } return fmt.Errorf("unknown SentinelAppBinaryFile field %s", name) } @@ -23837,23 +23912,27 @@ func (m *SentinelAppBinaryFileMutation) ResetEdge(name string) error { // 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 - clearedFields map[string]struct{} - sentinel_library map[model.InternalID]struct{} - removedsentinel_library map[model.InternalID]struct{} - clearedsentinel_library bool - done bool - oldValue func(context.Context) (*SentinelInfo, error) - predicates []predicate.SentinelInfo + 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) @@ -24218,10 +24297,122 @@ 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 ...model.InternalID) { +func (m *SentinelInfoMutation) AddSentinelLibraryIDs(ids ...int) { if m.sentinel_library == nil { - m.sentinel_library = make(map[model.InternalID]struct{}) + m.sentinel_library = make(map[int]struct{}) } for i := range ids { m.sentinel_library[ids[i]] = struct{}{} @@ -24239,9 +24430,9 @@ func (m *SentinelInfoMutation) SentinelLibraryCleared() bool { } // RemoveSentinelLibraryIDs removes the "sentinel_library" edge to the SentinelLibrary entity by IDs. -func (m *SentinelInfoMutation) RemoveSentinelLibraryIDs(ids ...model.InternalID) { +func (m *SentinelInfoMutation) RemoveSentinelLibraryIDs(ids ...int) { if m.removedsentinel_library == nil { - m.removedsentinel_library = make(map[model.InternalID]struct{}) + m.removedsentinel_library = make(map[int]struct{}) } for i := range ids { delete(m.sentinel_library, ids[i]) @@ -24250,7 +24441,7 @@ func (m *SentinelInfoMutation) RemoveSentinelLibraryIDs(ids ...model.InternalID) } // RemovedSentinelLibrary returns the removed IDs of the "sentinel_library" edge to the SentinelLibrary entity. -func (m *SentinelInfoMutation) RemovedSentinelLibraryIDs() (ids []model.InternalID) { +func (m *SentinelInfoMutation) RemovedSentinelLibraryIDs() (ids []int) { for id := range m.removedsentinel_library { ids = append(ids, id) } @@ -24258,7 +24449,7 @@ func (m *SentinelInfoMutation) RemovedSentinelLibraryIDs() (ids []model.Internal } // SentinelLibraryIDs returns the "sentinel_library" edge IDs in the mutation. -func (m *SentinelInfoMutation) SentinelLibraryIDs() (ids []model.InternalID) { +func (m *SentinelInfoMutation) SentinelLibraryIDs() (ids []int) { for id := range m.sentinel_library { ids = append(ids, id) } @@ -24306,7 +24497,7 @@ func (m *SentinelInfoMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *SentinelInfoMutation) Fields() []string { - fields := make([]string, 0, 6) + fields := make([]string, 0, 8) if m.url != nil { fields = append(fields, sentinelinfo.FieldURL) } @@ -24325,6 +24516,12 @@ func (m *SentinelInfoMutation) Fields() []string { 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 } @@ -24345,6 +24542,10 @@ func (m *SentinelInfoMutation) Field(name string) (ent.Value, bool) { return m.UpdatedAt() case sentinelinfo.FieldCreatedAt: return m.CreatedAt() + case sentinelinfo.FieldLibraryReportSequence: + return m.LibraryReportSequence() + case sentinelinfo.FieldAppBinaryReportSequence: + return m.AppBinaryReportSequence() } return nil, false } @@ -24366,6 +24567,10 @@ func (m *SentinelInfoMutation) OldField(ctx context.Context, name string) (ent.V 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) } @@ -24417,6 +24622,20 @@ func (m *SentinelInfoMutation) SetField(name string, value ent.Value) error { } 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) } @@ -24424,13 +24643,26 @@ func (m *SentinelInfoMutation) SetField(name string, value ent.Value) error { // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *SentinelInfoMutation) AddedFields() []string { - return nil + 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 } @@ -24439,6 +24671,20 @@ func (m *SentinelInfoMutation) AddedField(name string) (ent.Value, bool) { // 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) } @@ -24499,6 +24745,12 @@ func (m *SentinelInfoMutation) ResetField(name string) error { 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) } @@ -24592,19 +24844,19 @@ type SentinelLibraryMutation struct { config op Op typ string - id *model.InternalID + id *int reported_id *int64 addreported_id *int64 download_base_path *string updated_at *time.Time created_at *time.Time - report_sequence *int64 - addreport_sequence *int64 + library_report_sequence *int64 + addlibrary_report_sequence *int64 clearedFields map[string]struct{} sentinel_info *model.InternalID clearedsentinel_info bool - sentinel_app_binary map[model.InternalID]struct{} - removedsentinel_app_binary map[model.InternalID]struct{} + sentinel_app_binary map[int]struct{} + removedsentinel_app_binary map[int]struct{} clearedsentinel_app_binary bool done bool oldValue func(context.Context) (*SentinelLibrary, error) @@ -24631,7 +24883,7 @@ func newSentinelLibraryMutation(c config, op Op, opts ...sentinellibraryOption) } // withSentinelLibraryID sets the ID field of the mutation. -func withSentinelLibraryID(id model.InternalID) sentinellibraryOption { +func withSentinelLibraryID(id int) sentinellibraryOption { return func(m *SentinelLibraryMutation) { var ( err error @@ -24681,15 +24933,9 @@ func (m SentinelLibraryMutation) Tx() (*Tx, error) { return tx, nil } -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of SentinelLibrary entities. -func (m *SentinelLibraryMutation) 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 *SentinelLibraryMutation) ID() (id model.InternalID, exists bool) { +func (m *SentinelLibraryMutation) ID() (id int, exists bool) { if m.id == nil { return } @@ -24700,12 +24946,12 @@ func (m *SentinelLibraryMutation) ID() (id model.InternalID, exists bool) { // 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) ([]model.InternalID, error) { +func (m *SentinelLibraryMutation) IDs(ctx context.Context) ([]int, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { - return []model.InternalID{id}, nil + return []int{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): @@ -24915,60 +25161,60 @@ func (m *SentinelLibraryMutation) ResetCreatedAt() { m.created_at = nil } -// SetReportSequence sets the "report_sequence" field. -func (m *SentinelLibraryMutation) SetReportSequence(i int64) { - m.report_sequence = &i - m.addreport_sequence = nil +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (m *SentinelLibraryMutation) SetLibraryReportSequence(i int64) { + m.library_report_sequence = &i + m.addlibrary_report_sequence = nil } -// ReportSequence returns the value of the "report_sequence" field in the mutation. -func (m *SentinelLibraryMutation) ReportSequence() (r int64, exists bool) { - v := m.report_sequence +// 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 } -// OldReportSequence returns the old "report_sequence" field's value of the SentinelLibrary entity. +// 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) OldReportSequence(ctx context.Context) (v int64, err error) { +func (m *SentinelLibraryMutation) OldLibraryReportSequence(ctx context.Context) (v int64, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldReportSequence is only allowed on UpdateOne operations") + return v, errors.New("OldLibraryReportSequence is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldReportSequence requires an ID field in the mutation") + 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 OldReportSequence: %w", err) + return v, fmt.Errorf("querying old value for OldLibraryReportSequence: %w", err) } - return oldValue.ReportSequence, nil + return oldValue.LibraryReportSequence, nil } -// AddReportSequence adds i to the "report_sequence" field. -func (m *SentinelLibraryMutation) AddReportSequence(i int64) { - if m.addreport_sequence != nil { - *m.addreport_sequence += i +// 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.addreport_sequence = &i + m.addlibrary_report_sequence = &i } } -// AddedReportSequence returns the value that was added to the "report_sequence" field in this mutation. -func (m *SentinelLibraryMutation) AddedReportSequence() (r int64, exists bool) { - v := m.addreport_sequence +// 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 } -// ResetReportSequence resets all changes to the "report_sequence" field. -func (m *SentinelLibraryMutation) ResetReportSequence() { - m.report_sequence = nil - m.addreport_sequence = nil +// 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. @@ -24999,9 +25245,9 @@ func (m *SentinelLibraryMutation) ResetSentinelInfo() { } // AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by ids. -func (m *SentinelLibraryMutation) AddSentinelAppBinaryIDs(ids ...model.InternalID) { +func (m *SentinelLibraryMutation) AddSentinelAppBinaryIDs(ids ...int) { if m.sentinel_app_binary == nil { - m.sentinel_app_binary = make(map[model.InternalID]struct{}) + m.sentinel_app_binary = make(map[int]struct{}) } for i := range ids { m.sentinel_app_binary[ids[i]] = struct{}{} @@ -25019,9 +25265,9 @@ func (m *SentinelLibraryMutation) SentinelAppBinaryCleared() bool { } // RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (m *SentinelLibraryMutation) RemoveSentinelAppBinaryIDs(ids ...model.InternalID) { +func (m *SentinelLibraryMutation) RemoveSentinelAppBinaryIDs(ids ...int) { if m.removedsentinel_app_binary == nil { - m.removedsentinel_app_binary = make(map[model.InternalID]struct{}) + m.removedsentinel_app_binary = make(map[int]struct{}) } for i := range ids { delete(m.sentinel_app_binary, ids[i]) @@ -25030,7 +25276,7 @@ func (m *SentinelLibraryMutation) RemoveSentinelAppBinaryIDs(ids ...model.Intern } // RemovedSentinelAppBinary returns the removed IDs of the "sentinel_app_binary" edge to the SentinelAppBinary entity. -func (m *SentinelLibraryMutation) RemovedSentinelAppBinaryIDs() (ids []model.InternalID) { +func (m *SentinelLibraryMutation) RemovedSentinelAppBinaryIDs() (ids []int) { for id := range m.removedsentinel_app_binary { ids = append(ids, id) } @@ -25038,7 +25284,7 @@ func (m *SentinelLibraryMutation) RemovedSentinelAppBinaryIDs() (ids []model.Int } // SentinelAppBinaryIDs returns the "sentinel_app_binary" edge IDs in the mutation. -func (m *SentinelLibraryMutation) SentinelAppBinaryIDs() (ids []model.InternalID) { +func (m *SentinelLibraryMutation) SentinelAppBinaryIDs() (ids []int) { for id := range m.sentinel_app_binary { ids = append(ids, id) } @@ -25102,8 +25348,8 @@ func (m *SentinelLibraryMutation) Fields() []string { if m.created_at != nil { fields = append(fields, sentinellibrary.FieldCreatedAt) } - if m.report_sequence != nil { - fields = append(fields, sentinellibrary.FieldReportSequence) + if m.library_report_sequence != nil { + fields = append(fields, sentinellibrary.FieldLibraryReportSequence) } return fields } @@ -25123,8 +25369,8 @@ func (m *SentinelLibraryMutation) Field(name string) (ent.Value, bool) { return m.UpdatedAt() case sentinellibrary.FieldCreatedAt: return m.CreatedAt() - case sentinellibrary.FieldReportSequence: - return m.ReportSequence() + case sentinellibrary.FieldLibraryReportSequence: + return m.LibraryReportSequence() } return nil, false } @@ -25144,8 +25390,8 @@ func (m *SentinelLibraryMutation) OldField(ctx context.Context, name string) (en return m.OldUpdatedAt(ctx) case sentinellibrary.FieldCreatedAt: return m.OldCreatedAt(ctx) - case sentinellibrary.FieldReportSequence: - return m.OldReportSequence(ctx) + case sentinellibrary.FieldLibraryReportSequence: + return m.OldLibraryReportSequence(ctx) } return nil, fmt.Errorf("unknown SentinelLibrary field %s", name) } @@ -25190,12 +25436,12 @@ func (m *SentinelLibraryMutation) SetField(name string, value ent.Value) error { } m.SetCreatedAt(v) return nil - case sentinellibrary.FieldReportSequence: + case sentinellibrary.FieldLibraryReportSequence: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetReportSequence(v) + m.SetLibraryReportSequence(v) return nil } return fmt.Errorf("unknown SentinelLibrary field %s", name) @@ -25208,8 +25454,8 @@ func (m *SentinelLibraryMutation) AddedFields() []string { if m.addreported_id != nil { fields = append(fields, sentinellibrary.FieldReportedID) } - if m.addreport_sequence != nil { - fields = append(fields, sentinellibrary.FieldReportSequence) + if m.addlibrary_report_sequence != nil { + fields = append(fields, sentinellibrary.FieldLibraryReportSequence) } return fields } @@ -25221,8 +25467,8 @@ func (m *SentinelLibraryMutation) AddedField(name string) (ent.Value, bool) { switch name { case sentinellibrary.FieldReportedID: return m.AddedReportedID() - case sentinellibrary.FieldReportSequence: - return m.AddedReportSequence() + case sentinellibrary.FieldLibraryReportSequence: + return m.AddedLibraryReportSequence() } return nil, false } @@ -25239,12 +25485,12 @@ func (m *SentinelLibraryMutation) AddField(name string, value ent.Value) error { } m.AddReportedID(v) return nil - case sentinellibrary.FieldReportSequence: + case sentinellibrary.FieldLibraryReportSequence: v, ok := value.(int64) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.AddReportSequence(v) + m.AddLibraryReportSequence(v) return nil } return fmt.Errorf("unknown SentinelLibrary numeric field %s", name) @@ -25288,8 +25534,8 @@ func (m *SentinelLibraryMutation) ResetField(name string) error { case sentinellibrary.FieldCreatedAt: m.ResetCreatedAt() return nil - case sentinellibrary.FieldReportSequence: - m.ResetReportSequence() + case sentinellibrary.FieldLibraryReportSequence: + m.ResetLibraryReportSequence() return nil } return fmt.Errorf("unknown SentinelLibrary field %s", name) diff --git a/internal/data/internal/ent/runtime.go b/internal/data/internal/ent/runtime.go index 723dd0f3..821891c6 100644 --- a/internal/data/internal/ent/runtime.go +++ b/internal/data/internal/ent/runtime.go @@ -314,25 +314,25 @@ func init() { sentinelappbinaryFields := schema.SentinelAppBinary{}.Fields() _ = sentinelappbinaryFields // sentinelappbinaryDescUpdatedAt is the schema descriptor for updated_at field. - sentinelappbinaryDescUpdatedAt := sentinelappbinaryFields[9].Descriptor() + sentinelappbinaryDescUpdatedAt := sentinelappbinaryFields[8].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() + sentinelappbinaryDescCreatedAt := sentinelappbinaryFields[9].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[7].Descriptor() + sentinelappbinaryfileDescUpdatedAt := sentinelappbinaryfileFields[6].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[8].Descriptor() + sentinelappbinaryfileDescCreatedAt := sentinelappbinaryfileFields[7].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() @@ -350,13 +350,13 @@ func init() { sentinellibraryFields := schema.SentinelLibrary{}.Fields() _ = sentinellibraryFields // sentinellibraryDescUpdatedAt is the schema descriptor for updated_at field. - sentinellibraryDescUpdatedAt := sentinellibraryFields[4].Descriptor() + 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[5].Descriptor() + 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() diff --git a/internal/data/internal/ent/schema/sentinel_app_binary.go b/internal/data/internal/ent/schema/sentinel_app_binary.go index f5e3b369..1b6a590e 100644 --- a/internal/data/internal/ent/schema/sentinel_app_binary.go +++ b/internal/data/internal/ent/schema/sentinel_app_binary.go @@ -3,8 +3,6 @@ package schema import ( "time" - "github.com/tuihub/librarian/internal/model" - "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" @@ -17,8 +15,7 @@ type SentinelAppBinary struct { func (SentinelAppBinary) Fields() []ent.Field { return []ent.Field{ - defaultPrimaryKey(), - field.Int64("sentinel_library_id").GoType(model.InternalID(0)), + field.Int("sentinel_library_id"), field.String("generated_id"), field.Int64("size_bytes"), field.Bool("need_token"), @@ -30,7 +27,7 @@ func (SentinelAppBinary) Fields() []ent.Field { Default(time.Now).UpdateDefault(time.Now), field.Time("created_at"). Default(time.Now), - field.Int64("report_sequence"), + field.Int64("app_binary_report_sequence"), } } @@ -39,7 +36,7 @@ func (SentinelAppBinary) Indexes() []ent.Index { index.Fields("sentinel_library_id", "generated_id"). Unique(), index.Fields("generated_id"), - index.Fields("report_sequence"), + index.Fields("app_binary_report_sequence"), } } diff --git a/internal/data/internal/ent/schema/sentinel_app_binary_file.go b/internal/data/internal/ent/schema/sentinel_app_binary_file.go index d1118c52..da8c3bed 100644 --- a/internal/data/internal/ent/schema/sentinel_app_binary_file.go +++ b/internal/data/internal/ent/schema/sentinel_app_binary_file.go @@ -3,8 +3,6 @@ package schema import ( "time" - "github.com/tuihub/librarian/internal/model" - "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" @@ -17,8 +15,7 @@ type SentinelAppBinaryFile struct { func (SentinelAppBinaryFile) Fields() []ent.Field { return []ent.Field{ - defaultPrimaryKey(), - field.Int64("sentinel_app_binary_id").GoType(model.InternalID(0)), + field.Int("sentinel_app_binary_id"), field.String("name"), field.Int64("size_bytes"), field.Bytes("sha256"), @@ -28,12 +25,15 @@ func (SentinelAppBinaryFile) Fields() []ent.Field { 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", "name"), + index.Fields("sentinel_app_binary_id", "server_file_path"). + Unique(), + index.Fields("app_binary_report_sequence"), } } diff --git a/internal/data/internal/ent/schema/sentinel_info.go b/internal/data/internal/ent/schema/sentinel_info.go index b6306bc9..f435b4bd 100644 --- a/internal/data/internal/ent/schema/sentinel_info.go +++ b/internal/data/internal/ent/schema/sentinel_info.go @@ -23,6 +23,8 @@ func (SentinelInfo) Fields() []ent.Field { Default(time.Now).UpdateDefault(time.Now), field.Time("created_at"). Default(time.Now), + field.Int64("library_report_sequence"), + field.Int64("app_binary_report_sequence"), } } diff --git a/internal/data/internal/ent/schema/sentinel_library.go b/internal/data/internal/ent/schema/sentinel_library.go index ccc0f530..988a8762 100644 --- a/internal/data/internal/ent/schema/sentinel_library.go +++ b/internal/data/internal/ent/schema/sentinel_library.go @@ -17,7 +17,6 @@ type SentinelLibrary struct { func (SentinelLibrary) Fields() []ent.Field { return []ent.Field{ - defaultPrimaryKey(), field.Int64("sentinel_info_id").GoType(model.InternalID(0)), field.Int64("reported_id"), field.String("download_base_path"), @@ -25,7 +24,7 @@ func (SentinelLibrary) Fields() []ent.Field { Default(time.Now).UpdateDefault(time.Now), field.Time("created_at"). Default(time.Now), - field.Int64("report_sequence"), + field.Int64("library_report_sequence"), } } @@ -33,7 +32,7 @@ func (SentinelLibrary) Indexes() []ent.Index { return []ent.Index{ index.Fields("sentinel_info_id", "reported_id"). Unique(), - index.Fields("report_sequence"), + index.Fields("library_report_sequence"), } } diff --git a/internal/data/internal/ent/sentinelappbinary.go b/internal/data/internal/ent/sentinelappbinary.go index f0cc90bb..2f2b3b2e 100644 --- a/internal/data/internal/ent/sentinelappbinary.go +++ b/internal/data/internal/ent/sentinelappbinary.go @@ -11,16 +11,15 @@ import ( "entgo.io/ent/dialect/sql" "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" - "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 model.InternalID `json:"id,omitempty"` + ID int `json:"id,omitempty"` // SentinelLibraryID holds the value of the "sentinel_library_id" field. - SentinelLibraryID model.InternalID `json:"sentinel_library_id,omitempty"` + SentinelLibraryID int `json:"sentinel_library_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. @@ -39,8 +38,8 @@ type SentinelAppBinary struct { UpdatedAt time.Time `json:"updated_at,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` - // ReportSequence holds the value of the "report_sequence" field. - ReportSequence int64 `json:"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 SentinelAppBinaryQuery when eager-loading is set. Edges SentinelAppBinaryEdges `json:"edges"` @@ -85,7 +84,7 @@ func (*SentinelAppBinary) scanValues(columns []string) ([]any, error) { switch columns[i] { case sentinelappbinary.FieldNeedToken: values[i] = new(sql.NullBool) - case sentinelappbinary.FieldID, sentinelappbinary.FieldSentinelLibraryID, sentinelappbinary.FieldSizeBytes, sentinelappbinary.FieldReportSequence: + case sentinelappbinary.FieldID, sentinelappbinary.FieldSentinelLibraryID, 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) @@ -107,16 +106,16 @@ func (sab *SentinelAppBinary) assignValues(columns []string, values []any) error for i := range columns { switch columns[i] { case sentinelappbinary.FieldID: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field id", values[i]) - } else if value.Valid { - sab.ID = model.InternalID(value.Int64) + 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.FieldSentinelLibraryID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field sentinel_library_id", values[i]) } else if value.Valid { - sab.SentinelLibraryID = model.InternalID(value.Int64) + sab.SentinelLibraryID = int(value.Int64) } case sentinelappbinary.FieldGeneratedID: if value, ok := values[i].(*sql.NullString); !ok { @@ -172,11 +171,11 @@ func (sab *SentinelAppBinary) assignValues(columns []string, values []any) error } else if value.Valid { sab.CreatedAt = value.Time } - case sentinelappbinary.FieldReportSequence: + case sentinelappbinary.FieldAppBinaryReportSequence: if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field report_sequence", values[i]) + return fmt.Errorf("unexpected type %T for field app_binary_report_sequence", values[i]) } else if value.Valid { - sab.ReportSequence = value.Int64 + sab.AppBinaryReportSequence = value.Int64 } default: sab.selectValues.Set(columns[i], values[i]) @@ -254,8 +253,8 @@ func (sab *SentinelAppBinary) String() string { builder.WriteString("created_at=") builder.WriteString(sab.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") - builder.WriteString("report_sequence=") - builder.WriteString(fmt.Sprintf("%v", sab.ReportSequence)) + builder.WriteString("app_binary_report_sequence=") + builder.WriteString(fmt.Sprintf("%v", sab.AppBinaryReportSequence)) builder.WriteByte(')') return builder.String() } diff --git a/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go b/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go index 137734c4..acbecd70 100644 --- a/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go +++ b/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go @@ -34,8 +34,8 @@ const ( FieldUpdatedAt = "updated_at" // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" - // FieldReportSequence holds the string denoting the report_sequence field in the database. - FieldReportSequence = "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" // EdgeSentinelAppBinaryFile holds the string denoting the sentinel_app_binary_file edge name in mutations. @@ -71,7 +71,7 @@ var Columns = []string{ FieldPublisher, FieldUpdatedAt, FieldCreatedAt, - FieldReportSequence, + FieldAppBinaryReportSequence, } // ValidColumn reports if the column name is valid (part of the table columns). @@ -151,9 +151,9 @@ func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() } -// ByReportSequence orders the results by the report_sequence field. -func ByReportSequence(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldReportSequence, 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() } // BySentinelLibraryField orders the results by sentinel_library field. diff --git a/internal/data/internal/ent/sentinelappbinary/where.go b/internal/data/internal/ent/sentinelappbinary/where.go index 1008426d..8d6bde8e 100644 --- a/internal/data/internal/ent/sentinelappbinary/where.go +++ b/internal/data/internal/ent/sentinelappbinary/where.go @@ -8,58 +8,56 @@ import ( "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.SentinelAppBinary { +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 model.InternalID) predicate.SentinelAppBinary { +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 model.InternalID) predicate.SentinelAppBinary { +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 ...model.InternalID) predicate.SentinelAppBinary { +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 ...model.InternalID) predicate.SentinelAppBinary { +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 model.InternalID) predicate.SentinelAppBinary { +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 model.InternalID) predicate.SentinelAppBinary { +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 model.InternalID) predicate.SentinelAppBinary { +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 model.InternalID) predicate.SentinelAppBinary { +func IDLTE(id int) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldLTE(FieldID, id)) } // SentinelLibraryID applies equality check predicate on the "sentinel_library_id" field. It's identical to SentinelLibraryIDEQ. -func SentinelLibraryID(v model.InternalID) predicate.SentinelAppBinary { - vc := int64(v) - return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, vc)) +func SentinelLibraryID(v int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, v)) } // GeneratedID applies equality check predicate on the "generated_id" field. It's identical to GeneratedIDEQ. @@ -107,39 +105,29 @@ func CreatedAt(v time.Time) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldEQ(FieldCreatedAt, v)) } -// ReportSequence applies equality check predicate on the "report_sequence" field. It's identical to ReportSequenceEQ. -func ReportSequence(v int64) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldEQ(FieldReportSequence, 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)) } // SentinelLibraryIDEQ applies the EQ predicate on the "sentinel_library_id" field. -func SentinelLibraryIDEQ(v model.InternalID) predicate.SentinelAppBinary { - vc := int64(v) - return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, vc)) +func SentinelLibraryIDEQ(v int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, v)) } // SentinelLibraryIDNEQ applies the NEQ predicate on the "sentinel_library_id" field. -func SentinelLibraryIDNEQ(v model.InternalID) predicate.SentinelAppBinary { - vc := int64(v) - return predicate.SentinelAppBinary(sql.FieldNEQ(FieldSentinelLibraryID, vc)) +func SentinelLibraryIDNEQ(v int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNEQ(FieldSentinelLibraryID, v)) } // SentinelLibraryIDIn applies the In predicate on the "sentinel_library_id" field. -func SentinelLibraryIDIn(vs ...model.InternalID) predicate.SentinelAppBinary { - v := make([]any, len(vs)) - for i := range v { - v[i] = int64(vs[i]) - } - return predicate.SentinelAppBinary(sql.FieldIn(FieldSentinelLibraryID, v...)) +func SentinelLibraryIDIn(vs ...int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldIn(FieldSentinelLibraryID, vs...)) } // SentinelLibraryIDNotIn applies the NotIn predicate on the "sentinel_library_id" field. -func SentinelLibraryIDNotIn(vs ...model.InternalID) predicate.SentinelAppBinary { - v := make([]any, len(vs)) - for i := range v { - v[i] = int64(vs[i]) - } - return predicate.SentinelAppBinary(sql.FieldNotIn(FieldSentinelLibraryID, v...)) +func SentinelLibraryIDNotIn(vs ...int) predicate.SentinelAppBinary { + return predicate.SentinelAppBinary(sql.FieldNotIn(FieldSentinelLibraryID, vs...)) } // GeneratedIDEQ applies the EQ predicate on the "generated_id" field. @@ -637,44 +625,44 @@ func CreatedAtLTE(v time.Time) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldLTE(FieldCreatedAt, v)) } -// ReportSequenceEQ applies the EQ predicate on the "report_sequence" field. -func ReportSequenceEQ(v int64) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldEQ(FieldReportSequence, 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)) } -// ReportSequenceNEQ applies the NEQ predicate on the "report_sequence" field. -func ReportSequenceNEQ(v int64) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldNEQ(FieldReportSequence, 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)) } -// ReportSequenceIn applies the In predicate on the "report_sequence" field. -func ReportSequenceIn(vs ...int64) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldIn(FieldReportSequence, vs...)) +// 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...)) } -// ReportSequenceNotIn applies the NotIn predicate on the "report_sequence" field. -func ReportSequenceNotIn(vs ...int64) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldNotIn(FieldReportSequence, 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...)) } -// ReportSequenceGT applies the GT predicate on the "report_sequence" field. -func ReportSequenceGT(v int64) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldGT(FieldReportSequence, v)) +// 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)) } -// ReportSequenceGTE applies the GTE predicate on the "report_sequence" field. -func ReportSequenceGTE(v int64) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldGTE(FieldReportSequence, 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)) } -// ReportSequenceLT applies the LT predicate on the "report_sequence" field. -func ReportSequenceLT(v int64) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldLT(FieldReportSequence, 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)) } -// ReportSequenceLTE applies the LTE predicate on the "report_sequence" field. -func ReportSequenceLTE(v int64) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldLTE(FieldReportSequence, 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)) } // HasSentinelLibrary applies the HasEdge predicate on the "sentinel_library" edge. diff --git a/internal/data/internal/ent/sentinelappbinary_create.go b/internal/data/internal/ent/sentinelappbinary_create.go index 65d95248..fc9aeaec 100644 --- a/internal/data/internal/ent/sentinelappbinary_create.go +++ b/internal/data/internal/ent/sentinelappbinary_create.go @@ -14,7 +14,6 @@ import ( "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/sentinellibrary" - "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryCreate is the builder for creating a SentinelAppBinary entity. @@ -26,8 +25,8 @@ type SentinelAppBinaryCreate struct { } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (sabc *SentinelAppBinaryCreate) SetSentinelLibraryID(mi model.InternalID) *SentinelAppBinaryCreate { - sabc.mutation.SetSentinelLibraryID(mi) +func (sabc *SentinelAppBinaryCreate) SetSentinelLibraryID(i int) *SentinelAppBinaryCreate { + sabc.mutation.SetSentinelLibraryID(i) return sabc } @@ -133,15 +132,9 @@ func (sabc *SentinelAppBinaryCreate) SetNillableCreatedAt(t *time.Time) *Sentine return sabc } -// SetReportSequence sets the "report_sequence" field. -func (sabc *SentinelAppBinaryCreate) SetReportSequence(i int64) *SentinelAppBinaryCreate { - sabc.mutation.SetReportSequence(i) - return sabc -} - -// SetID sets the "id" field. -func (sabc *SentinelAppBinaryCreate) SetID(mi model.InternalID) *SentinelAppBinaryCreate { - sabc.mutation.SetID(mi) +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (sabc *SentinelAppBinaryCreate) SetAppBinaryReportSequence(i int64) *SentinelAppBinaryCreate { + sabc.mutation.SetAppBinaryReportSequence(i) return sabc } @@ -151,14 +144,14 @@ func (sabc *SentinelAppBinaryCreate) SetSentinelLibrary(s *SentinelLibrary) *Sen } // AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (sabc *SentinelAppBinaryCreate) AddSentinelAppBinaryFileIDs(ids ...model.InternalID) *SentinelAppBinaryCreate { +func (sabc *SentinelAppBinaryCreate) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryCreate { sabc.mutation.AddSentinelAppBinaryFileIDs(ids...) return sabc } // AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. func (sabc *SentinelAppBinaryCreate) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryCreate { - ids := make([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -230,8 +223,8 @@ func (sabc *SentinelAppBinaryCreate) check() error { 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.ReportSequence(); !ok { - return &ValidationError{Name: "report_sequence", err: errors.New(`ent: missing required field "SentinelAppBinary.report_sequence"`)} + 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"`)} } if len(sabc.mutation.SentinelLibraryIDs()) == 0 { return &ValidationError{Name: "sentinel_library", err: errors.New(`ent: missing required edge "SentinelAppBinary.sentinel_library"`)} @@ -250,10 +243,8 @@ func (sabc *SentinelAppBinaryCreate) sqlSave(ctx context.Context) (*SentinelAppB } return nil, err } - if _spec.ID.Value != _node.ID { - id := _spec.ID.Value.(int64) - _node.ID = model.InternalID(id) - } + id := _spec.ID.Value.(int64) + _node.ID = int(id) sabc.mutation.id = &_node.ID sabc.mutation.done = true return _node, nil @@ -262,13 +253,9 @@ func (sabc *SentinelAppBinaryCreate) sqlSave(ctx context.Context) (*SentinelAppB func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph.CreateSpec) { var ( _node = &SentinelAppBinary{config: sabc.config} - _spec = sqlgraph.NewCreateSpec(sentinelappbinary.Table, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64)) + _spec = sqlgraph.NewCreateSpec(sentinelappbinary.Table, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt)) ) _spec.OnConflict = sabc.conflict - if id, ok := sabc.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = id - } if value, ok := sabc.mutation.GeneratedID(); ok { _spec.SetField(sentinelappbinary.FieldGeneratedID, field.TypeString, value) _node.GeneratedID = value @@ -305,9 +292,9 @@ func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph _spec.SetField(sentinelappbinary.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } - if value, ok := sabc.mutation.ReportSequence(); ok { - _spec.SetField(sentinelappbinary.FieldReportSequence, field.TypeInt64, value) - _node.ReportSequence = value + if value, ok := sabc.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) + _node.AppBinaryReportSequence = value } if nodes := sabc.mutation.SentinelLibraryIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ @@ -317,7 +304,7 @@ func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph Columns: []string{sentinelappbinary.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -334,7 +321,7 @@ func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -395,7 +382,7 @@ type ( ) // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (u *SentinelAppBinaryUpsert) SetSentinelLibraryID(v model.InternalID) *SentinelAppBinaryUpsert { +func (u *SentinelAppBinaryUpsert) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsert { u.Set(sentinelappbinary.FieldSentinelLibraryID, v) return u } @@ -544,42 +531,34 @@ func (u *SentinelAppBinaryUpsert) UpdateCreatedAt() *SentinelAppBinaryUpsert { return u } -// SetReportSequence sets the "report_sequence" field. -func (u *SentinelAppBinaryUpsert) SetReportSequence(v int64) *SentinelAppBinaryUpsert { - u.Set(sentinelappbinary.FieldReportSequence, v) +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryUpsert) SetAppBinaryReportSequence(v int64) *SentinelAppBinaryUpsert { + u.Set(sentinelappbinary.FieldAppBinaryReportSequence, v) return u } -// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. -func (u *SentinelAppBinaryUpsert) UpdateReportSequence() *SentinelAppBinaryUpsert { - u.SetExcluded(sentinelappbinary.FieldReportSequence) +// 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 } -// AddReportSequence adds v to the "report_sequence" field. -func (u *SentinelAppBinaryUpsert) AddReportSequence(v int64) *SentinelAppBinaryUpsert { - u.Add(sentinelappbinary.FieldReportSequence, v) +// 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 except the ID field. +// 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(), -// sql.ResolveWith(func(u *sql.UpdateSet) { -// u.SetIgnore(sentinelappbinary.FieldID) -// }), // ). // Exec(ctx) func (u *SentinelAppBinaryUpsertOne) UpdateNewValues() *SentinelAppBinaryUpsertOne { 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(sentinelappbinary.FieldID) - } - })) return u } @@ -611,7 +590,7 @@ func (u *SentinelAppBinaryUpsertOne) Update(set func(*SentinelAppBinaryUpsert)) } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (u *SentinelAppBinaryUpsertOne) SetSentinelLibraryID(v model.InternalID) *SentinelAppBinaryUpsertOne { +func (u *SentinelAppBinaryUpsertOne) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsertOne { return u.Update(func(s *SentinelAppBinaryUpsert) { s.SetSentinelLibraryID(v) }) @@ -785,24 +764,24 @@ func (u *SentinelAppBinaryUpsertOne) UpdateCreatedAt() *SentinelAppBinaryUpsertO }) } -// SetReportSequence sets the "report_sequence" field. -func (u *SentinelAppBinaryUpsertOne) SetReportSequence(v int64) *SentinelAppBinaryUpsertOne { +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryUpsertOne) SetAppBinaryReportSequence(v int64) *SentinelAppBinaryUpsertOne { return u.Update(func(s *SentinelAppBinaryUpsert) { - s.SetReportSequence(v) + s.SetAppBinaryReportSequence(v) }) } -// AddReportSequence adds v to the "report_sequence" field. -func (u *SentinelAppBinaryUpsertOne) AddReportSequence(v int64) *SentinelAppBinaryUpsertOne { +// AddAppBinaryReportSequence adds v to the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryUpsertOne) AddAppBinaryReportSequence(v int64) *SentinelAppBinaryUpsertOne { return u.Update(func(s *SentinelAppBinaryUpsert) { - s.AddReportSequence(v) + s.AddAppBinaryReportSequence(v) }) } -// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. -func (u *SentinelAppBinaryUpsertOne) UpdateReportSequence() *SentinelAppBinaryUpsertOne { +// 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.UpdateReportSequence() + s.UpdateAppBinaryReportSequence() }) } @@ -822,7 +801,7 @@ func (u *SentinelAppBinaryUpsertOne) ExecX(ctx context.Context) { } // Exec executes the UPSERT query and returns the inserted/updated ID. -func (u *SentinelAppBinaryUpsertOne) ID(ctx context.Context) (id model.InternalID, err error) { +func (u *SentinelAppBinaryUpsertOne) ID(ctx context.Context) (id int, err error) { node, err := u.create.Save(ctx) if err != nil { return id, err @@ -831,7 +810,7 @@ func (u *SentinelAppBinaryUpsertOne) ID(ctx context.Context) (id model.InternalI } // IDX is like ID, but panics if an error occurs. -func (u *SentinelAppBinaryUpsertOne) IDX(ctx context.Context) model.InternalID { +func (u *SentinelAppBinaryUpsertOne) IDX(ctx context.Context) int { id, err := u.ID(ctx) if err != nil { panic(err) @@ -886,9 +865,9 @@ func (sabcb *SentinelAppBinaryCreateBulk) Save(ctx context.Context) ([]*Sentinel return nil, err } mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil && nodes[i].ID == 0 { + if specs[i].ID.Value != nil { id := specs[i].ID.Value.(int64) - nodes[i].ID = model.InternalID(id) + nodes[i].ID = int(id) } mutation.done = true return nodes[i], nil @@ -976,20 +955,10 @@ type SentinelAppBinaryUpsertBulk struct { // client.SentinelAppBinary.Create(). // OnConflict( // sql.ResolveWithNewValues(), -// sql.ResolveWith(func(u *sql.UpdateSet) { -// u.SetIgnore(sentinelappbinary.FieldID) -// }), // ). // Exec(ctx) func (u *SentinelAppBinaryUpsertBulk) UpdateNewValues() *SentinelAppBinaryUpsertBulk { 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(sentinelappbinary.FieldID) - } - } - })) return u } @@ -1021,7 +990,7 @@ func (u *SentinelAppBinaryUpsertBulk) Update(set func(*SentinelAppBinaryUpsert)) } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (u *SentinelAppBinaryUpsertBulk) SetSentinelLibraryID(v model.InternalID) *SentinelAppBinaryUpsertBulk { +func (u *SentinelAppBinaryUpsertBulk) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsertBulk { return u.Update(func(s *SentinelAppBinaryUpsert) { s.SetSentinelLibraryID(v) }) @@ -1195,24 +1164,24 @@ func (u *SentinelAppBinaryUpsertBulk) UpdateCreatedAt() *SentinelAppBinaryUpsert }) } -// SetReportSequence sets the "report_sequence" field. -func (u *SentinelAppBinaryUpsertBulk) SetReportSequence(v int64) *SentinelAppBinaryUpsertBulk { +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryUpsertBulk) SetAppBinaryReportSequence(v int64) *SentinelAppBinaryUpsertBulk { return u.Update(func(s *SentinelAppBinaryUpsert) { - s.SetReportSequence(v) + s.SetAppBinaryReportSequence(v) }) } -// AddReportSequence adds v to the "report_sequence" field. -func (u *SentinelAppBinaryUpsertBulk) AddReportSequence(v int64) *SentinelAppBinaryUpsertBulk { +// AddAppBinaryReportSequence adds v to the "app_binary_report_sequence" field. +func (u *SentinelAppBinaryUpsertBulk) AddAppBinaryReportSequence(v int64) *SentinelAppBinaryUpsertBulk { return u.Update(func(s *SentinelAppBinaryUpsert) { - s.AddReportSequence(v) + s.AddAppBinaryReportSequence(v) }) } -// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. -func (u *SentinelAppBinaryUpsertBulk) UpdateReportSequence() *SentinelAppBinaryUpsertBulk { +// 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.UpdateReportSequence() + s.UpdateAppBinaryReportSequence() }) } diff --git a/internal/data/internal/ent/sentinelappbinary_delete.go b/internal/data/internal/ent/sentinelappbinary_delete.go index b5b67825..34ba2f90 100644 --- a/internal/data/internal/ent/sentinelappbinary_delete.go +++ b/internal/data/internal/ent/sentinelappbinary_delete.go @@ -40,7 +40,7 @@ func (sabd *SentinelAppBinaryDelete) ExecX(ctx context.Context) int { } func (sabd *SentinelAppBinaryDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(sentinelappbinary.Table, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64)) + _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 { diff --git a/internal/data/internal/ent/sentinelappbinary_query.go b/internal/data/internal/ent/sentinelappbinary_query.go index f76c693e..14486346 100644 --- a/internal/data/internal/ent/sentinelappbinary_query.go +++ b/internal/data/internal/ent/sentinelappbinary_query.go @@ -16,7 +16,6 @@ import ( "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/sentinellibrary" - "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryQuery is the builder for querying SentinelAppBinary entities. @@ -132,8 +131,8 @@ func (sabq *SentinelAppBinaryQuery) FirstX(ctx context.Context) *SentinelAppBina // 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 model.InternalID, err error) { - var ids []model.InternalID +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 } @@ -145,7 +144,7 @@ func (sabq *SentinelAppBinaryQuery) FirstID(ctx context.Context) (id model.Inter } // FirstIDX is like FirstID, but panics if an error occurs. -func (sabq *SentinelAppBinaryQuery) FirstIDX(ctx context.Context) model.InternalID { +func (sabq *SentinelAppBinaryQuery) FirstIDX(ctx context.Context) int { id, err := sabq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -183,8 +182,8 @@ func (sabq *SentinelAppBinaryQuery) OnlyX(ctx context.Context) *SentinelAppBinar // 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 model.InternalID, err error) { - var ids []model.InternalID +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 } @@ -200,7 +199,7 @@ func (sabq *SentinelAppBinaryQuery) OnlyID(ctx context.Context) (id model.Intern } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (sabq *SentinelAppBinaryQuery) OnlyIDX(ctx context.Context) model.InternalID { +func (sabq *SentinelAppBinaryQuery) OnlyIDX(ctx context.Context) int { id, err := sabq.OnlyID(ctx) if err != nil { panic(err) @@ -228,7 +227,7 @@ func (sabq *SentinelAppBinaryQuery) AllX(ctx context.Context) []*SentinelAppBina } // IDs executes the query and returns a list of SentinelAppBinary IDs. -func (sabq *SentinelAppBinaryQuery) IDs(ctx context.Context) (ids []model.InternalID, err error) { +func (sabq *SentinelAppBinaryQuery) IDs(ctx context.Context) (ids []int, err error) { if sabq.ctx.Unique == nil && sabq.path != nil { sabq.Unique(true) } @@ -240,7 +239,7 @@ func (sabq *SentinelAppBinaryQuery) IDs(ctx context.Context) (ids []model.Intern } // IDsX is like IDs, but panics if an error occurs. -func (sabq *SentinelAppBinaryQuery) IDsX(ctx context.Context) []model.InternalID { +func (sabq *SentinelAppBinaryQuery) IDsX(ctx context.Context) []int { ids, err := sabq.IDs(ctx) if err != nil { panic(err) @@ -336,7 +335,7 @@ func (sabq *SentinelAppBinaryQuery) WithSentinelAppBinaryFile(opts ...func(*Sent // Example: // // var v []struct { -// SentinelLibraryID model.InternalID `json:"sentinel_library_id,omitempty"` +// SentinelLibraryID int `json:"sentinel_library_id,omitempty"` // Count int `json:"count,omitempty"` // } // @@ -359,7 +358,7 @@ func (sabq *SentinelAppBinaryQuery) GroupBy(field string, fields ...string) *Sen // Example: // // var v []struct { -// SentinelLibraryID model.InternalID `json:"sentinel_library_id,omitempty"` +// SentinelLibraryID int `json:"sentinel_library_id,omitempty"` // } // // client.SentinelAppBinary.Query(). @@ -450,8 +449,8 @@ func (sabq *SentinelAppBinaryQuery) sqlAll(ctx context.Context, hooks ...queryHo } func (sabq *SentinelAppBinaryQuery) loadSentinelLibrary(ctx context.Context, query *SentinelLibraryQuery, nodes []*SentinelAppBinary, init func(*SentinelAppBinary), assign func(*SentinelAppBinary, *SentinelLibrary)) error { - ids := make([]model.InternalID, 0, len(nodes)) - nodeids := make(map[model.InternalID][]*SentinelAppBinary) + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*SentinelAppBinary) for i := range nodes { fk := nodes[i].SentinelLibraryID if _, ok := nodeids[fk]; !ok { @@ -480,7 +479,7 @@ func (sabq *SentinelAppBinaryQuery) loadSentinelLibrary(ctx context.Context, que } func (sabq *SentinelAppBinaryQuery) loadSentinelAppBinaryFile(ctx context.Context, query *SentinelAppBinaryFileQuery, nodes []*SentinelAppBinary, init func(*SentinelAppBinary), assign func(*SentinelAppBinary, *SentinelAppBinaryFile)) error { fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[model.InternalID]*SentinelAppBinary) + nodeids := make(map[int]*SentinelAppBinary) for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] @@ -519,7 +518,7 @@ func (sabq *SentinelAppBinaryQuery) sqlCount(ctx context.Context) (int, error) { } func (sabq *SentinelAppBinaryQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64)) + _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 diff --git a/internal/data/internal/ent/sentinelappbinary_update.go b/internal/data/internal/ent/sentinelappbinary_update.go index 9c2f91c5..241f2d67 100644 --- a/internal/data/internal/ent/sentinelappbinary_update.go +++ b/internal/data/internal/ent/sentinelappbinary_update.go @@ -15,7 +15,6 @@ import ( "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/sentinellibrary" - "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryUpdate is the builder for updating SentinelAppBinary entities. @@ -32,15 +31,15 @@ func (sabu *SentinelAppBinaryUpdate) Where(ps ...predicate.SentinelAppBinary) *S } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (sabu *SentinelAppBinaryUpdate) SetSentinelLibraryID(mi model.InternalID) *SentinelAppBinaryUpdate { - sabu.mutation.SetSentinelLibraryID(mi) +func (sabu *SentinelAppBinaryUpdate) SetSentinelLibraryID(i int) *SentinelAppBinaryUpdate { + sabu.mutation.SetSentinelLibraryID(i) return sabu } // SetNillableSentinelLibraryID sets the "sentinel_library_id" field if the given value is not nil. -func (sabu *SentinelAppBinaryUpdate) SetNillableSentinelLibraryID(mi *model.InternalID) *SentinelAppBinaryUpdate { - if mi != nil { - sabu.SetSentinelLibraryID(*mi) +func (sabu *SentinelAppBinaryUpdate) SetNillableSentinelLibraryID(i *int) *SentinelAppBinaryUpdate { + if i != nil { + sabu.SetSentinelLibraryID(*i) } return sabu } @@ -194,24 +193,24 @@ func (sabu *SentinelAppBinaryUpdate) SetNillableCreatedAt(t *time.Time) *Sentine return sabu } -// SetReportSequence sets the "report_sequence" field. -func (sabu *SentinelAppBinaryUpdate) SetReportSequence(i int64) *SentinelAppBinaryUpdate { - sabu.mutation.ResetReportSequence() - sabu.mutation.SetReportSequence(i) +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (sabu *SentinelAppBinaryUpdate) SetAppBinaryReportSequence(i int64) *SentinelAppBinaryUpdate { + sabu.mutation.ResetAppBinaryReportSequence() + sabu.mutation.SetAppBinaryReportSequence(i) return sabu } -// SetNillableReportSequence sets the "report_sequence" field if the given value is not nil. -func (sabu *SentinelAppBinaryUpdate) SetNillableReportSequence(i *int64) *SentinelAppBinaryUpdate { +// 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.SetReportSequence(*i) + sabu.SetAppBinaryReportSequence(*i) } return sabu } -// AddReportSequence adds i to the "report_sequence" field. -func (sabu *SentinelAppBinaryUpdate) AddReportSequence(i int64) *SentinelAppBinaryUpdate { - sabu.mutation.AddReportSequence(i) +// AddAppBinaryReportSequence adds i to the "app_binary_report_sequence" field. +func (sabu *SentinelAppBinaryUpdate) AddAppBinaryReportSequence(i int64) *SentinelAppBinaryUpdate { + sabu.mutation.AddAppBinaryReportSequence(i) return sabu } @@ -221,14 +220,14 @@ func (sabu *SentinelAppBinaryUpdate) SetSentinelLibrary(s *SentinelLibrary) *Sen } // AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (sabu *SentinelAppBinaryUpdate) AddSentinelAppBinaryFileIDs(ids ...model.InternalID) *SentinelAppBinaryUpdate { +func (sabu *SentinelAppBinaryUpdate) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdate { sabu.mutation.AddSentinelAppBinaryFileIDs(ids...) return sabu } // AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. func (sabu *SentinelAppBinaryUpdate) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdate { - ids := make([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -253,14 +252,14 @@ func (sabu *SentinelAppBinaryUpdate) ClearSentinelAppBinaryFile() *SentinelAppBi } // RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to SentinelAppBinaryFile entities by IDs. -func (sabu *SentinelAppBinaryUpdate) RemoveSentinelAppBinaryFileIDs(ids ...model.InternalID) *SentinelAppBinaryUpdate { +func (sabu *SentinelAppBinaryUpdate) RemoveSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdate { sabu.mutation.RemoveSentinelAppBinaryFileIDs(ids...) return sabu } // RemoveSentinelAppBinaryFile removes "sentinel_app_binary_file" edges to SentinelAppBinaryFile entities. func (sabu *SentinelAppBinaryUpdate) RemoveSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdate { - ids := make([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -315,7 +314,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er if err := sabu.check(); err != nil { return n, err } - _spec := sqlgraph.NewUpdateSpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64)) + _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 { @@ -365,11 +364,11 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er if value, ok := sabu.mutation.CreatedAt(); ok { _spec.SetField(sentinelappbinary.FieldCreatedAt, field.TypeTime, value) } - if value, ok := sabu.mutation.ReportSequence(); ok { - _spec.SetField(sentinelappbinary.FieldReportSequence, field.TypeInt64, value) + if value, ok := sabu.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) } - if value, ok := sabu.mutation.AddedReportSequence(); ok { - _spec.AddField(sentinelappbinary.FieldReportSequence, field.TypeInt64, value) + if value, ok := sabu.mutation.AddedAppBinaryReportSequence(); ok { + _spec.AddField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) } if sabu.mutation.SentinelLibraryCleared() { edge := &sqlgraph.EdgeSpec{ @@ -379,7 +378,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er Columns: []string{sentinelappbinary.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -392,7 +391,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er Columns: []string{sentinelappbinary.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -408,7 +407,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -421,7 +420,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -437,7 +436,7 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -466,15 +465,15 @@ type SentinelAppBinaryUpdateOne struct { } // SetSentinelLibraryID sets the "sentinel_library_id" field. -func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelLibraryID(mi model.InternalID) *SentinelAppBinaryUpdateOne { - sabuo.mutation.SetSentinelLibraryID(mi) +func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelLibraryID(i int) *SentinelAppBinaryUpdateOne { + sabuo.mutation.SetSentinelLibraryID(i) return sabuo } // SetNillableSentinelLibraryID sets the "sentinel_library_id" field if the given value is not nil. -func (sabuo *SentinelAppBinaryUpdateOne) SetNillableSentinelLibraryID(mi *model.InternalID) *SentinelAppBinaryUpdateOne { - if mi != nil { - sabuo.SetSentinelLibraryID(*mi) +func (sabuo *SentinelAppBinaryUpdateOne) SetNillableSentinelLibraryID(i *int) *SentinelAppBinaryUpdateOne { + if i != nil { + sabuo.SetSentinelLibraryID(*i) } return sabuo } @@ -628,24 +627,24 @@ func (sabuo *SentinelAppBinaryUpdateOne) SetNillableCreatedAt(t *time.Time) *Sen return sabuo } -// SetReportSequence sets the "report_sequence" field. -func (sabuo *SentinelAppBinaryUpdateOne) SetReportSequence(i int64) *SentinelAppBinaryUpdateOne { - sabuo.mutation.ResetReportSequence() - sabuo.mutation.SetReportSequence(i) +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetAppBinaryReportSequence(i int64) *SentinelAppBinaryUpdateOne { + sabuo.mutation.ResetAppBinaryReportSequence() + sabuo.mutation.SetAppBinaryReportSequence(i) return sabuo } -// SetNillableReportSequence sets the "report_sequence" field if the given value is not nil. -func (sabuo *SentinelAppBinaryUpdateOne) SetNillableReportSequence(i *int64) *SentinelAppBinaryUpdateOne { +// 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.SetReportSequence(*i) + sabuo.SetAppBinaryReportSequence(*i) } return sabuo } -// AddReportSequence adds i to the "report_sequence" field. -func (sabuo *SentinelAppBinaryUpdateOne) AddReportSequence(i int64) *SentinelAppBinaryUpdateOne { - sabuo.mutation.AddReportSequence(i) +// AddAppBinaryReportSequence adds i to the "app_binary_report_sequence" field. +func (sabuo *SentinelAppBinaryUpdateOne) AddAppBinaryReportSequence(i int64) *SentinelAppBinaryUpdateOne { + sabuo.mutation.AddAppBinaryReportSequence(i) return sabuo } @@ -655,14 +654,14 @@ func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelLibrary(s *SentinelLibrary) } // AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelAppBinaryFileIDs(ids ...model.InternalID) *SentinelAppBinaryUpdateOne { +func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdateOne { sabuo.mutation.AddSentinelAppBinaryFileIDs(ids...) return sabuo } // AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdateOne { - ids := make([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -687,14 +686,14 @@ func (sabuo *SentinelAppBinaryUpdateOne) ClearSentinelAppBinaryFile() *SentinelA } // RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to SentinelAppBinaryFile entities by IDs. -func (sabuo *SentinelAppBinaryUpdateOne) RemoveSentinelAppBinaryFileIDs(ids ...model.InternalID) *SentinelAppBinaryUpdateOne { +func (sabuo *SentinelAppBinaryUpdateOne) RemoveSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdateOne { sabuo.mutation.RemoveSentinelAppBinaryFileIDs(ids...) return sabuo } // RemoveSentinelAppBinaryFile removes "sentinel_app_binary_file" edges to SentinelAppBinaryFile entities. func (sabuo *SentinelAppBinaryUpdateOne) RemoveSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdateOne { - ids := make([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -762,7 +761,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se if err := sabuo.check(); err != nil { return _node, err } - _spec := sqlgraph.NewUpdateSpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64)) + _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`)} @@ -829,11 +828,11 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se if value, ok := sabuo.mutation.CreatedAt(); ok { _spec.SetField(sentinelappbinary.FieldCreatedAt, field.TypeTime, value) } - if value, ok := sabuo.mutation.ReportSequence(); ok { - _spec.SetField(sentinelappbinary.FieldReportSequence, field.TypeInt64, value) + if value, ok := sabuo.mutation.AppBinaryReportSequence(); ok { + _spec.SetField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) } - if value, ok := sabuo.mutation.AddedReportSequence(); ok { - _spec.AddField(sentinelappbinary.FieldReportSequence, field.TypeInt64, value) + if value, ok := sabuo.mutation.AddedAppBinaryReportSequence(); ok { + _spec.AddField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) } if sabuo.mutation.SentinelLibraryCleared() { edge := &sqlgraph.EdgeSpec{ @@ -843,7 +842,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se Columns: []string{sentinelappbinary.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -856,7 +855,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se Columns: []string{sentinelappbinary.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -872,7 +871,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -885,7 +884,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -901,7 +900,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), }, } for _, k := range nodes { diff --git a/internal/data/internal/ent/sentinelappbinaryfile.go b/internal/data/internal/ent/sentinelappbinaryfile.go index 853cbee0..f50e5d8c 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile.go +++ b/internal/data/internal/ent/sentinelappbinaryfile.go @@ -11,16 +11,15 @@ import ( "entgo.io/ent/dialect/sql" "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" "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 model.InternalID `json:"id,omitempty"` + ID int `json:"id,omitempty"` // SentinelAppBinaryID holds the value of the "sentinel_app_binary_id" field. - SentinelAppBinaryID model.InternalID `json:"sentinel_app_binary_id,omitempty"` + SentinelAppBinaryID int `json:"sentinel_app_binary_id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` // SizeBytes holds the value of the "size_bytes" field. @@ -35,6 +34,8 @@ type SentinelAppBinaryFile struct { 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"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the SentinelAppBinaryFileQuery when eager-loading is set. Edges SentinelAppBinaryFileEdges `json:"edges"` @@ -68,7 +69,7 @@ func (*SentinelAppBinaryFile) scanValues(columns []string) ([]any, error) { switch columns[i] { case sentinelappbinaryfile.FieldSha256: values[i] = new([]byte) - case sentinelappbinaryfile.FieldID, sentinelappbinaryfile.FieldSentinelAppBinaryID, sentinelappbinaryfile.FieldSizeBytes: + case sentinelappbinaryfile.FieldID, sentinelappbinaryfile.FieldSentinelAppBinaryID, sentinelappbinaryfile.FieldSizeBytes, sentinelappbinaryfile.FieldAppBinaryReportSequence: values[i] = new(sql.NullInt64) case sentinelappbinaryfile.FieldName, sentinelappbinaryfile.FieldServerFilePath, sentinelappbinaryfile.FieldChunksInfo: values[i] = new(sql.NullString) @@ -90,16 +91,16 @@ func (sabf *SentinelAppBinaryFile) assignValues(columns []string, values []any) for i := range columns { switch columns[i] { case sentinelappbinaryfile.FieldID: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field id", values[i]) - } else if value.Valid { - sabf.ID = model.InternalID(value.Int64) + 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.FieldSentinelAppBinaryID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field sentinel_app_binary_id", values[i]) } else if value.Valid { - sabf.SentinelAppBinaryID = model.InternalID(value.Int64) + sabf.SentinelAppBinaryID = int(value.Int64) } case sentinelappbinaryfile.FieldName: if value, ok := values[i].(*sql.NullString); !ok { @@ -143,6 +144,12 @@ func (sabf *SentinelAppBinaryFile) assignValues(columns []string, values []any) } 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]) } @@ -207,6 +214,9 @@ func (sabf *SentinelAppBinaryFile) String() string { 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() } diff --git a/internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go b/internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go index 8614cf59..9bb26280 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go +++ b/internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go @@ -30,6 +30,8 @@ const ( 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" // EdgeSentinelAppBinary holds the string denoting the sentinel_app_binary edge name in mutations. EdgeSentinelAppBinary = "sentinel_app_binary" // Table holds the table name of the sentinelappbinaryfile in the database. @@ -54,6 +56,7 @@ var Columns = []string{ FieldChunksInfo, FieldUpdatedAt, FieldCreatedAt, + FieldAppBinaryReportSequence, } // ValidColumn reports if the column name is valid (part of the table columns). @@ -118,6 +121,11 @@ 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() +} + // BySentinelAppBinaryField orders the results by sentinel_app_binary field. func BySentinelAppBinaryField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { diff --git a/internal/data/internal/ent/sentinelappbinaryfile/where.go b/internal/data/internal/ent/sentinelappbinaryfile/where.go index 03bb1842..f6f1ad62 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile/where.go +++ b/internal/data/internal/ent/sentinelappbinaryfile/where.go @@ -8,58 +8,56 @@ import ( "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.SentinelAppBinaryFile { +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 model.InternalID) predicate.SentinelAppBinaryFile { +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 model.InternalID) predicate.SentinelAppBinaryFile { +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 ...model.InternalID) predicate.SentinelAppBinaryFile { +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 ...model.InternalID) predicate.SentinelAppBinaryFile { +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 model.InternalID) predicate.SentinelAppBinaryFile { +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 model.InternalID) predicate.SentinelAppBinaryFile { +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 model.InternalID) predicate.SentinelAppBinaryFile { +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 model.InternalID) predicate.SentinelAppBinaryFile { +func IDLTE(id int) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldID, id)) } // SentinelAppBinaryID applies equality check predicate on the "sentinel_app_binary_id" field. It's identical to SentinelAppBinaryIDEQ. -func SentinelAppBinaryID(v model.InternalID) predicate.SentinelAppBinaryFile { - vc := int64(v) - return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, vc)) +func SentinelAppBinaryID(v int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, v)) } // Name applies equality check predicate on the "name" field. It's identical to NameEQ. @@ -97,34 +95,29 @@ 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)) +} + // SentinelAppBinaryIDEQ applies the EQ predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDEQ(v model.InternalID) predicate.SentinelAppBinaryFile { - vc := int64(v) - return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, vc)) +func SentinelAppBinaryIDEQ(v int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, v)) } // SentinelAppBinaryIDNEQ applies the NEQ predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDNEQ(v model.InternalID) predicate.SentinelAppBinaryFile { - vc := int64(v) - return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldSentinelAppBinaryID, vc)) +func SentinelAppBinaryIDNEQ(v int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldSentinelAppBinaryID, v)) } // SentinelAppBinaryIDIn applies the In predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDIn(vs ...model.InternalID) predicate.SentinelAppBinaryFile { - v := make([]any, len(vs)) - for i := range v { - v[i] = int64(vs[i]) - } - return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldSentinelAppBinaryID, v...)) +func SentinelAppBinaryIDIn(vs ...int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldSentinelAppBinaryID, vs...)) } // SentinelAppBinaryIDNotIn applies the NotIn predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDNotIn(vs ...model.InternalID) predicate.SentinelAppBinaryFile { - v := make([]any, len(vs)) - for i := range v { - v[i] = int64(vs[i]) - } - return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldSentinelAppBinaryID, v...)) +func SentinelAppBinaryIDNotIn(vs ...int) predicate.SentinelAppBinaryFile { + return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldSentinelAppBinaryID, vs...)) } // NameEQ applies the EQ predicate on the "name" field. @@ -492,6 +485,46 @@ 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)) +} + // HasSentinelAppBinary applies the HasEdge predicate on the "sentinel_app_binary" edge. func HasSentinelAppBinary() predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(func(s *sql.Selector) { diff --git a/internal/data/internal/ent/sentinelappbinaryfile_create.go b/internal/data/internal/ent/sentinelappbinaryfile_create.go index 3e2e0e1d..446b0c5b 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile_create.go +++ b/internal/data/internal/ent/sentinelappbinaryfile_create.go @@ -13,7 +13,6 @@ import ( "entgo.io/ent/schema/field" "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" - "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryFileCreate is the builder for creating a SentinelAppBinaryFile entity. @@ -25,8 +24,8 @@ type SentinelAppBinaryFileCreate struct { } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (sabfc *SentinelAppBinaryFileCreate) SetSentinelAppBinaryID(mi model.InternalID) *SentinelAppBinaryFileCreate { - sabfc.mutation.SetSentinelAppBinaryID(mi) +func (sabfc *SentinelAppBinaryFileCreate) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetSentinelAppBinaryID(i) return sabfc } @@ -96,9 +95,9 @@ func (sabfc *SentinelAppBinaryFileCreate) SetNillableCreatedAt(t *time.Time) *Se return sabfc } -// SetID sets the "id" field. -func (sabfc *SentinelAppBinaryFileCreate) SetID(mi model.InternalID) *SentinelAppBinaryFileCreate { - sabfc.mutation.SetID(mi) +// SetAppBinaryReportSequence sets the "app_binary_report_sequence" field. +func (sabfc *SentinelAppBinaryFileCreate) SetAppBinaryReportSequence(i int64) *SentinelAppBinaryFileCreate { + sabfc.mutation.SetAppBinaryReportSequence(i) return sabfc } @@ -175,6 +174,9 @@ func (sabfc *SentinelAppBinaryFileCreate) check() error { 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"`)} + } if len(sabfc.mutation.SentinelAppBinaryIDs()) == 0 { return &ValidationError{Name: "sentinel_app_binary", err: errors.New(`ent: missing required edge "SentinelAppBinaryFile.sentinel_app_binary"`)} } @@ -192,10 +194,8 @@ func (sabfc *SentinelAppBinaryFileCreate) sqlSave(ctx context.Context) (*Sentine } return nil, err } - if _spec.ID.Value != _node.ID { - id := _spec.ID.Value.(int64) - _node.ID = model.InternalID(id) - } + id := _spec.ID.Value.(int64) + _node.ID = int(id) sabfc.mutation.id = &_node.ID sabfc.mutation.done = true return _node, nil @@ -204,13 +204,9 @@ func (sabfc *SentinelAppBinaryFileCreate) sqlSave(ctx context.Context) (*Sentine func (sabfc *SentinelAppBinaryFileCreate) createSpec() (*SentinelAppBinaryFile, *sqlgraph.CreateSpec) { var ( _node = &SentinelAppBinaryFile{config: sabfc.config} - _spec = sqlgraph.NewCreateSpec(sentinelappbinaryfile.Table, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64)) + _spec = sqlgraph.NewCreateSpec(sentinelappbinaryfile.Table, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt)) ) _spec.OnConflict = sabfc.conflict - if id, ok := sabfc.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = id - } if value, ok := sabfc.mutation.Name(); ok { _spec.SetField(sentinelappbinaryfile.FieldName, field.TypeString, value) _node.Name = value @@ -239,6 +235,10 @@ func (sabfc *SentinelAppBinaryFileCreate) createSpec() (*SentinelAppBinaryFile, _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 + } if nodes := sabfc.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -247,7 +247,7 @@ func (sabfc *SentinelAppBinaryFileCreate) createSpec() (*SentinelAppBinaryFile, Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -309,7 +309,7 @@ type ( ) // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (u *SentinelAppBinaryFileUpsert) SetSentinelAppBinaryID(v model.InternalID) *SentinelAppBinaryFileUpsert { +func (u *SentinelAppBinaryFileUpsert) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsert { u.Set(sentinelappbinaryfile.FieldSentinelAppBinaryID, v) return u } @@ -416,24 +416,34 @@ func (u *SentinelAppBinaryFileUpsert) UpdateCreatedAt() *SentinelAppBinaryFileUp return u } -// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. +// 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(), -// sql.ResolveWith(func(u *sql.UpdateSet) { -// u.SetIgnore(sentinelappbinaryfile.FieldID) -// }), // ). // Exec(ctx) func (u *SentinelAppBinaryFileUpsertOne) UpdateNewValues() *SentinelAppBinaryFileUpsertOne { 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(sentinelappbinaryfile.FieldID) - } - })) return u } @@ -465,7 +475,7 @@ func (u *SentinelAppBinaryFileUpsertOne) Update(set func(*SentinelAppBinaryFileU } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (u *SentinelAppBinaryFileUpsertOne) SetSentinelAppBinaryID(v model.InternalID) *SentinelAppBinaryFileUpsertOne { +func (u *SentinelAppBinaryFileUpsertOne) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsertOne { return u.Update(func(s *SentinelAppBinaryFileUpsert) { s.SetSentinelAppBinaryID(v) }) @@ -590,6 +600,27 @@ func (u *SentinelAppBinaryFileUpsertOne) UpdateCreatedAt() *SentinelAppBinaryFil }) } +// 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 { @@ -606,7 +637,7 @@ func (u *SentinelAppBinaryFileUpsertOne) ExecX(ctx context.Context) { } // Exec executes the UPSERT query and returns the inserted/updated ID. -func (u *SentinelAppBinaryFileUpsertOne) ID(ctx context.Context) (id model.InternalID, err error) { +func (u *SentinelAppBinaryFileUpsertOne) ID(ctx context.Context) (id int, err error) { node, err := u.create.Save(ctx) if err != nil { return id, err @@ -615,7 +646,7 @@ func (u *SentinelAppBinaryFileUpsertOne) ID(ctx context.Context) (id model.Inter } // IDX is like ID, but panics if an error occurs. -func (u *SentinelAppBinaryFileUpsertOne) IDX(ctx context.Context) model.InternalID { +func (u *SentinelAppBinaryFileUpsertOne) IDX(ctx context.Context) int { id, err := u.ID(ctx) if err != nil { panic(err) @@ -670,9 +701,9 @@ func (sabfcb *SentinelAppBinaryFileCreateBulk) Save(ctx context.Context) ([]*Sen return nil, err } mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil && nodes[i].ID == 0 { + if specs[i].ID.Value != nil { id := specs[i].ID.Value.(int64) - nodes[i].ID = model.InternalID(id) + nodes[i].ID = int(id) } mutation.done = true return nodes[i], nil @@ -760,20 +791,10 @@ type SentinelAppBinaryFileUpsertBulk struct { // client.SentinelAppBinaryFile.Create(). // OnConflict( // sql.ResolveWithNewValues(), -// sql.ResolveWith(func(u *sql.UpdateSet) { -// u.SetIgnore(sentinelappbinaryfile.FieldID) -// }), // ). // Exec(ctx) func (u *SentinelAppBinaryFileUpsertBulk) UpdateNewValues() *SentinelAppBinaryFileUpsertBulk { 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(sentinelappbinaryfile.FieldID) - } - } - })) return u } @@ -805,7 +826,7 @@ func (u *SentinelAppBinaryFileUpsertBulk) Update(set func(*SentinelAppBinaryFile } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (u *SentinelAppBinaryFileUpsertBulk) SetSentinelAppBinaryID(v model.InternalID) *SentinelAppBinaryFileUpsertBulk { +func (u *SentinelAppBinaryFileUpsertBulk) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsertBulk { return u.Update(func(s *SentinelAppBinaryFileUpsert) { s.SetSentinelAppBinaryID(v) }) @@ -930,6 +951,27 @@ func (u *SentinelAppBinaryFileUpsertBulk) UpdateCreatedAt() *SentinelAppBinaryFi }) } +// 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 { diff --git a/internal/data/internal/ent/sentinelappbinaryfile_delete.go b/internal/data/internal/ent/sentinelappbinaryfile_delete.go index 8365a3a4..78472628 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile_delete.go +++ b/internal/data/internal/ent/sentinelappbinaryfile_delete.go @@ -40,7 +40,7 @@ func (sabfd *SentinelAppBinaryFileDelete) ExecX(ctx context.Context) int { } func (sabfd *SentinelAppBinaryFileDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(sentinelappbinaryfile.Table, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64)) + _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 { diff --git a/internal/data/internal/ent/sentinelappbinaryfile_query.go b/internal/data/internal/ent/sentinelappbinaryfile_query.go index 321afc40..5dec5c78 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile_query.go +++ b/internal/data/internal/ent/sentinelappbinaryfile_query.go @@ -14,7 +14,6 @@ import ( "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/model" ) // SentinelAppBinaryFileQuery is the builder for querying SentinelAppBinaryFile entities. @@ -107,8 +106,8 @@ func (sabfq *SentinelAppBinaryFileQuery) FirstX(ctx context.Context) *SentinelAp // 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 model.InternalID, err error) { - var ids []model.InternalID +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 } @@ -120,7 +119,7 @@ func (sabfq *SentinelAppBinaryFileQuery) FirstID(ctx context.Context) (id model. } // FirstIDX is like FirstID, but panics if an error occurs. -func (sabfq *SentinelAppBinaryFileQuery) FirstIDX(ctx context.Context) model.InternalID { +func (sabfq *SentinelAppBinaryFileQuery) FirstIDX(ctx context.Context) int { id, err := sabfq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -158,8 +157,8 @@ func (sabfq *SentinelAppBinaryFileQuery) OnlyX(ctx context.Context) *SentinelApp // 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 model.InternalID, err error) { - var ids []model.InternalID +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 } @@ -175,7 +174,7 @@ func (sabfq *SentinelAppBinaryFileQuery) OnlyID(ctx context.Context) (id model.I } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (sabfq *SentinelAppBinaryFileQuery) OnlyIDX(ctx context.Context) model.InternalID { +func (sabfq *SentinelAppBinaryFileQuery) OnlyIDX(ctx context.Context) int { id, err := sabfq.OnlyID(ctx) if err != nil { panic(err) @@ -203,7 +202,7 @@ func (sabfq *SentinelAppBinaryFileQuery) AllX(ctx context.Context) []*SentinelAp } // IDs executes the query and returns a list of SentinelAppBinaryFile IDs. -func (sabfq *SentinelAppBinaryFileQuery) IDs(ctx context.Context) (ids []model.InternalID, err error) { +func (sabfq *SentinelAppBinaryFileQuery) IDs(ctx context.Context) (ids []int, err error) { if sabfq.ctx.Unique == nil && sabfq.path != nil { sabfq.Unique(true) } @@ -215,7 +214,7 @@ func (sabfq *SentinelAppBinaryFileQuery) IDs(ctx context.Context) (ids []model.I } // IDsX is like IDs, but panics if an error occurs. -func (sabfq *SentinelAppBinaryFileQuery) IDsX(ctx context.Context) []model.InternalID { +func (sabfq *SentinelAppBinaryFileQuery) IDsX(ctx context.Context) []int { ids, err := sabfq.IDs(ctx) if err != nil { panic(err) @@ -299,7 +298,7 @@ func (sabfq *SentinelAppBinaryFileQuery) WithSentinelAppBinary(opts ...func(*Sen // Example: // // var v []struct { -// SentinelAppBinaryID model.InternalID `json:"sentinel_app_binary_id,omitempty"` +// SentinelAppBinaryID int `json:"sentinel_app_binary_id,omitempty"` // Count int `json:"count,omitempty"` // } // @@ -322,7 +321,7 @@ func (sabfq *SentinelAppBinaryFileQuery) GroupBy(field string, fields ...string) // Example: // // var v []struct { -// SentinelAppBinaryID model.InternalID `json:"sentinel_app_binary_id,omitempty"` +// SentinelAppBinaryID int `json:"sentinel_app_binary_id,omitempty"` // } // // client.SentinelAppBinaryFile.Query(). @@ -403,8 +402,8 @@ func (sabfq *SentinelAppBinaryFileQuery) sqlAll(ctx context.Context, hooks ...qu } func (sabfq *SentinelAppBinaryFileQuery) loadSentinelAppBinary(ctx context.Context, query *SentinelAppBinaryQuery, nodes []*SentinelAppBinaryFile, init func(*SentinelAppBinaryFile), assign func(*SentinelAppBinaryFile, *SentinelAppBinary)) error { - ids := make([]model.InternalID, 0, len(nodes)) - nodeids := make(map[model.InternalID][]*SentinelAppBinaryFile) + ids := make([]int, 0, len(nodes)) + nodeids := make(map[int][]*SentinelAppBinaryFile) for i := range nodes { fk := nodes[i].SentinelAppBinaryID if _, ok := nodeids[fk]; !ok { @@ -442,7 +441,7 @@ func (sabfq *SentinelAppBinaryFileQuery) sqlCount(ctx context.Context) (int, err } func (sabfq *SentinelAppBinaryFileQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64)) + _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 diff --git a/internal/data/internal/ent/sentinelappbinaryfile_update.go b/internal/data/internal/ent/sentinelappbinaryfile_update.go index d9f140a1..1adb3377 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile_update.go +++ b/internal/data/internal/ent/sentinelappbinaryfile_update.go @@ -14,7 +14,6 @@ import ( "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/model" ) // SentinelAppBinaryFileUpdate is the builder for updating SentinelAppBinaryFile entities. @@ -31,15 +30,15 @@ func (sabfu *SentinelAppBinaryFileUpdate) Where(ps ...predicate.SentinelAppBinar } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelAppBinaryID(mi model.InternalID) *SentinelAppBinaryFileUpdate { - sabfu.mutation.SetSentinelAppBinaryID(mi) +func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileUpdate { + sabfu.mutation.SetSentinelAppBinaryID(i) return sabfu } // SetNillableSentinelAppBinaryID sets the "sentinel_app_binary_id" field if the given value is not nil. -func (sabfu *SentinelAppBinaryFileUpdate) SetNillableSentinelAppBinaryID(mi *model.InternalID) *SentinelAppBinaryFileUpdate { - if mi != nil { - sabfu.SetSentinelAppBinaryID(*mi) +func (sabfu *SentinelAppBinaryFileUpdate) SetNillableSentinelAppBinaryID(i *int) *SentinelAppBinaryFileUpdate { + if i != nil { + sabfu.SetSentinelAppBinaryID(*i) } return sabfu } @@ -139,6 +138,27 @@ func (sabfu *SentinelAppBinaryFileUpdate) SetNillableCreatedAt(t *time.Time) *Se 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 +} + // SetSentinelAppBinary sets the "sentinel_app_binary" edge to the SentinelAppBinary entity. func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelAppBinary(s *SentinelAppBinary) *SentinelAppBinaryFileUpdate { return sabfu.SetSentinelAppBinaryID(s.ID) @@ -203,7 +223,7 @@ func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, e if err := sabfu.check(); err != nil { return n, err } - _spec := sqlgraph.NewUpdateSpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64)) + _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 { @@ -238,6 +258,12 @@ func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, e 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 sabfu.mutation.SentinelAppBinaryCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -246,7 +272,7 @@ func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, e Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -259,7 +285,7 @@ func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, e Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -288,15 +314,15 @@ type SentinelAppBinaryFileUpdateOne struct { } // SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelAppBinaryID(mi model.InternalID) *SentinelAppBinaryFileUpdateOne { - sabfuo.mutation.SetSentinelAppBinaryID(mi) +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.SetSentinelAppBinaryID(i) return sabfuo } // SetNillableSentinelAppBinaryID sets the "sentinel_app_binary_id" field if the given value is not nil. -func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableSentinelAppBinaryID(mi *model.InternalID) *SentinelAppBinaryFileUpdateOne { - if mi != nil { - sabfuo.SetSentinelAppBinaryID(*mi) +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableSentinelAppBinaryID(i *int) *SentinelAppBinaryFileUpdateOne { + if i != nil { + sabfuo.SetSentinelAppBinaryID(*i) } return sabfuo } @@ -396,6 +422,27 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableCreatedAt(t *time.Time) 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 +} + // SetSentinelAppBinary sets the "sentinel_app_binary" edge to the SentinelAppBinary entity. func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelAppBinary(s *SentinelAppBinary) *SentinelAppBinaryFileUpdateOne { return sabfuo.SetSentinelAppBinaryID(s.ID) @@ -473,7 +520,7 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_nod if err := sabfuo.check(); err != nil { return _node, err } - _spec := sqlgraph.NewUpdateSpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt64)) + _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`)} @@ -525,6 +572,12 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_nod 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) + } if sabfuo.mutation.SentinelAppBinaryCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -533,7 +586,7 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_nod Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -546,7 +599,7 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_nod Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } for _, k := range nodes { diff --git a/internal/data/internal/ent/sentinelinfo.go b/internal/data/internal/ent/sentinelinfo.go index b983203d..4c540950 100644 --- a/internal/data/internal/ent/sentinelinfo.go +++ b/internal/data/internal/ent/sentinelinfo.go @@ -31,6 +31,10 @@ type SentinelInfo struct { 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"` @@ -62,7 +66,7 @@ func (*SentinelInfo) scanValues(columns []string) ([]any, error) { switch columns[i] { case sentinelinfo.FieldAlternativeUrls: values[i] = new([]byte) - case sentinelinfo.FieldID: + case sentinelinfo.FieldID, sentinelinfo.FieldLibraryReportSequence, sentinelinfo.FieldAppBinaryReportSequence: values[i] = new(sql.NullInt64) case sentinelinfo.FieldURL, sentinelinfo.FieldGetTokenPath, sentinelinfo.FieldDownloadFileBasePath: values[i] = new(sql.NullString) @@ -127,6 +131,18 @@ func (si *SentinelInfo) assignValues(columns []string, values []any) error { } 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]) } @@ -185,6 +201,12 @@ func (si *SentinelInfo) String() string { 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() } diff --git a/internal/data/internal/ent/sentinelinfo/sentinelinfo.go b/internal/data/internal/ent/sentinelinfo/sentinelinfo.go index 9e3c2d83..275dfb9d 100644 --- a/internal/data/internal/ent/sentinelinfo/sentinelinfo.go +++ b/internal/data/internal/ent/sentinelinfo/sentinelinfo.go @@ -26,6 +26,10 @@ const ( 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. @@ -48,6 +52,8 @@ var Columns = []string{ FieldDownloadFileBasePath, FieldUpdatedAt, FieldCreatedAt, + FieldLibraryReportSequence, + FieldAppBinaryReportSequence, } // ValidColumn reports if the column name is valid (part of the table columns). @@ -102,6 +108,16 @@ 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) { diff --git a/internal/data/internal/ent/sentinelinfo/where.go b/internal/data/internal/ent/sentinelinfo/where.go index acfe106c..6d20c42b 100644 --- a/internal/data/internal/ent/sentinelinfo/where.go +++ b/internal/data/internal/ent/sentinelinfo/where.go @@ -81,6 +81,16 @@ 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)) @@ -376,6 +386,86 @@ 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) { diff --git a/internal/data/internal/ent/sentinelinfo_create.go b/internal/data/internal/ent/sentinelinfo_create.go index 4681bf8f..3ca77830 100644 --- a/internal/data/internal/ent/sentinelinfo_create.go +++ b/internal/data/internal/ent/sentinelinfo_create.go @@ -84,6 +84,18 @@ func (sic *SentinelInfoCreate) SetNillableCreatedAt(t *time.Time) *SentinelInfoC 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) @@ -91,14 +103,14 @@ func (sic *SentinelInfoCreate) SetID(mi model.InternalID) *SentinelInfoCreate { } // AddSentinelLibraryIDs adds the "sentinel_library" edge to the SentinelLibrary entity by IDs. -func (sic *SentinelInfoCreate) AddSentinelLibraryIDs(ids ...model.InternalID) *SentinelInfoCreate { +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([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -164,6 +176,12 @@ func (sic *SentinelInfoCreate) check() error { 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 } @@ -221,6 +239,14 @@ func (sic *SentinelInfoCreate) createSpec() (*SentinelInfo, *sqlgraph.CreateSpec _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, @@ -229,7 +255,7 @@ func (sic *SentinelInfoCreate) createSpec() (*SentinelInfo, *sqlgraph.CreateSpec Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -373,6 +399,42 @@ func (u *SentinelInfoUpsert) UpdateCreatedAt() *SentinelInfoUpsert { 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: // @@ -519,6 +581,48 @@ func (u *SentinelInfoUpsertOne) UpdateCreatedAt() *SentinelInfoUpsertOne { }) } +// 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 { @@ -831,6 +935,48 @@ func (u *SentinelInfoUpsertBulk) UpdateCreatedAt() *SentinelInfoUpsertBulk { }) } +// 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 { diff --git a/internal/data/internal/ent/sentinelinfo_update.go b/internal/data/internal/ent/sentinelinfo_update.go index 735b406b..738ebd85 100644 --- a/internal/data/internal/ent/sentinelinfo_update.go +++ b/internal/data/internal/ent/sentinelinfo_update.go @@ -15,7 +15,6 @@ import ( "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" ) // SentinelInfoUpdate is the builder for updating SentinelInfo entities. @@ -117,15 +116,57 @@ func (siu *SentinelInfoUpdate) SetNillableCreatedAt(t *time.Time) *SentinelInfoU 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 ...model.InternalID) *SentinelInfoUpdate { +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([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -144,14 +185,14 @@ func (siu *SentinelInfoUpdate) ClearSentinelLibrary() *SentinelInfoUpdate { } // RemoveSentinelLibraryIDs removes the "sentinel_library" edge to SentinelLibrary entities by IDs. -func (siu *SentinelInfoUpdate) RemoveSentinelLibraryIDs(ids ...model.InternalID) *SentinelInfoUpdate { +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([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -232,6 +273,18 @@ func (siu *SentinelInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { 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, @@ -240,7 +293,7 @@ func (siu *SentinelInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -253,7 +306,7 @@ func (siu *SentinelInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -269,7 +322,7 @@ func (siu *SentinelInfoUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -383,15 +436,57 @@ func (siuo *SentinelInfoUpdateOne) SetNillableCreatedAt(t *time.Time) *SentinelI 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 ...model.InternalID) *SentinelInfoUpdateOne { +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([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -410,14 +505,14 @@ func (siuo *SentinelInfoUpdateOne) ClearSentinelLibrary() *SentinelInfoUpdateOne } // RemoveSentinelLibraryIDs removes the "sentinel_library" edge to SentinelLibrary entities by IDs. -func (siuo *SentinelInfoUpdateOne) RemoveSentinelLibraryIDs(ids ...model.InternalID) *SentinelInfoUpdateOne { +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([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -528,6 +623,18 @@ func (siuo *SentinelInfoUpdateOne) sqlSave(ctx context.Context) (_node *Sentinel 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, @@ -536,7 +643,7 @@ func (siuo *SentinelInfoUpdateOne) sqlSave(ctx context.Context) (_node *Sentinel Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -549,7 +656,7 @@ func (siuo *SentinelInfoUpdateOne) sqlSave(ctx context.Context) (_node *Sentinel Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -565,7 +672,7 @@ func (siuo *SentinelInfoUpdateOne) sqlSave(ctx context.Context) (_node *Sentinel Columns: []string{sentinelinfo.SentinelLibraryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), }, } for _, k := range nodes { diff --git a/internal/data/internal/ent/sentinellibrary.go b/internal/data/internal/ent/sentinellibrary.go index 647261a7..fd52d3e6 100644 --- a/internal/data/internal/ent/sentinellibrary.go +++ b/internal/data/internal/ent/sentinellibrary.go @@ -18,7 +18,7 @@ import ( type SentinelLibrary struct { config `json:"-"` // ID of the ent. - ID model.InternalID `json:"id,omitempty"` + 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. @@ -29,8 +29,8 @@ type SentinelLibrary struct { UpdatedAt time.Time `json:"updated_at,omitempty"` // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` - // ReportSequence holds the value of the "report_sequence" field. - ReportSequence int64 `json:"report_sequence,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"` @@ -73,7 +73,7 @@ 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.FieldReportSequence: + case sentinellibrary.FieldID, sentinellibrary.FieldSentinelInfoID, sentinellibrary.FieldReportedID, sentinellibrary.FieldLibraryReportSequence: values[i] = new(sql.NullInt64) case sentinellibrary.FieldDownloadBasePath: values[i] = new(sql.NullString) @@ -95,11 +95,11 @@ func (sl *SentinelLibrary) assignValues(columns []string, values []any) error { for i := range columns { switch columns[i] { case sentinellibrary.FieldID: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field id", values[i]) - } else if value.Valid { - sl.ID = model.InternalID(value.Int64) + 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]) @@ -130,11 +130,11 @@ func (sl *SentinelLibrary) assignValues(columns []string, values []any) error { } else if value.Valid { sl.CreatedAt = value.Time } - case sentinellibrary.FieldReportSequence: + case sentinellibrary.FieldLibraryReportSequence: if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field report_sequence", values[i]) + return fmt.Errorf("unexpected type %T for field library_report_sequence", values[i]) } else if value.Valid { - sl.ReportSequence = value.Int64 + sl.LibraryReportSequence = value.Int64 } default: sl.selectValues.Set(columns[i], values[i]) @@ -197,8 +197,8 @@ func (sl *SentinelLibrary) String() string { builder.WriteString("created_at=") builder.WriteString(sl.CreatedAt.Format(time.ANSIC)) builder.WriteString(", ") - builder.WriteString("report_sequence=") - builder.WriteString(fmt.Sprintf("%v", sl.ReportSequence)) + builder.WriteString("library_report_sequence=") + builder.WriteString(fmt.Sprintf("%v", sl.LibraryReportSequence)) builder.WriteByte(')') return builder.String() } diff --git a/internal/data/internal/ent/sentinellibrary/sentinellibrary.go b/internal/data/internal/ent/sentinellibrary/sentinellibrary.go index 259daf09..c17d7ede 100644 --- a/internal/data/internal/ent/sentinellibrary/sentinellibrary.go +++ b/internal/data/internal/ent/sentinellibrary/sentinellibrary.go @@ -24,8 +24,8 @@ const ( FieldUpdatedAt = "updated_at" // FieldCreatedAt holds the string denoting the created_at field in the database. FieldCreatedAt = "created_at" - // FieldReportSequence holds the string denoting the report_sequence field in the database. - FieldReportSequence = "report_sequence" + // 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" // EdgeSentinelAppBinary holds the string denoting the sentinel_app_binary edge name in mutations. @@ -56,7 +56,7 @@ var Columns = []string{ FieldDownloadBasePath, FieldUpdatedAt, FieldCreatedAt, - FieldReportSequence, + FieldLibraryReportSequence, } // ValidColumn reports if the column name is valid (part of the table columns). @@ -111,9 +111,9 @@ func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() } -// ByReportSequence orders the results by the report_sequence field. -func ByReportSequence(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldReportSequence, 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. diff --git a/internal/data/internal/ent/sentinellibrary/where.go b/internal/data/internal/ent/sentinellibrary/where.go index 0d903971..66a2d00f 100644 --- a/internal/data/internal/ent/sentinellibrary/where.go +++ b/internal/data/internal/ent/sentinellibrary/where.go @@ -12,47 +12,47 @@ import ( ) // ID filters vertices based on their ID field. -func ID(id model.InternalID) predicate.SentinelLibrary { +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 model.InternalID) predicate.SentinelLibrary { +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 model.InternalID) predicate.SentinelLibrary { +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 ...model.InternalID) predicate.SentinelLibrary { +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 ...model.InternalID) predicate.SentinelLibrary { +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 model.InternalID) predicate.SentinelLibrary { +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 model.InternalID) predicate.SentinelLibrary { +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 model.InternalID) predicate.SentinelLibrary { +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 model.InternalID) predicate.SentinelLibrary { +func IDLTE(id int) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldLTE(FieldID, id)) } @@ -82,9 +82,9 @@ func CreatedAt(v time.Time) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldEQ(FieldCreatedAt, v)) } -// ReportSequence applies equality check predicate on the "report_sequence" field. It's identical to ReportSequenceEQ. -func ReportSequence(v int64) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldEQ(FieldReportSequence, 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. @@ -302,44 +302,44 @@ func CreatedAtLTE(v time.Time) predicate.SentinelLibrary { return predicate.SentinelLibrary(sql.FieldLTE(FieldCreatedAt, v)) } -// ReportSequenceEQ applies the EQ predicate on the "report_sequence" field. -func ReportSequenceEQ(v int64) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldEQ(FieldReportSequence, 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)) } -// ReportSequenceNEQ applies the NEQ predicate on the "report_sequence" field. -func ReportSequenceNEQ(v int64) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldNEQ(FieldReportSequence, 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)) } -// ReportSequenceIn applies the In predicate on the "report_sequence" field. -func ReportSequenceIn(vs ...int64) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldIn(FieldReportSequence, vs...)) +// LibraryReportSequenceIn applies the In predicate on the "library_report_sequence" field. +func LibraryReportSequenceIn(vs ...int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldIn(FieldLibraryReportSequence, vs...)) } -// ReportSequenceNotIn applies the NotIn predicate on the "report_sequence" field. -func ReportSequenceNotIn(vs ...int64) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldNotIn(FieldReportSequence, 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...)) } -// ReportSequenceGT applies the GT predicate on the "report_sequence" field. -func ReportSequenceGT(v int64) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldGT(FieldReportSequence, v)) +// LibraryReportSequenceGT applies the GT predicate on the "library_report_sequence" field. +func LibraryReportSequenceGT(v int64) predicate.SentinelLibrary { + return predicate.SentinelLibrary(sql.FieldGT(FieldLibraryReportSequence, v)) } -// ReportSequenceGTE applies the GTE predicate on the "report_sequence" field. -func ReportSequenceGTE(v int64) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldGTE(FieldReportSequence, 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)) } -// ReportSequenceLT applies the LT predicate on the "report_sequence" field. -func ReportSequenceLT(v int64) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldLT(FieldReportSequence, 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)) } -// ReportSequenceLTE applies the LTE predicate on the "report_sequence" field. -func ReportSequenceLTE(v int64) predicate.SentinelLibrary { - return predicate.SentinelLibrary(sql.FieldLTE(FieldReportSequence, 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. diff --git a/internal/data/internal/ent/sentinellibrary_create.go b/internal/data/internal/ent/sentinellibrary_create.go index db1e652b..699d2120 100644 --- a/internal/data/internal/ent/sentinellibrary_create.go +++ b/internal/data/internal/ent/sentinellibrary_create.go @@ -71,15 +71,9 @@ func (slc *SentinelLibraryCreate) SetNillableCreatedAt(t *time.Time) *SentinelLi return slc } -// SetReportSequence sets the "report_sequence" field. -func (slc *SentinelLibraryCreate) SetReportSequence(i int64) *SentinelLibraryCreate { - slc.mutation.SetReportSequence(i) - return slc -} - -// SetID sets the "id" field. -func (slc *SentinelLibraryCreate) SetID(mi model.InternalID) *SentinelLibraryCreate { - slc.mutation.SetID(mi) +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (slc *SentinelLibraryCreate) SetLibraryReportSequence(i int64) *SentinelLibraryCreate { + slc.mutation.SetLibraryReportSequence(i) return slc } @@ -89,14 +83,14 @@ func (slc *SentinelLibraryCreate) SetSentinelInfo(s *SentinelInfo) *SentinelLibr } // AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (slc *SentinelLibraryCreate) AddSentinelAppBinaryIDs(ids ...model.InternalID) *SentinelLibraryCreate { +func (slc *SentinelLibraryCreate) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryCreate { slc.mutation.AddSentinelAppBinaryIDs(ids...) return slc } // AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. func (slc *SentinelLibraryCreate) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryCreate { - ids := make([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -165,8 +159,8 @@ func (slc *SentinelLibraryCreate) check() error { 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.ReportSequence(); !ok { - return &ValidationError{Name: "report_sequence", err: errors.New(`ent: missing required field "SentinelLibrary.report_sequence"`)} + 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"`)} @@ -185,10 +179,8 @@ func (slc *SentinelLibraryCreate) sqlSave(ctx context.Context) (*SentinelLibrary } return nil, err } - if _spec.ID.Value != _node.ID { - id := _spec.ID.Value.(int64) - _node.ID = model.InternalID(id) - } + id := _spec.ID.Value.(int64) + _node.ID = int(id) slc.mutation.id = &_node.ID slc.mutation.done = true return _node, nil @@ -197,13 +189,9 @@ func (slc *SentinelLibraryCreate) sqlSave(ctx context.Context) (*SentinelLibrary func (slc *SentinelLibraryCreate) createSpec() (*SentinelLibrary, *sqlgraph.CreateSpec) { var ( _node = &SentinelLibrary{config: slc.config} - _spec = sqlgraph.NewCreateSpec(sentinellibrary.Table, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64)) + _spec = sqlgraph.NewCreateSpec(sentinellibrary.Table, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt)) ) _spec.OnConflict = slc.conflict - if id, ok := slc.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = id - } if value, ok := slc.mutation.ReportedID(); ok { _spec.SetField(sentinellibrary.FieldReportedID, field.TypeInt64, value) _node.ReportedID = value @@ -220,9 +208,9 @@ func (slc *SentinelLibraryCreate) createSpec() (*SentinelLibrary, *sqlgraph.Crea _spec.SetField(sentinellibrary.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } - if value, ok := slc.mutation.ReportSequence(); ok { - _spec.SetField(sentinellibrary.FieldReportSequence, field.TypeInt64, value) - _node.ReportSequence = 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{ @@ -249,7 +237,7 @@ func (slc *SentinelLibraryCreate) createSpec() (*SentinelLibrary, *sqlgraph.Crea Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -375,42 +363,34 @@ func (u *SentinelLibraryUpsert) UpdateCreatedAt() *SentinelLibraryUpsert { return u } -// SetReportSequence sets the "report_sequence" field. -func (u *SentinelLibraryUpsert) SetReportSequence(v int64) *SentinelLibraryUpsert { - u.Set(sentinellibrary.FieldReportSequence, v) +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (u *SentinelLibraryUpsert) SetLibraryReportSequence(v int64) *SentinelLibraryUpsert { + u.Set(sentinellibrary.FieldLibraryReportSequence, v) return u } -// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. -func (u *SentinelLibraryUpsert) UpdateReportSequence() *SentinelLibraryUpsert { - u.SetExcluded(sentinellibrary.FieldReportSequence) +// 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 } -// AddReportSequence adds v to the "report_sequence" field. -func (u *SentinelLibraryUpsert) AddReportSequence(v int64) *SentinelLibraryUpsert { - u.Add(sentinellibrary.FieldReportSequence, v) +// 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 except the ID field. +// 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(), -// sql.ResolveWith(func(u *sql.UpdateSet) { -// u.SetIgnore(sentinellibrary.FieldID) -// }), // ). // Exec(ctx) func (u *SentinelLibraryUpsertOne) UpdateNewValues() *SentinelLibraryUpsertOne { 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(sentinellibrary.FieldID) - } - })) return u } @@ -518,24 +498,24 @@ func (u *SentinelLibraryUpsertOne) UpdateCreatedAt() *SentinelLibraryUpsertOne { }) } -// SetReportSequence sets the "report_sequence" field. -func (u *SentinelLibraryUpsertOne) SetReportSequence(v int64) *SentinelLibraryUpsertOne { +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (u *SentinelLibraryUpsertOne) SetLibraryReportSequence(v int64) *SentinelLibraryUpsertOne { return u.Update(func(s *SentinelLibraryUpsert) { - s.SetReportSequence(v) + s.SetLibraryReportSequence(v) }) } -// AddReportSequence adds v to the "report_sequence" field. -func (u *SentinelLibraryUpsertOne) AddReportSequence(v int64) *SentinelLibraryUpsertOne { +// AddLibraryReportSequence adds v to the "library_report_sequence" field. +func (u *SentinelLibraryUpsertOne) AddLibraryReportSequence(v int64) *SentinelLibraryUpsertOne { return u.Update(func(s *SentinelLibraryUpsert) { - s.AddReportSequence(v) + s.AddLibraryReportSequence(v) }) } -// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. -func (u *SentinelLibraryUpsertOne) UpdateReportSequence() *SentinelLibraryUpsertOne { +// 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.UpdateReportSequence() + s.UpdateLibraryReportSequence() }) } @@ -555,7 +535,7 @@ func (u *SentinelLibraryUpsertOne) ExecX(ctx context.Context) { } // Exec executes the UPSERT query and returns the inserted/updated ID. -func (u *SentinelLibraryUpsertOne) ID(ctx context.Context) (id model.InternalID, err error) { +func (u *SentinelLibraryUpsertOne) ID(ctx context.Context) (id int, err error) { node, err := u.create.Save(ctx) if err != nil { return id, err @@ -564,7 +544,7 @@ func (u *SentinelLibraryUpsertOne) ID(ctx context.Context) (id model.InternalID, } // IDX is like ID, but panics if an error occurs. -func (u *SentinelLibraryUpsertOne) IDX(ctx context.Context) model.InternalID { +func (u *SentinelLibraryUpsertOne) IDX(ctx context.Context) int { id, err := u.ID(ctx) if err != nil { panic(err) @@ -619,9 +599,9 @@ func (slcb *SentinelLibraryCreateBulk) Save(ctx context.Context) ([]*SentinelLib return nil, err } mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil && nodes[i].ID == 0 { + if specs[i].ID.Value != nil { id := specs[i].ID.Value.(int64) - nodes[i].ID = model.InternalID(id) + nodes[i].ID = int(id) } mutation.done = true return nodes[i], nil @@ -709,20 +689,10 @@ type SentinelLibraryUpsertBulk struct { // client.SentinelLibrary.Create(). // OnConflict( // sql.ResolveWithNewValues(), -// sql.ResolveWith(func(u *sql.UpdateSet) { -// u.SetIgnore(sentinellibrary.FieldID) -// }), // ). // Exec(ctx) func (u *SentinelLibraryUpsertBulk) UpdateNewValues() *SentinelLibraryUpsertBulk { 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(sentinellibrary.FieldID) - } - } - })) return u } @@ -830,24 +800,24 @@ func (u *SentinelLibraryUpsertBulk) UpdateCreatedAt() *SentinelLibraryUpsertBulk }) } -// SetReportSequence sets the "report_sequence" field. -func (u *SentinelLibraryUpsertBulk) SetReportSequence(v int64) *SentinelLibraryUpsertBulk { +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (u *SentinelLibraryUpsertBulk) SetLibraryReportSequence(v int64) *SentinelLibraryUpsertBulk { return u.Update(func(s *SentinelLibraryUpsert) { - s.SetReportSequence(v) + s.SetLibraryReportSequence(v) }) } -// AddReportSequence adds v to the "report_sequence" field. -func (u *SentinelLibraryUpsertBulk) AddReportSequence(v int64) *SentinelLibraryUpsertBulk { +// AddLibraryReportSequence adds v to the "library_report_sequence" field. +func (u *SentinelLibraryUpsertBulk) AddLibraryReportSequence(v int64) *SentinelLibraryUpsertBulk { return u.Update(func(s *SentinelLibraryUpsert) { - s.AddReportSequence(v) + s.AddLibraryReportSequence(v) }) } -// UpdateReportSequence sets the "report_sequence" field to the value that was provided on create. -func (u *SentinelLibraryUpsertBulk) UpdateReportSequence() *SentinelLibraryUpsertBulk { +// 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.UpdateReportSequence() + s.UpdateLibraryReportSequence() }) } diff --git a/internal/data/internal/ent/sentinellibrary_delete.go b/internal/data/internal/ent/sentinellibrary_delete.go index cba4b668..bf19e24f 100644 --- a/internal/data/internal/ent/sentinellibrary_delete.go +++ b/internal/data/internal/ent/sentinellibrary_delete.go @@ -40,7 +40,7 @@ func (sld *SentinelLibraryDelete) ExecX(ctx context.Context) int { } func (sld *SentinelLibraryDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(sentinellibrary.Table, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64)) + _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 { diff --git a/internal/data/internal/ent/sentinellibrary_query.go b/internal/data/internal/ent/sentinellibrary_query.go index cffc3fba..0eb22a2e 100644 --- a/internal/data/internal/ent/sentinellibrary_query.go +++ b/internal/data/internal/ent/sentinellibrary_query.go @@ -132,8 +132,8 @@ func (slq *SentinelLibraryQuery) FirstX(ctx context.Context) *SentinelLibrary { // 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 model.InternalID, err error) { - var ids []model.InternalID +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 } @@ -145,7 +145,7 @@ func (slq *SentinelLibraryQuery) FirstID(ctx context.Context) (id model.Internal } // FirstIDX is like FirstID, but panics if an error occurs. -func (slq *SentinelLibraryQuery) FirstIDX(ctx context.Context) model.InternalID { +func (slq *SentinelLibraryQuery) FirstIDX(ctx context.Context) int { id, err := slq.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -183,8 +183,8 @@ func (slq *SentinelLibraryQuery) OnlyX(ctx context.Context) *SentinelLibrary { // 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 model.InternalID, err error) { - var ids []model.InternalID +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 } @@ -200,7 +200,7 @@ func (slq *SentinelLibraryQuery) OnlyID(ctx context.Context) (id model.InternalI } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (slq *SentinelLibraryQuery) OnlyIDX(ctx context.Context) model.InternalID { +func (slq *SentinelLibraryQuery) OnlyIDX(ctx context.Context) int { id, err := slq.OnlyID(ctx) if err != nil { panic(err) @@ -228,7 +228,7 @@ func (slq *SentinelLibraryQuery) AllX(ctx context.Context) []*SentinelLibrary { } // IDs executes the query and returns a list of SentinelLibrary IDs. -func (slq *SentinelLibraryQuery) IDs(ctx context.Context) (ids []model.InternalID, err error) { +func (slq *SentinelLibraryQuery) IDs(ctx context.Context) (ids []int, err error) { if slq.ctx.Unique == nil && slq.path != nil { slq.Unique(true) } @@ -240,7 +240,7 @@ func (slq *SentinelLibraryQuery) IDs(ctx context.Context) (ids []model.InternalI } // IDsX is like IDs, but panics if an error occurs. -func (slq *SentinelLibraryQuery) IDsX(ctx context.Context) []model.InternalID { +func (slq *SentinelLibraryQuery) IDsX(ctx context.Context) []int { ids, err := slq.IDs(ctx) if err != nil { panic(err) @@ -480,7 +480,7 @@ func (slq *SentinelLibraryQuery) loadSentinelInfo(ctx context.Context, query *Se } func (slq *SentinelLibraryQuery) loadSentinelAppBinary(ctx context.Context, query *SentinelAppBinaryQuery, nodes []*SentinelLibrary, init func(*SentinelLibrary), assign func(*SentinelLibrary, *SentinelAppBinary)) error { fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[model.InternalID]*SentinelLibrary) + nodeids := make(map[int]*SentinelLibrary) for i := range nodes { fks = append(fks, nodes[i].ID) nodeids[nodes[i].ID] = nodes[i] @@ -519,7 +519,7 @@ func (slq *SentinelLibraryQuery) sqlCount(ctx context.Context) (int, error) { } func (slq *SentinelLibraryQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(sentinellibrary.Table, sentinellibrary.Columns, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64)) + _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 diff --git a/internal/data/internal/ent/sentinellibrary_update.go b/internal/data/internal/ent/sentinellibrary_update.go index ca18d291..ea6e18d1 100644 --- a/internal/data/internal/ent/sentinellibrary_update.go +++ b/internal/data/internal/ent/sentinellibrary_update.go @@ -100,24 +100,24 @@ func (slu *SentinelLibraryUpdate) SetNillableCreatedAt(t *time.Time) *SentinelLi return slu } -// SetReportSequence sets the "report_sequence" field. -func (slu *SentinelLibraryUpdate) SetReportSequence(i int64) *SentinelLibraryUpdate { - slu.mutation.ResetReportSequence() - slu.mutation.SetReportSequence(i) +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (slu *SentinelLibraryUpdate) SetLibraryReportSequence(i int64) *SentinelLibraryUpdate { + slu.mutation.ResetLibraryReportSequence() + slu.mutation.SetLibraryReportSequence(i) return slu } -// SetNillableReportSequence sets the "report_sequence" field if the given value is not nil. -func (slu *SentinelLibraryUpdate) SetNillableReportSequence(i *int64) *SentinelLibraryUpdate { +// 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.SetReportSequence(*i) + slu.SetLibraryReportSequence(*i) } return slu } -// AddReportSequence adds i to the "report_sequence" field. -func (slu *SentinelLibraryUpdate) AddReportSequence(i int64) *SentinelLibraryUpdate { - slu.mutation.AddReportSequence(i) +// AddLibraryReportSequence adds i to the "library_report_sequence" field. +func (slu *SentinelLibraryUpdate) AddLibraryReportSequence(i int64) *SentinelLibraryUpdate { + slu.mutation.AddLibraryReportSequence(i) return slu } @@ -127,14 +127,14 @@ func (slu *SentinelLibraryUpdate) SetSentinelInfo(s *SentinelInfo) *SentinelLibr } // AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (slu *SentinelLibraryUpdate) AddSentinelAppBinaryIDs(ids ...model.InternalID) *SentinelLibraryUpdate { +func (slu *SentinelLibraryUpdate) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdate { slu.mutation.AddSentinelAppBinaryIDs(ids...) return slu } // AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. func (slu *SentinelLibraryUpdate) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdate { - ids := make([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -159,14 +159,14 @@ func (slu *SentinelLibraryUpdate) ClearSentinelAppBinary() *SentinelLibraryUpdat } // RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to SentinelAppBinary entities by IDs. -func (slu *SentinelLibraryUpdate) RemoveSentinelAppBinaryIDs(ids ...model.InternalID) *SentinelLibraryUpdate { +func (slu *SentinelLibraryUpdate) RemoveSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdate { slu.mutation.RemoveSentinelAppBinaryIDs(ids...) return slu } // RemoveSentinelAppBinary removes "sentinel_app_binary" edges to SentinelAppBinary entities. func (slu *SentinelLibraryUpdate) RemoveSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdate { - ids := make([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -221,7 +221,7 @@ 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.TypeInt64)) + _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 { @@ -244,11 +244,11 @@ func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error if value, ok := slu.mutation.CreatedAt(); ok { _spec.SetField(sentinellibrary.FieldCreatedAt, field.TypeTime, value) } - if value, ok := slu.mutation.ReportSequence(); ok { - _spec.SetField(sentinellibrary.FieldReportSequence, field.TypeInt64, value) + if value, ok := slu.mutation.LibraryReportSequence(); ok { + _spec.SetField(sentinellibrary.FieldLibraryReportSequence, field.TypeInt64, value) } - if value, ok := slu.mutation.AddedReportSequence(); ok { - _spec.AddField(sentinellibrary.FieldReportSequence, field.TypeInt64, value) + if value, ok := slu.mutation.AddedLibraryReportSequence(); ok { + _spec.AddField(sentinellibrary.FieldLibraryReportSequence, field.TypeInt64, value) } if slu.mutation.SentinelInfoCleared() { edge := &sqlgraph.EdgeSpec{ @@ -287,7 +287,7 @@ func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -300,7 +300,7 @@ func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -316,7 +316,7 @@ func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -413,24 +413,24 @@ func (sluo *SentinelLibraryUpdateOne) SetNillableCreatedAt(t *time.Time) *Sentin return sluo } -// SetReportSequence sets the "report_sequence" field. -func (sluo *SentinelLibraryUpdateOne) SetReportSequence(i int64) *SentinelLibraryUpdateOne { - sluo.mutation.ResetReportSequence() - sluo.mutation.SetReportSequence(i) +// SetLibraryReportSequence sets the "library_report_sequence" field. +func (sluo *SentinelLibraryUpdateOne) SetLibraryReportSequence(i int64) *SentinelLibraryUpdateOne { + sluo.mutation.ResetLibraryReportSequence() + sluo.mutation.SetLibraryReportSequence(i) return sluo } -// SetNillableReportSequence sets the "report_sequence" field if the given value is not nil. -func (sluo *SentinelLibraryUpdateOne) SetNillableReportSequence(i *int64) *SentinelLibraryUpdateOne { +// 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.SetReportSequence(*i) + sluo.SetLibraryReportSequence(*i) } return sluo } -// AddReportSequence adds i to the "report_sequence" field. -func (sluo *SentinelLibraryUpdateOne) AddReportSequence(i int64) *SentinelLibraryUpdateOne { - sluo.mutation.AddReportSequence(i) +// AddLibraryReportSequence adds i to the "library_report_sequence" field. +func (sluo *SentinelLibraryUpdateOne) AddLibraryReportSequence(i int64) *SentinelLibraryUpdateOne { + sluo.mutation.AddLibraryReportSequence(i) return sluo } @@ -440,14 +440,14 @@ func (sluo *SentinelLibraryUpdateOne) SetSentinelInfo(s *SentinelInfo) *Sentinel } // AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (sluo *SentinelLibraryUpdateOne) AddSentinelAppBinaryIDs(ids ...model.InternalID) *SentinelLibraryUpdateOne { +func (sluo *SentinelLibraryUpdateOne) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdateOne { sluo.mutation.AddSentinelAppBinaryIDs(ids...) return sluo } // AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. func (sluo *SentinelLibraryUpdateOne) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdateOne { - ids := make([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -472,14 +472,14 @@ func (sluo *SentinelLibraryUpdateOne) ClearSentinelAppBinary() *SentinelLibraryU } // RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to SentinelAppBinary entities by IDs. -func (sluo *SentinelLibraryUpdateOne) RemoveSentinelAppBinaryIDs(ids ...model.InternalID) *SentinelLibraryUpdateOne { +func (sluo *SentinelLibraryUpdateOne) RemoveSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdateOne { sluo.mutation.RemoveSentinelAppBinaryIDs(ids...) return sluo } // RemoveSentinelAppBinary removes "sentinel_app_binary" edges to SentinelAppBinary entities. func (sluo *SentinelLibraryUpdateOne) RemoveSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdateOne { - ids := make([]model.InternalID, len(s)) + ids := make([]int, len(s)) for i := range s { ids[i] = s[i].ID } @@ -547,7 +547,7 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti if err := sluo.check(); err != nil { return _node, err } - _spec := sqlgraph.NewUpdateSpec(sentinellibrary.Table, sentinellibrary.Columns, sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt64)) + _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`)} @@ -587,11 +587,11 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti if value, ok := sluo.mutation.CreatedAt(); ok { _spec.SetField(sentinellibrary.FieldCreatedAt, field.TypeTime, value) } - if value, ok := sluo.mutation.ReportSequence(); ok { - _spec.SetField(sentinellibrary.FieldReportSequence, field.TypeInt64, value) + if value, ok := sluo.mutation.LibraryReportSequence(); ok { + _spec.SetField(sentinellibrary.FieldLibraryReportSequence, field.TypeInt64, value) } - if value, ok := sluo.mutation.AddedReportSequence(); ok { - _spec.AddField(sentinellibrary.FieldReportSequence, field.TypeInt64, value) + if value, ok := sluo.mutation.AddedLibraryReportSequence(); ok { + _spec.AddField(sentinellibrary.FieldLibraryReportSequence, field.TypeInt64, value) } if sluo.mutation.SentinelInfoCleared() { edge := &sqlgraph.EdgeSpec{ @@ -630,7 +630,7 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -643,7 +643,7 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } for _, k := range nodes { @@ -659,7 +659,7 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt64), + IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), }, } for _, k := range nodes { diff --git a/internal/model/modelgebura/modelgebura.go b/internal/model/modelgebura/modelgebura.go index 58d0e8bb..41b5a026 100644 --- a/internal/model/modelgebura/modelgebura.go +++ b/internal/model/modelgebura/modelgebura.go @@ -119,15 +119,12 @@ type SentinelInfo struct { } type SentinelLibrary struct { - ID model.InternalID ReportedID int64 DownloadBasePath string AppBinaries []*SentinelAppBinary - ReportedSequence int64 } type SentinelAppBinary struct { - ID model.InternalID SentinelLibraryID int64 GeneratedID string SizeBytes int64 @@ -137,11 +134,9 @@ type SentinelAppBinary struct { Version string Developer string Publisher string - ReportedSequence int64 } type SentinelAppBinaryFile struct { - ID model.InternalID Name string SizeBytes int64 Sha256 []byte diff --git a/internal/service/sentinel/converter/pb_to_biz.go b/internal/service/sentinel/converter/pb_to_biz.go index 7529a6b1..ce2f5f7b 100644 --- a/internal/service/sentinel/converter/pb_to_biz.go +++ b/internal/service/sentinel/converter/pb_to_biz.go @@ -16,17 +16,12 @@ type toBizConverter interface { //nolint:unused // used by generator // goverter:ignore ID // goverter:map UrlAlternatives AlternativeUrls ToBizSentinelInfo(*sentinel.ReportSentinelInformationRequest) *modelgebura.SentinelInfo - // goverter:ignore ID // goverter:map Id ReportedID // goverter:ignore AppBinaries - // goverter:ignore ReportedSequence ToBizSentinelLibrary(*sentinel.SentinelLibrary) *modelgebura.SentinelLibrary - // goverter:ignore ID // goverter:map SentinelGeneratedId GeneratedID - // goverter:ignore ReportedSequence ToBizSentinelAppBinary(*sentinel.SentinelLibraryAppBinary) *modelgebura.SentinelAppBinary ToBizSentinelAppBinaryList([]*sentinel.SentinelLibraryAppBinary) []*modelgebura.SentinelAppBinary - // goverter:ignore ID ToBizSentinelAppBinaryFile(*sentinel.SentinelLibraryAppBinaryFile) *modelgebura.SentinelAppBinaryFile } From 83547fe7e88231ae0bf833299de7a1134e7a664a Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Thu, 10 Apr 2025 16:41:22 +0800 Subject: [PATCH 12/16] feat(sentinel): update biz, repo for new models --- internal/biz/bizgebura/sentinel.go | 24 +---- internal/data/gebura.go | 154 ++++++++++++++++------------- 2 files changed, 87 insertions(+), 91 deletions(-) diff --git a/internal/biz/bizgebura/sentinel.go b/internal/biz/bizgebura/sentinel.go index 0281859e..2ee2e9dc 100644 --- a/internal/biz/bizgebura/sentinel.go +++ b/internal/biz/bizgebura/sentinel.go @@ -18,14 +18,7 @@ func (g *Gebura) UpsertSentinelInfo( return bizutils.NoPermissionError() } info.ID = claims.UserID - var err error - for _, lib := range info.Libraries { - lib.ID, err = g.id.New() - if err != nil { - return pb.ErrorErrorReasonUnspecified("%s", err.Error()) - } - } - err = g.repo.UpsertSentinelInfo(ctx, info) + err := g.repo.UpsertSentinelInfo(ctx, info) if err != nil { return pb.ErrorErrorReasonUnspecified("%s", err.Error()) } @@ -40,20 +33,7 @@ func (g *Gebura) UpsertAppBinaries( return bizutils.NoPermissionError() } sentinelID := claims.UserID - var err error - for _, ab := range abs { - ab.ID, err = g.id.New() - if err != nil { - return pb.ErrorErrorReasonUnspecified("%s", err.Error()) - } - for _, f := range ab.Files { - f.ID, err = g.id.New() - if err != nil { - return pb.ErrorErrorReasonUnspecified("%s", err.Error()) - } - } - } - err = g.repo.UpsertAppBinaries(ctx, sentinelID, abs) + err := g.repo.UpsertAppBinaries(ctx, sentinelID, abs) if err != nil { return pb.ErrorErrorReasonUnspecified("%s", err.Error()) } diff --git a/internal/data/gebura.go b/internal/data/gebura.go index 81380f23..fd72a641 100644 --- a/internal/data/gebura.go +++ b/internal/data/gebura.go @@ -2,6 +2,7 @@ package data import ( "context" + "errors" "time" "github.com/tuihub/librarian/internal/data/internal/converter" @@ -12,6 +13,7 @@ import ( "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" @@ -622,49 +624,49 @@ func (g *GeburaRepo) UpsertSentinelInfo( info *modelgebura.SentinelInfo, ) error { return g.data.WithTx(ctx, func(tx *ent.Tx) error { + sInfo, err := tx.SentinelInfo.Query(). + Where(sentinelinfo.IDEQ(info.ID)). + Only(ctx) + var libReportSeq int64 + if err != nil { + if !ent.IsNotFound(err) { + return err + } + libReportSeq = 0 + } else { + libReportSeq = sInfo.LibraryReportSequence + 1 + } // upsert sentinel info q := tx.SentinelInfo.Create(). SetID(info.ID). SetURL(info.Url). SetAlternativeUrls(info.AlternativeUrls). SetGetTokenPath(info.GetTokenPath). - SetDownloadFileBasePath(info.DownloadFileBasePath) - err := q.OnConflict(sql.ConflictColumns(sentinelinfo.FieldID)). + SetDownloadFileBasePath(info.DownloadFileBasePath). + SetLibraryReportSequence(libReportSeq) + err = q.OnConflict(sql.ConflictColumns(sentinelinfo.FieldID)). UpdateNewValues(). 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 - } - oldLibs, err := tx.SentinelLibrary.Query(). - Where(sentinellibrary.SentinelInfoIDEQ(sInfo.ID)). - All(ctx) - if err != nil { - return err + if libReportSeq == 0 { + sInfo, err = tx.SentinelInfo.Query(). + Where(sentinelinfo.IDEQ(info.ID)). + Only(ctx) + if err != nil { + return err + } } - oldLibsMap := lo.Associate(oldLibs, func(lib *ent.SentinelLibrary) (int64, *ent.SentinelLibrary) { - return lib.ReportedID, lib - }) newLibs := make([]*ent.SentinelLibraryCreate, 0, len(info.Libraries)) for _, lib := range info.Libraries { - var reportSeq int64 - if oldLib, exists := oldLibsMap[lib.ReportedID]; exists { - reportSeq = oldLib.ReportSequence + 1 - } else { - reportSeq = 0 - } newLibs = append(newLibs, tx.SentinelLibrary.Create(). - SetID(lib.ID). SetSentinelInfoID(sInfo.ID). SetReportedID(lib.ReportedID). SetDownloadBasePath(lib.DownloadBasePath). - SetReportSequence(reportSeq)) + SetLibraryReportSequence(sInfo.LibraryReportSequence), + ) } return tx.SentinelLibrary.CreateBulk(newLibs...). OnConflict( @@ -672,9 +674,6 @@ func (g *GeburaRepo) UpsertSentinelInfo( sentinellibrary.FieldSentinelInfoID, sentinellibrary.FieldReportedID, ), - resolveWithIgnores([]string{ - sentinellibrary.FieldID, - }), ). UpdateNewValues(). Exec(ctx) @@ -687,6 +686,14 @@ func (g *GeburaRepo) UpsertAppBinaries( abs []*modelgebura.SentinelAppBinary, ) error { return g.data.WithTx(ctx, func(tx *ent.Tx) error { + // update AppBinaryReportSequence + err := tx.SentinelInfo.Update(). + Where(sentinelinfo.IDEQ(sentinelID)). + AddAppBinaryReportSequence(1). + Exec(ctx) + if err != nil { + return err + } sInfo, err := tx.SentinelInfo.Query(). Where(sentinelinfo.IDEQ(sentinelID)). WithSentinelLibrary(). @@ -694,30 +701,20 @@ func (g *GeburaRepo) UpsertAppBinaries( if err != nil { return err } - slibReportedIDs := lo.Map(sInfo.Edges.SentinelLibrary, func(lib *ent.SentinelLibrary, _ int) int64 { - return lib.ReportedID - }) + // upsert binaries slibReportedIDEntMap := lo.Associate( sInfo.Edges.SentinelLibrary, func(lib *ent.SentinelLibrary, ) (int64, *ent.SentinelLibrary) { return lib.ReportedID, lib }) - // remove all existing binary files - _, err = tx.SentinelAppBinary.Delete().Where( - sentinelappbinary.HasSentinelLibraryWith( - sentinellibrary.SentinelInfoIDEQ(sentinelID), - sentinellibrary.ReportedIDIn(slibReportedIDs...), - ), - ).Exec(ctx) - if err != nil { - return err - } - // upsert binaries newAbs := make([]*ent.SentinelAppBinaryCreate, 0, len(abs)) for _, ab := range abs { + slibEnt, exists := slibReportedIDEntMap[ab.SentinelLibraryID] + if !exists { + return errors.New("invalid app_binary data: associated sentinel library id not exists") + } newAbs = append(newAbs, tx.SentinelAppBinary.Create(). - SetID(ab.ID). - SetSentinelLibraryID(slibReportedIDEntMap[ab.SentinelLibraryID].ID). + SetSentinelLibrary(slibEnt). SetGeneratedID(ab.GeneratedID). SetSizeBytes(ab.SizeBytes). SetNeedToken(ab.NeedToken). @@ -725,7 +722,7 @@ func (g *GeburaRepo) UpsertAppBinaries( SetVersion(ab.Version). SetDeveloper(ab.Developer). SetPublisher(ab.Publisher). - SetReportSequence(slibReportedIDEntMap[ab.SentinelLibraryID].ReportSequence)) + SetAppBinaryReportSequence(sInfo.AppBinaryReportSequence)) } err = tx.SentinelAppBinary.CreateBulk(newAbs...). OnConflict( @@ -742,43 +739,62 @@ func (g *GeburaRepo) UpsertAppBinaries( if err != nil { return err } - // insert all binary files - slibIDs := lo.Map(sInfo.Edges.SentinelLibrary, func(lib *ent.SentinelLibrary, _ int) model.InternalID { - return lib.ID - }) - abGeneratedIDs := lo.Map(abs, func(ab *modelgebura.SentinelAppBinary, _ int) string { - return ab.GeneratedID - }) - dbAbs, err := tx.SentinelAppBinary.Query(). - Where( - sentinelappbinary.SentinelLibraryIDIn(slibIDs...), - sentinelappbinary.GeneratedIDIn(abGeneratedIDs...), - ). - All(ctx) + // upsert binary files + dbAbs, err := tx.SentinelAppBinary.Query().Where( + sentinelappbinary.HasSentinelLibraryWith( + sentinellibrary.HasSentinelInfoWith( + sentinelinfo.IDEQ(sentinelID), + ), + ), + ).All(ctx) if err != nil { return err } - dbAbGeneratedIDIDMap := lo.Associate(dbAbs, func(ab *ent.SentinelAppBinary) (string, model.InternalID) { - return ab.GeneratedID, ab.ID + type AbKey struct { + SlibID int64 + GenID string + } + abSlibIDGenIDEntMap := lo.Associate(dbAbs, func(ab *ent.SentinelAppBinary) (AbKey, *ent.SentinelAppBinary) { + return AbKey{ + SlibID: ab.Edges.SentinelLibrary.ReportedID, + GenID: ab.GeneratedID, + }, ab }) + 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 { - abfs := make([]*ent.SentinelAppBinaryFileCreate, 0, len(ab.Files)) + abEnt, exists := abSlibIDGenIDEntMap[AbKey{ab.SentinelLibraryID, ab.GeneratedID}] + if !exists { + return errors.New("invalid app_binary_file data: associated app binary not exists") + } for _, f := range ab.Files { - abfs = append(abfs, tx.SentinelAppBinaryFile.Create(). - SetID(f.ID). - SetSentinelAppBinaryID(dbAbGeneratedIDIDMap[ab.GeneratedID]). + newAbfs = append(newAbfs, tx.SentinelAppBinaryFile.Create(). + SetSentinelAppBinaryID(abEnt.ID). SetName(f.Name). SetSizeBytes(f.SizeBytes). SetSha256(f.Sha256). SetServerFilePath(f.ServerFilePath). - SetChunksInfo(f.ChunksInfo)) - } - err = tx.SentinelAppBinaryFile.CreateBulk(abfs...). - Exec(ctx) - if err != nil { - return err + SetChunksInfo(f.ChunksInfo). + SetAppBinaryReportSequence(sInfo.AppBinaryReportSequence)) } } + err = tx.SentinelAppBinaryFile.CreateBulk(newAbfs...). + OnConflict( + sql.ConflictColumns( + sentinelappbinaryfile.FieldSentinelAppBinaryID, + sentinelappbinaryfile.FieldServerFilePath, + ), + resolveWithIgnores([]string{ + sentinelappbinaryfile.FieldID, + }), + ). + UpdateNewValues(). + Exec(ctx) + if err != nil { + return err + } return nil }) } From 5ca75a07c0b17f70da3f1984c6c795d71025206f Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Fri, 11 Apr 2025 10:57:46 +0800 Subject: [PATCH 13/16] feat(sentinel): update model, biz, repo --- internal/data/gebura.go | 48 +- internal/data/internal/ent/client.go | 64 -- internal/data/internal/ent/migrate/schema.go | 39 +- internal/data/internal/ent/mutation.go | 736 +++++++++--------- internal/data/internal/ent/runtime.go | 8 +- .../ent/schema/sentinel_app_binary.go | 23 +- .../ent/schema/sentinel_app_binary_file.go | 21 +- .../internal/ent/schema/sentinel_library.go | 4 +- .../data/internal/ent/sentinelappbinary.go | 75 +- .../sentinelappbinary/sentinelappbinary.go | 74 +- .../internal/ent/sentinelappbinary/where.go | 158 ++-- .../internal/ent/sentinelappbinary_create.go | 208 +++-- .../internal/ent/sentinelappbinary_query.go | 186 +---- .../internal/ent/sentinelappbinary_update.go | 371 +++------ .../internal/ent/sentinelappbinaryfile.go | 72 +- .../sentinelappbinaryfile.go | 52 +- .../ent/sentinelappbinaryfile/where.go | 205 ++++- .../ent/sentinelappbinaryfile_create.go | 229 ++++-- .../ent/sentinelappbinaryfile_query.go | 109 +-- .../ent/sentinelappbinaryfile_update.go | 242 +++--- internal/data/internal/ent/sentinellibrary.go | 18 +- .../ent/sentinellibrary/sentinellibrary.go | 30 - .../internal/ent/sentinellibrary/where.go | 23 - .../internal/ent/sentinellibrary_create.go | 32 - .../internal/ent/sentinellibrary_query.go | 101 +-- .../internal/ent/sentinellibrary_update.go | 163 ---- 26 files changed, 1348 insertions(+), 1943 deletions(-) diff --git a/internal/data/gebura.go b/internal/data/gebura.go index fd72a641..11e0d742 100644 --- a/internal/data/gebura.go +++ b/internal/data/gebura.go @@ -2,7 +2,6 @@ package data import ( "context" - "errors" "time" "github.com/tuihub/librarian/internal/data/internal/converter" @@ -702,19 +701,11 @@ func (g *GeburaRepo) UpsertAppBinaries( return err } // upsert binaries - slibReportedIDEntMap := lo.Associate( - sInfo.Edges.SentinelLibrary, func(lib *ent.SentinelLibrary, - ) (int64, *ent.SentinelLibrary) { - return lib.ReportedID, lib - }) newAbs := make([]*ent.SentinelAppBinaryCreate, 0, len(abs)) for _, ab := range abs { - slibEnt, exists := slibReportedIDEntMap[ab.SentinelLibraryID] - if !exists { - return errors.New("invalid app_binary data: associated sentinel library id not exists") - } newAbs = append(newAbs, tx.SentinelAppBinary.Create(). - SetSentinelLibrary(slibEnt). + SetSentinelInfoID(sentinelID). + SetSentinelLibraryReportedID(ab.SentinelLibraryID). SetGeneratedID(ab.GeneratedID). SetSizeBytes(ab.SizeBytes). SetNeedToken(ab.NeedToken). @@ -727,7 +718,8 @@ func (g *GeburaRepo) UpsertAppBinaries( err = tx.SentinelAppBinary.CreateBulk(newAbs...). OnConflict( sql.ConflictColumns( - sentinelappbinary.FieldSentinelLibraryID, + sentinelappbinary.FieldSentinelInfoID, + sentinelappbinary.FieldSentinelLibraryReportedID, sentinelappbinary.FieldGeneratedID, ), resolveWithIgnores([]string{ @@ -740,38 +732,16 @@ func (g *GeburaRepo) UpsertAppBinaries( return err } // upsert binary files - dbAbs, err := tx.SentinelAppBinary.Query().Where( - sentinelappbinary.HasSentinelLibraryWith( - sentinellibrary.HasSentinelInfoWith( - sentinelinfo.IDEQ(sentinelID), - ), - ), - ).All(ctx) - if err != nil { - return err - } - type AbKey struct { - SlibID int64 - GenID string - } - abSlibIDGenIDEntMap := lo.Associate(dbAbs, func(ab *ent.SentinelAppBinary) (AbKey, *ent.SentinelAppBinary) { - return AbKey{ - SlibID: ab.Edges.SentinelLibrary.ReportedID, - GenID: ab.GeneratedID, - }, ab - }) 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 { - abEnt, exists := abSlibIDGenIDEntMap[AbKey{ab.SentinelLibraryID, ab.GeneratedID}] - if !exists { - return errors.New("invalid app_binary_file data: associated app binary not exists") - } for _, f := range ab.Files { newAbfs = append(newAbfs, tx.SentinelAppBinaryFile.Create(). - SetSentinelAppBinaryID(abEnt.ID). + SetSentinelInfoID(sentinelID). + SetSentinelLibraryReportedID(ab.SentinelLibraryID). + SetSentinelAppBinaryGeneratedID(ab.GeneratedID). SetName(f.Name). SetSizeBytes(f.SizeBytes). SetSha256(f.Sha256). @@ -783,7 +753,9 @@ func (g *GeburaRepo) UpsertAppBinaries( err = tx.SentinelAppBinaryFile.CreateBulk(newAbfs...). OnConflict( sql.ConflictColumns( - sentinelappbinaryfile.FieldSentinelAppBinaryID, + sentinelappbinaryfile.FieldSentinelInfoID, + sentinelappbinaryfile.FieldSentinelLibraryReportedID, + sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID, sentinelappbinaryfile.FieldServerFilePath, ), resolveWithIgnores([]string{ diff --git a/internal/data/internal/ent/client.go b/internal/data/internal/ent/client.go index f59409e7..f6e85bd4 100644 --- a/internal/data/internal/ent/client.go +++ b/internal/data/internal/ent/client.go @@ -4316,38 +4316,6 @@ func (c *SentinelAppBinaryClient) GetX(ctx context.Context, id int) *SentinelApp return obj } -// QuerySentinelLibrary queries the sentinel_library edge of a SentinelAppBinary. -func (c *SentinelAppBinaryClient) QuerySentinelLibrary(sab *SentinelAppBinary) *SentinelLibraryQuery { - query := (&SentinelLibraryClient{config: c.config}).Query() - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := sab.ID - step := sqlgraph.NewStep( - sqlgraph.From(sentinelappbinary.Table, sentinelappbinary.FieldID, id), - sqlgraph.To(sentinellibrary.Table, sentinellibrary.FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, sentinelappbinary.SentinelLibraryTable, sentinelappbinary.SentinelLibraryColumn), - ) - fromV = sqlgraph.Neighbors(sab.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// QuerySentinelAppBinaryFile queries the sentinel_app_binary_file edge of a SentinelAppBinary. -func (c *SentinelAppBinaryClient) QuerySentinelAppBinaryFile(sab *SentinelAppBinary) *SentinelAppBinaryFileQuery { - query := (&SentinelAppBinaryFileClient{config: c.config}).Query() - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := sab.ID - step := sqlgraph.NewStep( - sqlgraph.From(sentinelappbinary.Table, sentinelappbinary.FieldID, id), - sqlgraph.To(sentinelappbinaryfile.Table, sentinelappbinaryfile.FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, sentinelappbinary.SentinelAppBinaryFileTable, sentinelappbinary.SentinelAppBinaryFileColumn), - ) - fromV = sqlgraph.Neighbors(sab.driver.Dialect(), step) - return fromV, nil - } - return query -} - // Hooks returns the client hooks. func (c *SentinelAppBinaryClient) Hooks() []Hook { return c.hooks.SentinelAppBinary @@ -4481,22 +4449,6 @@ func (c *SentinelAppBinaryFileClient) GetX(ctx context.Context, id int) *Sentine return obj } -// QuerySentinelAppBinary queries the sentinel_app_binary edge of a SentinelAppBinaryFile. -func (c *SentinelAppBinaryFileClient) QuerySentinelAppBinary(sabf *SentinelAppBinaryFile) *SentinelAppBinaryQuery { - query := (&SentinelAppBinaryClient{config: c.config}).Query() - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := sabf.ID - step := sqlgraph.NewStep( - sqlgraph.From(sentinelappbinaryfile.Table, sentinelappbinaryfile.FieldID, id), - sqlgraph.To(sentinelappbinary.Table, sentinelappbinary.FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, sentinelappbinaryfile.SentinelAppBinaryTable, sentinelappbinaryfile.SentinelAppBinaryColumn), - ) - fromV = sqlgraph.Neighbors(sabf.driver.Dialect(), step) - return fromV, nil - } - return query -} - // Hooks returns the client hooks. func (c *SentinelAppBinaryFileClient) Hooks() []Hook { return c.hooks.SentinelAppBinaryFile @@ -4795,22 +4747,6 @@ func (c *SentinelLibraryClient) QuerySentinelInfo(sl *SentinelLibrary) *Sentinel return query } -// QuerySentinelAppBinary queries the sentinel_app_binary edge of a SentinelLibrary. -func (c *SentinelLibraryClient) QuerySentinelAppBinary(sl *SentinelLibrary) *SentinelAppBinaryQuery { - query := (&SentinelAppBinaryClient{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(sentinelappbinary.Table, sentinelappbinary.FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, sentinellibrary.SentinelAppBinaryTable, sentinellibrary.SentinelAppBinaryColumn), - ) - 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 diff --git a/internal/data/internal/ent/migrate/schema.go b/internal/data/internal/ent/migrate/schema.go index e160eecd..c1cd958b 100644 --- a/internal/data/internal/ent/migrate/schema.go +++ b/internal/data/internal/ent/migrate/schema.go @@ -740,6 +740,8 @@ 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}, @@ -750,42 +752,36 @@ var ( {Name: "updated_at", Type: field.TypeTime}, {Name: "created_at", Type: field.TypeTime}, {Name: "app_binary_report_sequence", Type: field.TypeInt64}, - {Name: "sentinel_library_id", Type: field.TypeInt}, } // 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]}, - ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "sentinel_app_binaries_sentinel_libraries_sentinel_library", - Columns: []*schema.Column{SentinelAppBinariesColumns[11]}, - RefColumns: []*schema.Column{SentinelLibrariesColumns[0]}, - OnDelete: schema.NoAction, - }, - }, Indexes: []*schema.Index{ { - Name: "sentinelappbinary_sentinel_library_id_generated_id", + Name: "sentinelappbinary_sentinel_info_id_sentinel_library_reported_id_generated_id", Unique: true, - Columns: []*schema.Column{SentinelAppBinariesColumns[11], SentinelAppBinariesColumns[1]}, + Columns: []*schema.Column{SentinelAppBinariesColumns[1], SentinelAppBinariesColumns[2], SentinelAppBinariesColumns[3]}, }, { Name: "sentinelappbinary_generated_id", Unique: false, - Columns: []*schema.Column{SentinelAppBinariesColumns[1]}, + Columns: []*schema.Column{SentinelAppBinariesColumns[3]}, }, { Name: "sentinelappbinary_app_binary_report_sequence", Unique: false, - Columns: []*schema.Column{SentinelAppBinariesColumns[10]}, + 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}, @@ -794,31 +790,22 @@ var ( {Name: "updated_at", Type: field.TypeTime}, {Name: "created_at", Type: field.TypeTime}, {Name: "app_binary_report_sequence", Type: field.TypeInt64}, - {Name: "sentinel_app_binary_id", Type: field.TypeInt}, } // 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]}, - ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "sentinel_app_binary_files_sentinel_app_binaries_sentinel_app_binary", - Columns: []*schema.Column{SentinelAppBinaryFilesColumns[9]}, - RefColumns: []*schema.Column{SentinelAppBinariesColumns[0]}, - OnDelete: schema.NoAction, - }, - }, Indexes: []*schema.Index{ { - Name: "sentinelappbinaryfile_sentinel_app_binary_id_server_file_path", + Name: "sentinelappbinaryfile_sentinel_info_id_sentinel_library_reported_id_sentinel_app_binary_generated_id_server_file_path", Unique: true, - Columns: []*schema.Column{SentinelAppBinaryFilesColumns[9], SentinelAppBinaryFilesColumns[4]}, + Columns: []*schema.Column{SentinelAppBinaryFilesColumns[1], SentinelAppBinaryFilesColumns[2], SentinelAppBinaryFilesColumns[3], SentinelAppBinaryFilesColumns[7]}, }, { Name: "sentinelappbinaryfile_app_binary_report_sequence", Unique: false, - Columns: []*schema.Column{SentinelAppBinaryFilesColumns[8]}, + Columns: []*schema.Column{SentinelAppBinaryFilesColumns[11]}, }, }, } @@ -1111,8 +1098,6 @@ func init() { NotifySourcesTable.ForeignKeys[2].RefTable = UsersTable NotifyTargetsTable.ForeignKeys[0].RefTable = UsersTable PorterContextsTable.ForeignKeys[0].RefTable = UsersTable - SentinelAppBinariesTable.ForeignKeys[0].RefTable = SentinelLibrariesTable - SentinelAppBinaryFilesTable.ForeignKeys[0].RefTable = SentinelAppBinariesTable SentinelLibrariesTable.ForeignKeys[0].RefTable = SentinelInfosTable SessionsTable.ForeignKeys[0].RefTable = DevicesTable SessionsTable.ForeignKeys[1].RefTable = UsersTable diff --git a/internal/data/internal/ent/mutation.go b/internal/data/internal/ent/mutation.go index b997a77a..501d98e1 100644 --- a/internal/data/internal/ent/mutation.go +++ b/internal/data/internal/ent/mutation.go @@ -21859,6 +21859,10 @@ type SentinelAppBinaryMutation struct { 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 @@ -21872,11 +21876,6 @@ type SentinelAppBinaryMutation struct { app_binary_report_sequence *int64 addapp_binary_report_sequence *int64 clearedFields map[string]struct{} - sentinel_library *int - clearedsentinel_library bool - sentinel_app_binary_file map[int]struct{} - removedsentinel_app_binary_file map[int]struct{} - clearedsentinel_app_binary_file bool done bool oldValue func(context.Context) (*SentinelAppBinary, error) predicates []predicate.SentinelAppBinary @@ -21980,40 +21979,116 @@ func (m *SentinelAppBinaryMutation) IDs(ctx context.Context) ([]int, error) { } } -// SetSentinelLibraryID sets the "sentinel_library_id" field. -func (m *SentinelAppBinaryMutation) SetSentinelLibraryID(i int) { - m.sentinel_library = &i +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (m *SentinelAppBinaryMutation) SetSentinelInfoID(mi model.InternalID) { + m.sentinel_info_id = &mi + m.addsentinel_info_id = nil } -// SentinelLibraryID returns the value of the "sentinel_library_id" field in the mutation. -func (m *SentinelAppBinaryMutation) SentinelLibraryID() (r int, exists bool) { - v := m.sentinel_library +// 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 } -// OldSentinelLibraryID returns the old "sentinel_library_id" field's value of the SentinelAppBinary entity. +// 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) OldSentinelLibraryID(ctx context.Context) (v int, err error) { +func (m *SentinelAppBinaryMutation) OldSentinelInfoID(ctx context.Context) (v model.InternalID, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSentinelLibraryID is only allowed on UpdateOne operations") + return v, errors.New("OldSentinelInfoID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSentinelLibraryID requires an ID field in the mutation") + 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 OldSentinelLibraryID: %w", err) + return v, fmt.Errorf("querying old value for OldSentinelInfoID: %w", err) } - return oldValue.SentinelLibraryID, nil + return oldValue.SentinelInfoID, nil } -// ResetSentinelLibraryID resets all changes to the "sentinel_library_id" field. -func (m *SentinelAppBinaryMutation) ResetSentinelLibraryID() { - m.sentinel_library = 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. @@ -22468,87 +22543,6 @@ func (m *SentinelAppBinaryMutation) ResetAppBinaryReportSequence() { m.addapp_binary_report_sequence = nil } -// ClearSentinelLibrary clears the "sentinel_library" edge to the SentinelLibrary entity. -func (m *SentinelAppBinaryMutation) ClearSentinelLibrary() { - m.clearedsentinel_library = true - m.clearedFields[sentinelappbinary.FieldSentinelLibraryID] = struct{}{} -} - -// SentinelLibraryCleared reports if the "sentinel_library" edge to the SentinelLibrary entity was cleared. -func (m *SentinelAppBinaryMutation) SentinelLibraryCleared() bool { - return m.clearedsentinel_library -} - -// SentinelLibraryIDs returns the "sentinel_library" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// SentinelLibraryID instead. It exists only for internal usage by the builders. -func (m *SentinelAppBinaryMutation) SentinelLibraryIDs() (ids []int) { - if id := m.sentinel_library; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetSentinelLibrary resets all changes to the "sentinel_library" edge. -func (m *SentinelAppBinaryMutation) ResetSentinelLibrary() { - m.sentinel_library = nil - m.clearedsentinel_library = false -} - -// AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by ids. -func (m *SentinelAppBinaryMutation) AddSentinelAppBinaryFileIDs(ids ...int) { - if m.sentinel_app_binary_file == nil { - m.sentinel_app_binary_file = make(map[int]struct{}) - } - for i := range ids { - m.sentinel_app_binary_file[ids[i]] = struct{}{} - } -} - -// ClearSentinelAppBinaryFile clears the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity. -func (m *SentinelAppBinaryMutation) ClearSentinelAppBinaryFile() { - m.clearedsentinel_app_binary_file = true -} - -// SentinelAppBinaryFileCleared reports if the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity was cleared. -func (m *SentinelAppBinaryMutation) SentinelAppBinaryFileCleared() bool { - return m.clearedsentinel_app_binary_file -} - -// RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (m *SentinelAppBinaryMutation) RemoveSentinelAppBinaryFileIDs(ids ...int) { - if m.removedsentinel_app_binary_file == nil { - m.removedsentinel_app_binary_file = make(map[int]struct{}) - } - for i := range ids { - delete(m.sentinel_app_binary_file, ids[i]) - m.removedsentinel_app_binary_file[ids[i]] = struct{}{} - } -} - -// RemovedSentinelAppBinaryFile returns the removed IDs of the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity. -func (m *SentinelAppBinaryMutation) RemovedSentinelAppBinaryFileIDs() (ids []int) { - for id := range m.removedsentinel_app_binary_file { - ids = append(ids, id) - } - return -} - -// SentinelAppBinaryFileIDs returns the "sentinel_app_binary_file" edge IDs in the mutation. -func (m *SentinelAppBinaryMutation) SentinelAppBinaryFileIDs() (ids []int) { - for id := range m.sentinel_app_binary_file { - ids = append(ids, id) - } - return -} - -// ResetSentinelAppBinaryFile resets all changes to the "sentinel_app_binary_file" edge. -func (m *SentinelAppBinaryMutation) ResetSentinelAppBinaryFile() { - m.sentinel_app_binary_file = nil - m.clearedsentinel_app_binary_file = false - m.removedsentinel_app_binary_file = nil -} - // Where appends a list predicates to the SentinelAppBinaryMutation builder. func (m *SentinelAppBinaryMutation) Where(ps ...predicate.SentinelAppBinary) { m.predicates = append(m.predicates, ps...) @@ -22583,9 +22577,12 @@ func (m *SentinelAppBinaryMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *SentinelAppBinaryMutation) Fields() []string { - fields := make([]string, 0, 11) - if m.sentinel_library != nil { - fields = append(fields, sentinelappbinary.FieldSentinelLibraryID) + 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) @@ -22625,8 +22622,10 @@ func (m *SentinelAppBinaryMutation) Fields() []string { // schema. func (m *SentinelAppBinaryMutation) Field(name string) (ent.Value, bool) { switch name { - case sentinelappbinary.FieldSentinelLibraryID: - return m.SentinelLibraryID() + case sentinelappbinary.FieldSentinelInfoID: + return m.SentinelInfoID() + case sentinelappbinary.FieldSentinelLibraryReportedID: + return m.SentinelLibraryReportedID() case sentinelappbinary.FieldGeneratedID: return m.GeneratedID() case sentinelappbinary.FieldSizeBytes: @@ -22656,8 +22655,10 @@ func (m *SentinelAppBinaryMutation) Field(name string) (ent.Value, bool) { // database failed. func (m *SentinelAppBinaryMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case sentinelappbinary.FieldSentinelLibraryID: - return m.OldSentinelLibraryID(ctx) + case sentinelappbinary.FieldSentinelInfoID: + return m.OldSentinelInfoID(ctx) + case sentinelappbinary.FieldSentinelLibraryReportedID: + return m.OldSentinelLibraryReportedID(ctx) case sentinelappbinary.FieldGeneratedID: return m.OldGeneratedID(ctx) case sentinelappbinary.FieldSizeBytes: @@ -22687,12 +22688,19 @@ func (m *SentinelAppBinaryMutation) OldField(ctx context.Context, name string) ( // type. func (m *SentinelAppBinaryMutation) SetField(name string, value ent.Value) error { switch name { - case sentinelappbinary.FieldSentinelLibraryID: - v, ok := value.(int) + case sentinelappbinary.FieldSentinelInfoID: + v, ok := value.(model.InternalID) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetSentinelLibraryID(v) + 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) @@ -22772,6 +22780,12 @@ func (m *SentinelAppBinaryMutation) SetField(name string, value ent.Value) error // 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) } @@ -22786,6 +22800,10 @@ func (m *SentinelAppBinaryMutation) AddedFields() []string { // 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: @@ -22799,6 +22817,20 @@ func (m *SentinelAppBinaryMutation) AddedField(name string) (ent.Value, bool) { // 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 { @@ -22867,8 +22899,11 @@ func (m *SentinelAppBinaryMutation) ClearField(name string) error { // It returns an error if the field is not defined in the schema. func (m *SentinelAppBinaryMutation) ResetField(name string) error { switch name { - case sentinelappbinary.FieldSentinelLibraryID: - m.ResetSentinelLibraryID() + case sentinelappbinary.FieldSentinelInfoID: + m.ResetSentinelInfoID() + return nil + case sentinelappbinary.FieldSentinelLibraryReportedID: + m.ResetSentinelLibraryReportedID() return nil case sentinelappbinary.FieldGeneratedID: m.ResetGeneratedID() @@ -22906,128 +22941,77 @@ func (m *SentinelAppBinaryMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *SentinelAppBinaryMutation) AddedEdges() []string { - edges := make([]string, 0, 2) - if m.sentinel_library != nil { - edges = append(edges, sentinelappbinary.EdgeSentinelLibrary) - } - if m.sentinel_app_binary_file != nil { - edges = append(edges, sentinelappbinary.EdgeSentinelAppBinaryFile) - } + 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 { - switch name { - case sentinelappbinary.EdgeSentinelLibrary: - if id := m.sentinel_library; id != nil { - return []ent.Value{*id} - } - case sentinelappbinary.EdgeSentinelAppBinaryFile: - ids := make([]ent.Value, 0, len(m.sentinel_app_binary_file)) - for id := range m.sentinel_app_binary_file { - ids = append(ids, id) - } - return ids - } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *SentinelAppBinaryMutation) RemovedEdges() []string { - edges := make([]string, 0, 2) - if m.removedsentinel_app_binary_file != nil { - edges = append(edges, sentinelappbinary.EdgeSentinelAppBinaryFile) - } + 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 { - switch name { - case sentinelappbinary.EdgeSentinelAppBinaryFile: - ids := make([]ent.Value, 0, len(m.removedsentinel_app_binary_file)) - for id := range m.removedsentinel_app_binary_file { - ids = append(ids, id) - } - return ids - } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SentinelAppBinaryMutation) ClearedEdges() []string { - edges := make([]string, 0, 2) - if m.clearedsentinel_library { - edges = append(edges, sentinelappbinary.EdgeSentinelLibrary) - } - if m.clearedsentinel_app_binary_file { - edges = append(edges, sentinelappbinary.EdgeSentinelAppBinaryFile) - } + 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 { - switch name { - case sentinelappbinary.EdgeSentinelLibrary: - return m.clearedsentinel_library - case sentinelappbinary.EdgeSentinelAppBinaryFile: - return m.clearedsentinel_app_binary_file - } 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 { - switch name { - case sentinelappbinary.EdgeSentinelLibrary: - m.ClearSentinelLibrary() - return nil - } 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 { - switch name { - case sentinelappbinary.EdgeSentinelLibrary: - m.ResetSentinelLibrary() - return nil - case sentinelappbinary.EdgeSentinelAppBinaryFile: - m.ResetSentinelAppBinaryFile() - return nil - } 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 - 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{} - sentinel_app_binary *int - clearedsentinel_app_binary bool - done bool - oldValue func(context.Context) (*SentinelAppBinaryFile, error) - predicates []predicate.SentinelAppBinaryFile + 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) @@ -23128,40 +23112,152 @@ func (m *SentinelAppBinaryFileMutation) IDs(ctx context.Context) ([]int, error) } } -// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (m *SentinelAppBinaryFileMutation) SetSentinelAppBinaryID(i int) { - m.sentinel_app_binary = &i +// 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 } -// SentinelAppBinaryID returns the value of the "sentinel_app_binary_id" field in the mutation. -func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryID() (r int, exists bool) { - v := m.sentinel_app_binary +// 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 } -// OldSentinelAppBinaryID returns the old "sentinel_app_binary_id" field's value of the SentinelAppBinaryFile entity. +// 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) OldSentinelAppBinaryID(ctx context.Context) (v int, err error) { +func (m *SentinelAppBinaryFileMutation) OldSentinelAppBinaryGeneratedID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSentinelAppBinaryID is only allowed on UpdateOne operations") + return v, errors.New("OldSentinelAppBinaryGeneratedID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSentinelAppBinaryID requires an ID field in the mutation") + 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 OldSentinelAppBinaryID: %w", err) + return v, fmt.Errorf("querying old value for OldSentinelAppBinaryGeneratedID: %w", err) } - return oldValue.SentinelAppBinaryID, nil + return oldValue.SentinelAppBinaryGeneratedID, nil } -// ResetSentinelAppBinaryID resets all changes to the "sentinel_app_binary_id" field. -func (m *SentinelAppBinaryFileMutation) ResetSentinelAppBinaryID() { - m.sentinel_app_binary = 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. @@ -23505,33 +23601,6 @@ func (m *SentinelAppBinaryFileMutation) ResetAppBinaryReportSequence() { m.addapp_binary_report_sequence = nil } -// ClearSentinelAppBinary clears the "sentinel_app_binary" edge to the SentinelAppBinary entity. -func (m *SentinelAppBinaryFileMutation) ClearSentinelAppBinary() { - m.clearedsentinel_app_binary = true - m.clearedFields[sentinelappbinaryfile.FieldSentinelAppBinaryID] = struct{}{} -} - -// SentinelAppBinaryCleared reports if the "sentinel_app_binary" edge to the SentinelAppBinary entity was cleared. -func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryCleared() bool { - return m.clearedsentinel_app_binary -} - -// SentinelAppBinaryIDs returns the "sentinel_app_binary" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// SentinelAppBinaryID instead. It exists only for internal usage by the builders. -func (m *SentinelAppBinaryFileMutation) SentinelAppBinaryIDs() (ids []int) { - if id := m.sentinel_app_binary; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetSentinelAppBinary resets all changes to the "sentinel_app_binary" edge. -func (m *SentinelAppBinaryFileMutation) ResetSentinelAppBinary() { - m.sentinel_app_binary = nil - m.clearedsentinel_app_binary = false -} - // Where appends a list predicates to the SentinelAppBinaryFileMutation builder. func (m *SentinelAppBinaryFileMutation) Where(ps ...predicate.SentinelAppBinaryFile) { m.predicates = append(m.predicates, ps...) @@ -23566,9 +23635,15 @@ func (m *SentinelAppBinaryFileMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *SentinelAppBinaryFileMutation) Fields() []string { - fields := make([]string, 0, 9) - if m.sentinel_app_binary != nil { - fields = append(fields, sentinelappbinaryfile.FieldSentinelAppBinaryID) + 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) @@ -23602,8 +23677,12 @@ func (m *SentinelAppBinaryFileMutation) Fields() []string { // schema. func (m *SentinelAppBinaryFileMutation) Field(name string) (ent.Value, bool) { switch name { - case sentinelappbinaryfile.FieldSentinelAppBinaryID: - return m.SentinelAppBinaryID() + 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: @@ -23629,8 +23708,12 @@ func (m *SentinelAppBinaryFileMutation) Field(name string) (ent.Value, bool) { // database failed. func (m *SentinelAppBinaryFileMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { - case sentinelappbinaryfile.FieldSentinelAppBinaryID: - return m.OldSentinelAppBinaryID(ctx) + 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: @@ -23656,12 +23739,26 @@ func (m *SentinelAppBinaryFileMutation) OldField(ctx context.Context, name strin // type. func (m *SentinelAppBinaryFileMutation) SetField(name string, value ent.Value) error { switch name { - case sentinelappbinaryfile.FieldSentinelAppBinaryID: - v, ok := value.(int) + 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.SetSentinelAppBinaryID(v) + 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) @@ -23727,6 +23824,12 @@ func (m *SentinelAppBinaryFileMutation) SetField(name string, value ent.Value) e // 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) } @@ -23741,6 +23844,10 @@ func (m *SentinelAppBinaryFileMutation) AddedFields() []string { // 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: @@ -23754,6 +23861,20 @@ func (m *SentinelAppBinaryFileMutation) AddedField(name string) (ent.Value, bool // 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 { @@ -23804,8 +23925,14 @@ func (m *SentinelAppBinaryFileMutation) ClearField(name string) error { // It returns an error if the field is not defined in the schema. func (m *SentinelAppBinaryFileMutation) ResetField(name string) error { switch name { - case sentinelappbinaryfile.FieldSentinelAppBinaryID: - m.ResetSentinelAppBinaryID() + 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() @@ -23837,28 +23964,19 @@ func (m *SentinelAppBinaryFileMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *SentinelAppBinaryFileMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.sentinel_app_binary != nil { - edges = append(edges, sentinelappbinaryfile.EdgeSentinelAppBinary) - } + 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 { - switch name { - case sentinelappbinaryfile.EdgeSentinelAppBinary: - if id := m.sentinel_app_binary; id != nil { - return []ent.Value{*id} - } - } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *SentinelAppBinaryFileMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) + edges := make([]string, 0, 0) return edges } @@ -23870,42 +23988,25 @@ func (m *SentinelAppBinaryFileMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SentinelAppBinaryFileMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.clearedsentinel_app_binary { - edges = append(edges, sentinelappbinaryfile.EdgeSentinelAppBinary) - } + 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 { - switch name { - case sentinelappbinaryfile.EdgeSentinelAppBinary: - return m.clearedsentinel_app_binary - } 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 { - switch name { - case sentinelappbinaryfile.EdgeSentinelAppBinary: - m.ClearSentinelAppBinary() - return nil - } 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 { - switch name { - case sentinelappbinaryfile.EdgeSentinelAppBinary: - m.ResetSentinelAppBinary() - return nil - } return fmt.Errorf("unknown SentinelAppBinaryFile edge %s", name) } @@ -24855,9 +24956,6 @@ type SentinelLibraryMutation struct { clearedFields map[string]struct{} sentinel_info *model.InternalID clearedsentinel_info bool - sentinel_app_binary map[int]struct{} - removedsentinel_app_binary map[int]struct{} - clearedsentinel_app_binary bool done bool oldValue func(context.Context) (*SentinelLibrary, error) predicates []predicate.SentinelLibrary @@ -25244,60 +25342,6 @@ func (m *SentinelLibraryMutation) ResetSentinelInfo() { m.clearedsentinel_info = false } -// AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by ids. -func (m *SentinelLibraryMutation) AddSentinelAppBinaryIDs(ids ...int) { - if m.sentinel_app_binary == nil { - m.sentinel_app_binary = make(map[int]struct{}) - } - for i := range ids { - m.sentinel_app_binary[ids[i]] = struct{}{} - } -} - -// ClearSentinelAppBinary clears the "sentinel_app_binary" edge to the SentinelAppBinary entity. -func (m *SentinelLibraryMutation) ClearSentinelAppBinary() { - m.clearedsentinel_app_binary = true -} - -// SentinelAppBinaryCleared reports if the "sentinel_app_binary" edge to the SentinelAppBinary entity was cleared. -func (m *SentinelLibraryMutation) SentinelAppBinaryCleared() bool { - return m.clearedsentinel_app_binary -} - -// RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (m *SentinelLibraryMutation) RemoveSentinelAppBinaryIDs(ids ...int) { - if m.removedsentinel_app_binary == nil { - m.removedsentinel_app_binary = make(map[int]struct{}) - } - for i := range ids { - delete(m.sentinel_app_binary, ids[i]) - m.removedsentinel_app_binary[ids[i]] = struct{}{} - } -} - -// RemovedSentinelAppBinary returns the removed IDs of the "sentinel_app_binary" edge to the SentinelAppBinary entity. -func (m *SentinelLibraryMutation) RemovedSentinelAppBinaryIDs() (ids []int) { - for id := range m.removedsentinel_app_binary { - ids = append(ids, id) - } - return -} - -// SentinelAppBinaryIDs returns the "sentinel_app_binary" edge IDs in the mutation. -func (m *SentinelLibraryMutation) SentinelAppBinaryIDs() (ids []int) { - for id := range m.sentinel_app_binary { - ids = append(ids, id) - } - return -} - -// ResetSentinelAppBinary resets all changes to the "sentinel_app_binary" edge. -func (m *SentinelLibraryMutation) ResetSentinelAppBinary() { - m.sentinel_app_binary = nil - m.clearedsentinel_app_binary = false - m.removedsentinel_app_binary = nil -} - // Where appends a list predicates to the SentinelLibraryMutation builder. func (m *SentinelLibraryMutation) Where(ps ...predicate.SentinelLibrary) { m.predicates = append(m.predicates, ps...) @@ -25543,13 +25587,10 @@ func (m *SentinelLibraryMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *SentinelLibraryMutation) AddedEdges() []string { - edges := make([]string, 0, 2) + edges := make([]string, 0, 1) if m.sentinel_info != nil { edges = append(edges, sentinellibrary.EdgeSentinelInfo) } - if m.sentinel_app_binary != nil { - edges = append(edges, sentinellibrary.EdgeSentinelAppBinary) - } return edges } @@ -25561,48 +25602,28 @@ func (m *SentinelLibraryMutation) AddedIDs(name string) []ent.Value { if id := m.sentinel_info; id != nil { return []ent.Value{*id} } - case sentinellibrary.EdgeSentinelAppBinary: - ids := make([]ent.Value, 0, len(m.sentinel_app_binary)) - for id := range m.sentinel_app_binary { - ids = append(ids, id) - } - return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *SentinelLibraryMutation) RemovedEdges() []string { - edges := make([]string, 0, 2) - if m.removedsentinel_app_binary != nil { - edges = append(edges, sentinellibrary.EdgeSentinelAppBinary) - } + 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 { - switch name { - case sentinellibrary.EdgeSentinelAppBinary: - ids := make([]ent.Value, 0, len(m.removedsentinel_app_binary)) - for id := range m.removedsentinel_app_binary { - ids = append(ids, id) - } - return ids - } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SentinelLibraryMutation) ClearedEdges() []string { - edges := make([]string, 0, 2) + edges := make([]string, 0, 1) if m.clearedsentinel_info { edges = append(edges, sentinellibrary.EdgeSentinelInfo) } - if m.clearedsentinel_app_binary { - edges = append(edges, sentinellibrary.EdgeSentinelAppBinary) - } return edges } @@ -25612,8 +25633,6 @@ func (m *SentinelLibraryMutation) EdgeCleared(name string) bool { switch name { case sentinellibrary.EdgeSentinelInfo: return m.clearedsentinel_info - case sentinellibrary.EdgeSentinelAppBinary: - return m.clearedsentinel_app_binary } return false } @@ -25636,9 +25655,6 @@ func (m *SentinelLibraryMutation) ResetEdge(name string) error { case sentinellibrary.EdgeSentinelInfo: m.ResetSentinelInfo() return nil - case sentinellibrary.EdgeSentinelAppBinary: - m.ResetSentinelAppBinary() - return nil } return fmt.Errorf("unknown SentinelLibrary edge %s", name) } diff --git a/internal/data/internal/ent/runtime.go b/internal/data/internal/ent/runtime.go index 821891c6..faaa2d61 100644 --- a/internal/data/internal/ent/runtime.go +++ b/internal/data/internal/ent/runtime.go @@ -314,25 +314,25 @@ func init() { sentinelappbinaryFields := schema.SentinelAppBinary{}.Fields() _ = sentinelappbinaryFields // sentinelappbinaryDescUpdatedAt is the schema descriptor for updated_at field. - sentinelappbinaryDescUpdatedAt := sentinelappbinaryFields[8].Descriptor() + 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[9].Descriptor() + 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[6].Descriptor() + 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[7].Descriptor() + 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() diff --git a/internal/data/internal/ent/schema/sentinel_app_binary.go b/internal/data/internal/ent/schema/sentinel_app_binary.go index 1b6a590e..5c0d8aca 100644 --- a/internal/data/internal/ent/schema/sentinel_app_binary.go +++ b/internal/data/internal/ent/schema/sentinel_app_binary.go @@ -3,8 +3,9 @@ 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" ) @@ -15,7 +16,9 @@ type SentinelAppBinary struct { func (SentinelAppBinary) Fields() []ent.Field { return []ent.Field{ - field.Int("sentinel_library_id"), + // 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"), @@ -33,7 +36,9 @@ func (SentinelAppBinary) Fields() []ent.Field { func (SentinelAppBinary) Indexes() []ent.Index { return []ent.Index{ - index.Fields("sentinel_library_id", "generated_id"). + // 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"), @@ -42,11 +47,11 @@ func (SentinelAppBinary) Indexes() []ent.Index { 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"), + // 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 index da8c3bed..9f9aa869 100644 --- a/internal/data/internal/ent/schema/sentinel_app_binary_file.go +++ b/internal/data/internal/ent/schema/sentinel_app_binary_file.go @@ -3,8 +3,9 @@ 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" ) @@ -15,7 +16,10 @@ type SentinelAppBinaryFile struct { func (SentinelAppBinaryFile) Fields() []ent.Field { return []ent.Field{ - field.Int("sentinel_app_binary_id"), + // 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"), @@ -31,7 +35,10 @@ func (SentinelAppBinaryFile) Fields() []ent.Field { func (SentinelAppBinaryFile) Indexes() []ent.Index { return []ent.Index{ - index.Fields("sentinel_app_binary_id", "server_file_path"). + // 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"), } @@ -39,9 +46,9 @@ func (SentinelAppBinaryFile) Indexes() []ent.Index { func (SentinelAppBinaryFile) Edges() []ent.Edge { return []ent.Edge{ - edge.To("sentinel_app_binary", SentinelAppBinary.Type). - Required(). - Unique(). - Field("sentinel_app_binary_id"), + // edge.To("sentinel_app_binary", SentinelAppBinary.Type). + // Required(). + // Unique(). + // Field("sentinel_app_binary_id"), } } diff --git a/internal/data/internal/ent/schema/sentinel_library.go b/internal/data/internal/ent/schema/sentinel_library.go index 988a8762..730db502 100644 --- a/internal/data/internal/ent/schema/sentinel_library.go +++ b/internal/data/internal/ent/schema/sentinel_library.go @@ -42,7 +42,7 @@ func (SentinelLibrary) Edges() []ent.Edge { Required(). Unique(). Field("sentinel_info_id"), - edge.From("sentinel_app_binary", SentinelAppBinary.Type). - Ref("sentinel_library"), + // 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 index 2f2b3b2e..19165b83 100644 --- a/internal/data/internal/ent/sentinelappbinary.go +++ b/internal/data/internal/ent/sentinelappbinary.go @@ -10,7 +10,7 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" - "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" + "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinary is the model entity for the SentinelAppBinary schema. @@ -18,8 +18,10 @@ type SentinelAppBinary struct { config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` - // SentinelLibraryID holds the value of the "sentinel_library_id" field. - SentinelLibraryID int `json:"sentinel_library_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. @@ -40,41 +42,7 @@ type SentinelAppBinary struct { 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"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the SentinelAppBinaryQuery when eager-loading is set. - Edges SentinelAppBinaryEdges `json:"edges"` - selectValues sql.SelectValues -} - -// SentinelAppBinaryEdges holds the relations/edges for other nodes in the graph. -type SentinelAppBinaryEdges struct { - // SentinelLibrary holds the value of the sentinel_library edge. - SentinelLibrary *SentinelLibrary `json:"sentinel_library,omitempty"` - // SentinelAppBinaryFile holds the value of the sentinel_app_binary_file edge. - SentinelAppBinaryFile []*SentinelAppBinaryFile `json:"sentinel_app_binary_file,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [2]bool -} - -// SentinelLibraryOrErr returns the SentinelLibrary value or an error if the edge -// was not loaded in eager-loading, or loaded but was not found. -func (e SentinelAppBinaryEdges) SentinelLibraryOrErr() (*SentinelLibrary, error) { - if e.SentinelLibrary != nil { - return e.SentinelLibrary, nil - } else if e.loadedTypes[0] { - return nil, &NotFoundError{label: sentinellibrary.Label} - } - return nil, &NotLoadedError{edge: "sentinel_library"} -} - -// SentinelAppBinaryFileOrErr returns the SentinelAppBinaryFile value or an error if the edge -// was not loaded in eager-loading. -func (e SentinelAppBinaryEdges) SentinelAppBinaryFileOrErr() ([]*SentinelAppBinaryFile, error) { - if e.loadedTypes[1] { - return e.SentinelAppBinaryFile, nil - } - return nil, &NotLoadedError{edge: "sentinel_app_binary_file"} + selectValues sql.SelectValues } // scanValues returns the types for scanning values from sql.Rows. @@ -84,7 +52,7 @@ func (*SentinelAppBinary) scanValues(columns []string) ([]any, error) { switch columns[i] { case sentinelappbinary.FieldNeedToken: values[i] = new(sql.NullBool) - case sentinelappbinary.FieldID, sentinelappbinary.FieldSentinelLibraryID, sentinelappbinary.FieldSizeBytes, sentinelappbinary.FieldAppBinaryReportSequence: + 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) @@ -111,11 +79,17 @@ func (sab *SentinelAppBinary) assignValues(columns []string, values []any) error return fmt.Errorf("unexpected type %T for field id", value) } sab.ID = int(value.Int64) - case sentinelappbinary.FieldSentinelLibraryID: + case sentinelappbinary.FieldSentinelInfoID: if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field sentinel_library_id", values[i]) + return fmt.Errorf("unexpected type %T for field sentinel_info_id", values[i]) } else if value.Valid { - sab.SentinelLibraryID = int(value.Int64) + 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 { @@ -190,16 +164,6 @@ func (sab *SentinelAppBinary) Value(name string) (ent.Value, error) { return sab.selectValues.Get(name) } -// QuerySentinelLibrary queries the "sentinel_library" edge of the SentinelAppBinary entity. -func (sab *SentinelAppBinary) QuerySentinelLibrary() *SentinelLibraryQuery { - return NewSentinelAppBinaryClient(sab.config).QuerySentinelLibrary(sab) -} - -// QuerySentinelAppBinaryFile queries the "sentinel_app_binary_file" edge of the SentinelAppBinary entity. -func (sab *SentinelAppBinary) QuerySentinelAppBinaryFile() *SentinelAppBinaryFileQuery { - return NewSentinelAppBinaryClient(sab.config).QuerySentinelAppBinaryFile(sab) -} - // 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. @@ -223,8 +187,11 @@ func (sab *SentinelAppBinary) String() string { var builder strings.Builder builder.WriteString("SentinelAppBinary(") builder.WriteString(fmt.Sprintf("id=%v, ", sab.ID)) - builder.WriteString("sentinel_library_id=") - builder.WriteString(fmt.Sprintf("%v", sab.SentinelLibraryID)) + 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) diff --git a/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go b/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go index acbecd70..599cd42a 100644 --- a/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go +++ b/internal/data/internal/ent/sentinelappbinary/sentinelappbinary.go @@ -6,7 +6,6 @@ import ( "time" "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" ) const ( @@ -14,8 +13,10 @@ const ( Label = "sentinel_app_binary" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldSentinelLibraryID holds the string denoting the sentinel_library_id field in the database. - FieldSentinelLibraryID = "sentinel_library_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. @@ -36,32 +37,15 @@ const ( FieldCreatedAt = "created_at" // 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" - // EdgeSentinelAppBinaryFile holds the string denoting the sentinel_app_binary_file edge name in mutations. - EdgeSentinelAppBinaryFile = "sentinel_app_binary_file" // Table holds the table name of the sentinelappbinary in the database. Table = "sentinel_app_binaries" - // SentinelLibraryTable is the table that holds the sentinel_library relation/edge. - SentinelLibraryTable = "sentinel_app_binaries" - // 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_library_id" - // SentinelAppBinaryFileTable is the table that holds the sentinel_app_binary_file relation/edge. - SentinelAppBinaryFileTable = "sentinel_app_binary_files" - // SentinelAppBinaryFileInverseTable is the table name for the SentinelAppBinaryFile entity. - // It exists in this package in order to avoid circular dependency with the "sentinelappbinaryfile" package. - SentinelAppBinaryFileInverseTable = "sentinel_app_binary_files" - // SentinelAppBinaryFileColumn is the table column denoting the sentinel_app_binary_file relation/edge. - SentinelAppBinaryFileColumn = "sentinel_app_binary_id" ) // Columns holds all SQL columns for sentinelappbinary fields. var Columns = []string{ FieldID, - FieldSentinelLibraryID, + FieldSentinelInfoID, + FieldSentinelLibraryReportedID, FieldGeneratedID, FieldSizeBytes, FieldNeedToken, @@ -101,9 +85,14 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } -// BySentinelLibraryID orders the results by the sentinel_library_id field. -func BySentinelLibraryID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldSentinelLibraryID, 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. @@ -155,38 +144,3 @@ func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { func ByAppBinaryReportSequence(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldAppBinaryReportSequence, opts...).ToFunc() } - -// BySentinelLibraryField orders the results by sentinel_library field. -func BySentinelLibraryField(field string, opts ...sql.OrderTermOption) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newSentinelLibraryStep(), sql.OrderByField(field, opts...)) - } -} - -// BySentinelAppBinaryFileCount orders the results by sentinel_app_binary_file count. -func BySentinelAppBinaryFileCount(opts ...sql.OrderTermOption) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborsCount(s, newSentinelAppBinaryFileStep(), opts...) - } -} - -// BySentinelAppBinaryFile orders the results by sentinel_app_binary_file terms. -func BySentinelAppBinaryFile(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newSentinelAppBinaryFileStep(), append([]sql.OrderTerm{term}, terms...)...) - } -} -func newSentinelLibraryStep() *sqlgraph.Step { - return sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(SentinelLibraryInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, SentinelLibraryTable, SentinelLibraryColumn), - ) -} -func newSentinelAppBinaryFileStep() *sqlgraph.Step { - return sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(SentinelAppBinaryFileInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, SentinelAppBinaryFileTable, SentinelAppBinaryFileColumn), - ) -} diff --git a/internal/data/internal/ent/sentinelappbinary/where.go b/internal/data/internal/ent/sentinelappbinary/where.go index 8d6bde8e..347a35fe 100644 --- a/internal/data/internal/ent/sentinelappbinary/where.go +++ b/internal/data/internal/ent/sentinelappbinary/where.go @@ -6,8 +6,8 @@ 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. @@ -55,9 +55,15 @@ func IDLTE(id int) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldLTE(FieldID, id)) } -// SentinelLibraryID applies equality check predicate on the "sentinel_library_id" field. It's identical to SentinelLibraryIDEQ. -func SentinelLibraryID(v int) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, v)) +// 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. @@ -110,24 +116,98 @@ func AppBinaryReportSequence(v int64) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldEQ(FieldAppBinaryReportSequence, v)) } -// SentinelLibraryIDEQ applies the EQ predicate on the "sentinel_library_id" field. -func SentinelLibraryIDEQ(v int) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldEQ(FieldSentinelLibraryID, 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)) } -// SentinelLibraryIDNEQ applies the NEQ predicate on the "sentinel_library_id" field. -func SentinelLibraryIDNEQ(v int) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldNEQ(FieldSentinelLibraryID, v)) +// 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)) } -// SentinelLibraryIDIn applies the In predicate on the "sentinel_library_id" field. -func SentinelLibraryIDIn(vs ...int) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldIn(FieldSentinelLibraryID, vs...)) +// 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)) } -// SentinelLibraryIDNotIn applies the NotIn predicate on the "sentinel_library_id" field. -func SentinelLibraryIDNotIn(vs ...int) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(sql.FieldNotIn(FieldSentinelLibraryID, vs...)) +// 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. @@ -665,52 +745,6 @@ func AppBinaryReportSequenceLTE(v int64) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.FieldLTE(FieldAppBinaryReportSequence, v)) } -// HasSentinelLibrary applies the HasEdge predicate on the "sentinel_library" edge. -func HasSentinelLibrary() predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, 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.SentinelAppBinary { - return predicate.SentinelAppBinary(func(s *sql.Selector) { - step := newSentinelLibraryStep() - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// HasSentinelAppBinaryFile applies the HasEdge predicate on the "sentinel_app_binary_file" edge. -func HasSentinelAppBinaryFile() predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, SentinelAppBinaryFileTable, SentinelAppBinaryFileColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasSentinelAppBinaryFileWith applies the HasEdge predicate on the "sentinel_app_binary_file" edge with a given conditions (other predicates). -func HasSentinelAppBinaryFileWith(preds ...predicate.SentinelAppBinaryFile) predicate.SentinelAppBinary { - return predicate.SentinelAppBinary(func(s *sql.Selector) { - step := newSentinelAppBinaryFileStep() - 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.SentinelAppBinary) predicate.SentinelAppBinary { return predicate.SentinelAppBinary(sql.AndPredicates(predicates...)) diff --git a/internal/data/internal/ent/sentinelappbinary_create.go b/internal/data/internal/ent/sentinelappbinary_create.go index fc9aeaec..c841b3d2 100644 --- a/internal/data/internal/ent/sentinelappbinary_create.go +++ b/internal/data/internal/ent/sentinelappbinary_create.go @@ -12,8 +12,7 @@ import ( "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/data/internal/ent/sentinelappbinaryfile" - "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" + "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryCreate is the builder for creating a SentinelAppBinary entity. @@ -24,9 +23,15 @@ type SentinelAppBinaryCreate struct { conflict []sql.ConflictOption } -// SetSentinelLibraryID sets the "sentinel_library_id" field. -func (sabc *SentinelAppBinaryCreate) SetSentinelLibraryID(i int) *SentinelAppBinaryCreate { - sabc.mutation.SetSentinelLibraryID(i) +// 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 } @@ -138,26 +143,6 @@ func (sabc *SentinelAppBinaryCreate) SetAppBinaryReportSequence(i int64) *Sentin return sabc } -// SetSentinelLibrary sets the "sentinel_library" edge to the SentinelLibrary entity. -func (sabc *SentinelAppBinaryCreate) SetSentinelLibrary(s *SentinelLibrary) *SentinelAppBinaryCreate { - return sabc.SetSentinelLibraryID(s.ID) -} - -// AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (sabc *SentinelAppBinaryCreate) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryCreate { - sabc.mutation.AddSentinelAppBinaryFileIDs(ids...) - return sabc -} - -// AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. -func (sabc *SentinelAppBinaryCreate) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryCreate { - ids := make([]int, len(s)) - for i := range s { - ids[i] = s[i].ID - } - return sabc.AddSentinelAppBinaryFileIDs(ids...) -} - // Mutation returns the SentinelAppBinaryMutation object of the builder. func (sabc *SentinelAppBinaryCreate) Mutation() *SentinelAppBinaryMutation { return sabc.mutation @@ -205,8 +190,11 @@ func (sabc *SentinelAppBinaryCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (sabc *SentinelAppBinaryCreate) check() error { - if _, ok := sabc.mutation.SentinelLibraryID(); !ok { - return &ValidationError{Name: "sentinel_library_id", err: errors.New(`ent: missing required field "SentinelAppBinary.sentinel_library_id"`)} + 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"`)} @@ -226,9 +214,6 @@ func (sabc *SentinelAppBinaryCreate) check() error { 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"`)} } - if len(sabc.mutation.SentinelLibraryIDs()) == 0 { - return &ValidationError{Name: "sentinel_library", err: errors.New(`ent: missing required edge "SentinelAppBinary.sentinel_library"`)} - } return nil } @@ -256,6 +241,14 @@ func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph _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 @@ -296,39 +289,6 @@ func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph _spec.SetField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) _node.AppBinaryReportSequence = value } - if nodes := sabc.mutation.SentinelLibraryIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: sentinelappbinary.SentinelLibraryTable, - Columns: []string{sentinelappbinary.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) - } - _node.SentinelLibraryID = nodes[0] - _spec.Edges = append(_spec.Edges, edge) - } - if nodes := sabc.mutation.SentinelAppBinaryFileIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinelappbinary.SentinelAppBinaryFileTable, - Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } return _node, _spec } @@ -336,7 +296,7 @@ func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph // of the `INSERT` statement. For example: // // client.SentinelAppBinary.Create(). -// SetSentinelLibraryID(v). +// SetSentinelInfoID(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. @@ -345,7 +305,7 @@ func (sabc *SentinelAppBinaryCreate) createSpec() (*SentinelAppBinary, *sqlgraph // // Override some of the fields with custom // // update values. // Update(func(u *ent.SentinelAppBinaryUpsert) { -// SetSentinelLibraryID(v+v). +// SetSentinelInfoID(v+v). // }). // Exec(ctx) func (sabc *SentinelAppBinaryCreate) OnConflict(opts ...sql.ConflictOption) *SentinelAppBinaryUpsertOne { @@ -381,15 +341,39 @@ type ( } ) -// SetSentinelLibraryID sets the "sentinel_library_id" field. -func (u *SentinelAppBinaryUpsert) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsert { - u.Set(sentinelappbinary.FieldSentinelLibraryID, v) +// 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 } -// UpdateSentinelLibraryID sets the "sentinel_library_id" field to the value that was provided on create. -func (u *SentinelAppBinaryUpsert) UpdateSentinelLibraryID() *SentinelAppBinaryUpsert { - u.SetExcluded(sentinelappbinary.FieldSentinelLibraryID) +// AddSentinelLibraryReportedID adds v to the "sentinel_library_reported_id" field. +func (u *SentinelAppBinaryUpsert) AddSentinelLibraryReportedID(v int64) *SentinelAppBinaryUpsert { + u.Add(sentinelappbinary.FieldSentinelLibraryReportedID, v) return u } @@ -589,17 +573,45 @@ func (u *SentinelAppBinaryUpsertOne) Update(set func(*SentinelAppBinaryUpsert)) return u } -// SetSentinelLibraryID sets the "sentinel_library_id" field. -func (u *SentinelAppBinaryUpsertOne) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsertOne { +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (u *SentinelAppBinaryUpsertOne) SetSentinelInfoID(v model.InternalID) *SentinelAppBinaryUpsertOne { return u.Update(func(s *SentinelAppBinaryUpsert) { - s.SetSentinelLibraryID(v) + s.SetSentinelInfoID(v) }) } -// UpdateSentinelLibraryID sets the "sentinel_library_id" field to the value that was provided on create. -func (u *SentinelAppBinaryUpsertOne) UpdateSentinelLibraryID() *SentinelAppBinaryUpsertOne { +// AddSentinelInfoID adds v to the "sentinel_info_id" field. +func (u *SentinelAppBinaryUpsertOne) AddSentinelInfoID(v model.InternalID) *SentinelAppBinaryUpsertOne { return u.Update(func(s *SentinelAppBinaryUpsert) { - s.UpdateSentinelLibraryID() + 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() }) } @@ -920,7 +932,7 @@ func (sabcb *SentinelAppBinaryCreateBulk) ExecX(ctx context.Context) { // // Override some of the fields with custom // // update values. // Update(func(u *ent.SentinelAppBinaryUpsert) { -// SetSentinelLibraryID(v+v). +// SetSentinelInfoID(v+v). // }). // Exec(ctx) func (sabcb *SentinelAppBinaryCreateBulk) OnConflict(opts ...sql.ConflictOption) *SentinelAppBinaryUpsertBulk { @@ -989,17 +1001,45 @@ func (u *SentinelAppBinaryUpsertBulk) Update(set func(*SentinelAppBinaryUpsert)) return u } -// SetSentinelLibraryID sets the "sentinel_library_id" field. -func (u *SentinelAppBinaryUpsertBulk) SetSentinelLibraryID(v int) *SentinelAppBinaryUpsertBulk { +// 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.SetSentinelLibraryID(v) + s.AddSentinelLibraryReportedID(v) }) } -// UpdateSentinelLibraryID sets the "sentinel_library_id" field to the value that was provided on create. -func (u *SentinelAppBinaryUpsertBulk) UpdateSentinelLibraryID() *SentinelAppBinaryUpsertBulk { +// 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.UpdateSentinelLibraryID() + s.UpdateSentinelLibraryReportedID() }) } diff --git a/internal/data/internal/ent/sentinelappbinary_query.go b/internal/data/internal/ent/sentinelappbinary_query.go index 14486346..4e318dce 100644 --- a/internal/data/internal/ent/sentinelappbinary_query.go +++ b/internal/data/internal/ent/sentinelappbinary_query.go @@ -4,7 +4,6 @@ package ent import ( "context" - "database/sql/driver" "fmt" "math" @@ -14,19 +13,15 @@ import ( "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/data/internal/ent/sentinelappbinaryfile" - "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" ) // SentinelAppBinaryQuery is the builder for querying SentinelAppBinary entities. type SentinelAppBinaryQuery struct { config - ctx *QueryContext - order []sentinelappbinary.OrderOption - inters []Interceptor - predicates []predicate.SentinelAppBinary - withSentinelLibrary *SentinelLibraryQuery - withSentinelAppBinaryFile *SentinelAppBinaryFileQuery + 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) @@ -63,50 +58,6 @@ func (sabq *SentinelAppBinaryQuery) Order(o ...sentinelappbinary.OrderOption) *S return sabq } -// QuerySentinelLibrary chains the current query on the "sentinel_library" edge. -func (sabq *SentinelAppBinaryQuery) QuerySentinelLibrary() *SentinelLibraryQuery { - query := (&SentinelLibraryClient{config: sabq.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := sabq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := sabq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(sentinelappbinary.Table, sentinelappbinary.FieldID, selector), - sqlgraph.To(sentinellibrary.Table, sentinellibrary.FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, sentinelappbinary.SentinelLibraryTable, sentinelappbinary.SentinelLibraryColumn), - ) - fromU = sqlgraph.SetNeighbors(sabq.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QuerySentinelAppBinaryFile chains the current query on the "sentinel_app_binary_file" edge. -func (sabq *SentinelAppBinaryQuery) QuerySentinelAppBinaryFile() *SentinelAppBinaryFileQuery { - query := (&SentinelAppBinaryFileClient{config: sabq.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := sabq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := sabq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(sentinelappbinary.Table, sentinelappbinary.FieldID, selector), - sqlgraph.To(sentinelappbinaryfile.Table, sentinelappbinaryfile.FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, sentinelappbinary.SentinelAppBinaryFileTable, sentinelappbinary.SentinelAppBinaryFileColumn), - ) - fromU = sqlgraph.SetNeighbors(sabq.driver.Dialect(), step) - return fromU, nil - } - return query -} - // 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) { @@ -294,53 +245,29 @@ func (sabq *SentinelAppBinaryQuery) Clone() *SentinelAppBinaryQuery { 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...), - withSentinelLibrary: sabq.withSentinelLibrary.Clone(), - withSentinelAppBinaryFile: sabq.withSentinelAppBinaryFile.Clone(), + 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, } } -// 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 (sabq *SentinelAppBinaryQuery) WithSentinelLibrary(opts ...func(*SentinelLibraryQuery)) *SentinelAppBinaryQuery { - query := (&SentinelLibraryClient{config: sabq.config}).Query() - for _, opt := range opts { - opt(query) - } - sabq.withSentinelLibrary = query - return sabq -} - -// WithSentinelAppBinaryFile tells the query-builder to eager-load the nodes that are connected to -// the "sentinel_app_binary_file" edge. The optional arguments are used to configure the query builder of the edge. -func (sabq *SentinelAppBinaryQuery) WithSentinelAppBinaryFile(opts ...func(*SentinelAppBinaryFileQuery)) *SentinelAppBinaryQuery { - query := (&SentinelAppBinaryFileClient{config: sabq.config}).Query() - for _, opt := range opts { - opt(query) - } - sabq.withSentinelAppBinaryFile = query - return sabq -} - // 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 { -// SentinelLibraryID int `json:"sentinel_library_id,omitempty"` +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` // Count int `json:"count,omitempty"` // } // // client.SentinelAppBinary.Query(). -// GroupBy(sentinelappbinary.FieldSentinelLibraryID). +// GroupBy(sentinelappbinary.FieldSentinelInfoID). // Aggregate(ent.Count()). // Scan(ctx, &v) func (sabq *SentinelAppBinaryQuery) GroupBy(field string, fields ...string) *SentinelAppBinaryGroupBy { @@ -358,11 +285,11 @@ func (sabq *SentinelAppBinaryQuery) GroupBy(field string, fields ...string) *Sen // Example: // // var v []struct { -// SentinelLibraryID int `json:"sentinel_library_id,omitempty"` +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` // } // // client.SentinelAppBinary.Query(). -// Select(sentinelappbinary.FieldSentinelLibraryID). +// Select(sentinelappbinary.FieldSentinelInfoID). // Scan(ctx, &v) func (sabq *SentinelAppBinaryQuery) Select(fields ...string) *SentinelAppBinarySelect { sabq.ctx.Fields = append(sabq.ctx.Fields, fields...) @@ -405,12 +332,8 @@ func (sabq *SentinelAppBinaryQuery) prepareQuery(ctx context.Context) error { func (sabq *SentinelAppBinaryQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SentinelAppBinary, error) { var ( - nodes = []*SentinelAppBinary{} - _spec = sabq.querySpec() - loadedTypes = [2]bool{ - sabq.withSentinelLibrary != nil, - sabq.withSentinelAppBinaryFile != nil, - } + nodes = []*SentinelAppBinary{} + _spec = sabq.querySpec() ) _spec.ScanValues = func(columns []string) ([]any, error) { return (*SentinelAppBinary).scanValues(nil, columns) @@ -418,7 +341,6 @@ func (sabq *SentinelAppBinaryQuery) sqlAll(ctx context.Context, hooks ...queryHo _spec.Assign = func(columns []string, values []any) error { node := &SentinelAppBinary{config: sabq.config} nodes = append(nodes, node) - node.Edges.loadedTypes = loadedTypes return node.assignValues(columns, values) } for i := range hooks { @@ -430,84 +352,9 @@ func (sabq *SentinelAppBinaryQuery) sqlAll(ctx context.Context, hooks ...queryHo if len(nodes) == 0 { return nodes, nil } - if query := sabq.withSentinelLibrary; query != nil { - if err := sabq.loadSentinelLibrary(ctx, query, nodes, nil, - func(n *SentinelAppBinary, e *SentinelLibrary) { n.Edges.SentinelLibrary = e }); err != nil { - return nil, err - } - } - if query := sabq.withSentinelAppBinaryFile; query != nil { - if err := sabq.loadSentinelAppBinaryFile(ctx, query, nodes, - func(n *SentinelAppBinary) { n.Edges.SentinelAppBinaryFile = []*SentinelAppBinaryFile{} }, - func(n *SentinelAppBinary, e *SentinelAppBinaryFile) { - n.Edges.SentinelAppBinaryFile = append(n.Edges.SentinelAppBinaryFile, e) - }); err != nil { - return nil, err - } - } return nodes, nil } -func (sabq *SentinelAppBinaryQuery) loadSentinelLibrary(ctx context.Context, query *SentinelLibraryQuery, nodes []*SentinelAppBinary, init func(*SentinelAppBinary), assign func(*SentinelAppBinary, *SentinelLibrary)) error { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*SentinelAppBinary) - for i := range nodes { - fk := nodes[i].SentinelLibraryID - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - if len(ids) == 0 { - return nil - } - query.Where(sentinellibrary.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_library_id" returned %v`, n.ID) - } - for i := range nodes { - assign(nodes[i], n) - } - } - return nil -} -func (sabq *SentinelAppBinaryQuery) loadSentinelAppBinaryFile(ctx context.Context, query *SentinelAppBinaryFileQuery, nodes []*SentinelAppBinary, init func(*SentinelAppBinary), assign func(*SentinelAppBinary, *SentinelAppBinaryFile)) error { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*SentinelAppBinary) - 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(sentinelappbinaryfile.FieldSentinelAppBinaryID) - } - query.Where(predicate.SentinelAppBinaryFile(func(s *sql.Selector) { - s.Where(sql.InValues(s.C(sentinelappbinary.SentinelAppBinaryFileColumn), fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - fk := n.SentinelAppBinaryID - node, ok := nodeids[fk] - if !ok { - return fmt.Errorf(`unexpected referenced foreign-key "sentinel_app_binary_id" returned %v for node %v`, fk, n.ID) - } - assign(node, n) - } - return nil -} - func (sabq *SentinelAppBinaryQuery) sqlCount(ctx context.Context) (int, error) { _spec := sabq.querySpec() _spec.Node.Columns = sabq.ctx.Fields @@ -533,9 +380,6 @@ func (sabq *SentinelAppBinaryQuery) querySpec() *sqlgraph.QuerySpec { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } - if sabq.withSentinelLibrary != nil { - _spec.Node.AddColumnOnce(sentinelappbinary.FieldSentinelLibraryID) - } } if ps := sabq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { diff --git a/internal/data/internal/ent/sentinelappbinary_update.go b/internal/data/internal/ent/sentinelappbinary_update.go index 241f2d67..9cef1b34 100644 --- a/internal/data/internal/ent/sentinelappbinary_update.go +++ b/internal/data/internal/ent/sentinelappbinary_update.go @@ -13,8 +13,7 @@ import ( "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/data/internal/ent/sentinelappbinaryfile" - "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" + "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryUpdate is the builder for updating SentinelAppBinary entities. @@ -30,20 +29,48 @@ func (sabu *SentinelAppBinaryUpdate) Where(ps ...predicate.SentinelAppBinary) *S return sabu } -// SetSentinelLibraryID sets the "sentinel_library_id" field. -func (sabu *SentinelAppBinaryUpdate) SetSentinelLibraryID(i int) *SentinelAppBinaryUpdate { - sabu.mutation.SetSentinelLibraryID(i) +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (sabu *SentinelAppBinaryUpdate) SetSentinelInfoID(mi model.InternalID) *SentinelAppBinaryUpdate { + sabu.mutation.ResetSentinelInfoID() + sabu.mutation.SetSentinelInfoID(mi) return sabu } -// SetNillableSentinelLibraryID sets the "sentinel_library_id" field if the given value is not nil. -func (sabu *SentinelAppBinaryUpdate) SetNillableSentinelLibraryID(i *int) *SentinelAppBinaryUpdate { +// 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.SetSentinelLibraryID(*i) + 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) @@ -214,58 +241,11 @@ func (sabu *SentinelAppBinaryUpdate) AddAppBinaryReportSequence(i int64) *Sentin return sabu } -// SetSentinelLibrary sets the "sentinel_library" edge to the SentinelLibrary entity. -func (sabu *SentinelAppBinaryUpdate) SetSentinelLibrary(s *SentinelLibrary) *SentinelAppBinaryUpdate { - return sabu.SetSentinelLibraryID(s.ID) -} - -// AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (sabu *SentinelAppBinaryUpdate) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdate { - sabu.mutation.AddSentinelAppBinaryFileIDs(ids...) - return sabu -} - -// AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. -func (sabu *SentinelAppBinaryUpdate) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdate { - ids := make([]int, len(s)) - for i := range s { - ids[i] = s[i].ID - } - return sabu.AddSentinelAppBinaryFileIDs(ids...) -} - // Mutation returns the SentinelAppBinaryMutation object of the builder. func (sabu *SentinelAppBinaryUpdate) Mutation() *SentinelAppBinaryMutation { return sabu.mutation } -// ClearSentinelLibrary clears the "sentinel_library" edge to the SentinelLibrary entity. -func (sabu *SentinelAppBinaryUpdate) ClearSentinelLibrary() *SentinelAppBinaryUpdate { - sabu.mutation.ClearSentinelLibrary() - return sabu -} - -// ClearSentinelAppBinaryFile clears all "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. -func (sabu *SentinelAppBinaryUpdate) ClearSentinelAppBinaryFile() *SentinelAppBinaryUpdate { - sabu.mutation.ClearSentinelAppBinaryFile() - return sabu -} - -// RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to SentinelAppBinaryFile entities by IDs. -func (sabu *SentinelAppBinaryUpdate) RemoveSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdate { - sabu.mutation.RemoveSentinelAppBinaryFileIDs(ids...) - return sabu -} - -// RemoveSentinelAppBinaryFile removes "sentinel_app_binary_file" edges to SentinelAppBinaryFile entities. -func (sabu *SentinelAppBinaryUpdate) RemoveSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdate { - ids := make([]int, len(s)) - for i := range s { - ids[i] = s[i].ID - } - return sabu.RemoveSentinelAppBinaryFileIDs(ids...) -} - // 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() @@ -302,18 +282,7 @@ func (sabu *SentinelAppBinaryUpdate) defaults() { } } -// check runs all checks and user-defined validators on the builder. -func (sabu *SentinelAppBinaryUpdate) check() error { - if sabu.mutation.SentinelLibraryCleared() && len(sabu.mutation.SentinelLibraryIDs()) > 0 { - return errors.New(`ent: clearing a required unique edge "SentinelAppBinary.sentinel_library"`) - } - return nil -} - func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err error) { - if err := sabu.check(); err != nil { - return n, err - } _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) { @@ -322,6 +291,18 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er } } } + 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) } @@ -370,80 +351,6 @@ func (sabu *SentinelAppBinaryUpdate) sqlSave(ctx context.Context) (n int, err er if value, ok := sabu.mutation.AddedAppBinaryReportSequence(); ok { _spec.AddField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) } - if sabu.mutation.SentinelLibraryCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: sentinelappbinary.SentinelLibraryTable, - Columns: []string{sentinelappbinary.SentinelLibraryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := sabu.mutation.SentinelLibraryIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: sentinelappbinary.SentinelLibraryTable, - Columns: []string{sentinelappbinary.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 sabu.mutation.SentinelAppBinaryFileCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinelappbinary.SentinelAppBinaryFileTable, - Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := sabu.mutation.RemovedSentinelAppBinaryFileIDs(); len(nodes) > 0 && !sabu.mutation.SentinelAppBinaryFileCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinelappbinary.SentinelAppBinaryFileTable, - Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.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 := sabu.mutation.SentinelAppBinaryFileIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinelappbinary.SentinelAppBinaryFileTable, - Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.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, sabu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{sentinelappbinary.Label} @@ -464,20 +371,48 @@ type SentinelAppBinaryUpdateOne struct { mutation *SentinelAppBinaryMutation } -// SetSentinelLibraryID sets the "sentinel_library_id" field. -func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelLibraryID(i int) *SentinelAppBinaryUpdateOne { - sabuo.mutation.SetSentinelLibraryID(i) +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelInfoID(mi model.InternalID) *SentinelAppBinaryUpdateOne { + sabuo.mutation.ResetSentinelInfoID() + sabuo.mutation.SetSentinelInfoID(mi) return sabuo } -// SetNillableSentinelLibraryID sets the "sentinel_library_id" field if the given value is not nil. -func (sabuo *SentinelAppBinaryUpdateOne) SetNillableSentinelLibraryID(i *int) *SentinelAppBinaryUpdateOne { +// 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.SetSentinelLibraryID(*i) + 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) @@ -648,58 +583,11 @@ func (sabuo *SentinelAppBinaryUpdateOne) AddAppBinaryReportSequence(i int64) *Se return sabuo } -// SetSentinelLibrary sets the "sentinel_library" edge to the SentinelLibrary entity. -func (sabuo *SentinelAppBinaryUpdateOne) SetSentinelLibrary(s *SentinelLibrary) *SentinelAppBinaryUpdateOne { - return sabuo.SetSentinelLibraryID(s.ID) -} - -// AddSentinelAppBinaryFileIDs adds the "sentinel_app_binary_file" edge to the SentinelAppBinaryFile entity by IDs. -func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdateOne { - sabuo.mutation.AddSentinelAppBinaryFileIDs(ids...) - return sabuo -} - -// AddSentinelAppBinaryFile adds the "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. -func (sabuo *SentinelAppBinaryUpdateOne) AddSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdateOne { - ids := make([]int, len(s)) - for i := range s { - ids[i] = s[i].ID - } - return sabuo.AddSentinelAppBinaryFileIDs(ids...) -} - // Mutation returns the SentinelAppBinaryMutation object of the builder. func (sabuo *SentinelAppBinaryUpdateOne) Mutation() *SentinelAppBinaryMutation { return sabuo.mutation } -// ClearSentinelLibrary clears the "sentinel_library" edge to the SentinelLibrary entity. -func (sabuo *SentinelAppBinaryUpdateOne) ClearSentinelLibrary() *SentinelAppBinaryUpdateOne { - sabuo.mutation.ClearSentinelLibrary() - return sabuo -} - -// ClearSentinelAppBinaryFile clears all "sentinel_app_binary_file" edges to the SentinelAppBinaryFile entity. -func (sabuo *SentinelAppBinaryUpdateOne) ClearSentinelAppBinaryFile() *SentinelAppBinaryUpdateOne { - sabuo.mutation.ClearSentinelAppBinaryFile() - return sabuo -} - -// RemoveSentinelAppBinaryFileIDs removes the "sentinel_app_binary_file" edge to SentinelAppBinaryFile entities by IDs. -func (sabuo *SentinelAppBinaryUpdateOne) RemoveSentinelAppBinaryFileIDs(ids ...int) *SentinelAppBinaryUpdateOne { - sabuo.mutation.RemoveSentinelAppBinaryFileIDs(ids...) - return sabuo -} - -// RemoveSentinelAppBinaryFile removes "sentinel_app_binary_file" edges to SentinelAppBinaryFile entities. -func (sabuo *SentinelAppBinaryUpdateOne) RemoveSentinelAppBinaryFile(s ...*SentinelAppBinaryFile) *SentinelAppBinaryUpdateOne { - ids := make([]int, len(s)) - for i := range s { - ids[i] = s[i].ID - } - return sabuo.RemoveSentinelAppBinaryFileIDs(ids...) -} - // Where appends a list predicates to the SentinelAppBinaryUpdate builder. func (sabuo *SentinelAppBinaryUpdateOne) Where(ps ...predicate.SentinelAppBinary) *SentinelAppBinaryUpdateOne { sabuo.mutation.Where(ps...) @@ -749,18 +637,7 @@ func (sabuo *SentinelAppBinaryUpdateOne) defaults() { } } -// check runs all checks and user-defined validators on the builder. -func (sabuo *SentinelAppBinaryUpdateOne) check() error { - if sabuo.mutation.SentinelLibraryCleared() && len(sabuo.mutation.SentinelLibraryIDs()) > 0 { - return errors.New(`ent: clearing a required unique edge "SentinelAppBinary.sentinel_library"`) - } - return nil -} - func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *SentinelAppBinary, err error) { - if err := sabuo.check(); err != nil { - return _node, err - } _spec := sqlgraph.NewUpdateSpec(sentinelappbinary.Table, sentinelappbinary.Columns, sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt)) id, ok := sabuo.mutation.ID() if !ok { @@ -786,6 +663,18 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se } } } + 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) } @@ -834,80 +723,6 @@ func (sabuo *SentinelAppBinaryUpdateOne) sqlSave(ctx context.Context) (_node *Se if value, ok := sabuo.mutation.AddedAppBinaryReportSequence(); ok { _spec.AddField(sentinelappbinary.FieldAppBinaryReportSequence, field.TypeInt64, value) } - if sabuo.mutation.SentinelLibraryCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: sentinelappbinary.SentinelLibraryTable, - Columns: []string{sentinelappbinary.SentinelLibraryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinellibrary.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := sabuo.mutation.SentinelLibraryIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: sentinelappbinary.SentinelLibraryTable, - Columns: []string{sentinelappbinary.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 sabuo.mutation.SentinelAppBinaryFileCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinelappbinary.SentinelAppBinaryFileTable, - Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := sabuo.mutation.RemovedSentinelAppBinaryFileIDs(); len(nodes) > 0 && !sabuo.mutation.SentinelAppBinaryFileCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinelappbinary.SentinelAppBinaryFileTable, - Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.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 := sabuo.mutation.SentinelAppBinaryFileIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinelappbinary.SentinelAppBinaryFileTable, - Columns: []string{sentinelappbinary.SentinelAppBinaryFileColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } _node = &SentinelAppBinary{config: sabuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues diff --git a/internal/data/internal/ent/sentinelappbinaryfile.go b/internal/data/internal/ent/sentinelappbinaryfile.go index f50e5d8c..f33364bf 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile.go +++ b/internal/data/internal/ent/sentinelappbinaryfile.go @@ -9,8 +9,8 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect/sql" - "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinary" "github.com/tuihub/librarian/internal/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryFile is the model entity for the SentinelAppBinaryFile schema. @@ -18,8 +18,12 @@ type SentinelAppBinaryFile struct { config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` - // SentinelAppBinaryID holds the value of the "sentinel_app_binary_id" field. - SentinelAppBinaryID int `json:"sentinel_app_binary_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. @@ -36,30 +40,7 @@ type SentinelAppBinaryFile struct { 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"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the SentinelAppBinaryFileQuery when eager-loading is set. - Edges SentinelAppBinaryFileEdges `json:"edges"` - selectValues sql.SelectValues -} - -// SentinelAppBinaryFileEdges holds the relations/edges for other nodes in the graph. -type SentinelAppBinaryFileEdges struct { - // SentinelAppBinary holds the value of the sentinel_app_binary edge. - SentinelAppBinary *SentinelAppBinary `json:"sentinel_app_binary,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [1]bool -} - -// SentinelAppBinaryOrErr returns the SentinelAppBinary value or an error if the edge -// was not loaded in eager-loading, or loaded but was not found. -func (e SentinelAppBinaryFileEdges) SentinelAppBinaryOrErr() (*SentinelAppBinary, error) { - if e.SentinelAppBinary != nil { - return e.SentinelAppBinary, nil - } else if e.loadedTypes[0] { - return nil, &NotFoundError{label: sentinelappbinary.Label} - } - return nil, &NotLoadedError{edge: "sentinel_app_binary"} + selectValues sql.SelectValues } // scanValues returns the types for scanning values from sql.Rows. @@ -69,9 +50,9 @@ func (*SentinelAppBinaryFile) scanValues(columns []string) ([]any, error) { switch columns[i] { case sentinelappbinaryfile.FieldSha256: values[i] = new([]byte) - case sentinelappbinaryfile.FieldID, sentinelappbinaryfile.FieldSentinelAppBinaryID, sentinelappbinaryfile.FieldSizeBytes, sentinelappbinaryfile.FieldAppBinaryReportSequence: + case sentinelappbinaryfile.FieldID, sentinelappbinaryfile.FieldSentinelInfoID, sentinelappbinaryfile.FieldSentinelLibraryReportedID, sentinelappbinaryfile.FieldSizeBytes, sentinelappbinaryfile.FieldAppBinaryReportSequence: values[i] = new(sql.NullInt64) - case sentinelappbinaryfile.FieldName, sentinelappbinaryfile.FieldServerFilePath, sentinelappbinaryfile.FieldChunksInfo: + case sentinelappbinaryfile.FieldSentinelAppBinaryGeneratedID, sentinelappbinaryfile.FieldName, sentinelappbinaryfile.FieldServerFilePath, sentinelappbinaryfile.FieldChunksInfo: values[i] = new(sql.NullString) case sentinelappbinaryfile.FieldUpdatedAt, sentinelappbinaryfile.FieldCreatedAt: values[i] = new(sql.NullTime) @@ -96,11 +77,23 @@ func (sabf *SentinelAppBinaryFile) assignValues(columns []string, values []any) return fmt.Errorf("unexpected type %T for field id", value) } sabf.ID = int(value.Int64) - case sentinelappbinaryfile.FieldSentinelAppBinaryID: + 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_app_binary_id", values[i]) + return fmt.Errorf("unexpected type %T for field sentinel_library_reported_id", values[i]) } else if value.Valid { - sabf.SentinelAppBinaryID = int(value.Int64) + 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 { @@ -163,11 +156,6 @@ func (sabf *SentinelAppBinaryFile) Value(name string) (ent.Value, error) { return sabf.selectValues.Get(name) } -// QuerySentinelAppBinary queries the "sentinel_app_binary" edge of the SentinelAppBinaryFile entity. -func (sabf *SentinelAppBinaryFile) QuerySentinelAppBinary() *SentinelAppBinaryQuery { - return NewSentinelAppBinaryFileClient(sabf.config).QuerySentinelAppBinary(sabf) -} - // 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. @@ -191,8 +179,14 @@ func (sabf *SentinelAppBinaryFile) String() string { var builder strings.Builder builder.WriteString("SentinelAppBinaryFile(") builder.WriteString(fmt.Sprintf("id=%v, ", sabf.ID)) - builder.WriteString("sentinel_app_binary_id=") - builder.WriteString(fmt.Sprintf("%v", sabf.SentinelAppBinaryID)) + 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) diff --git a/internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go b/internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go index 9bb26280..faaf4a12 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go +++ b/internal/data/internal/ent/sentinelappbinaryfile/sentinelappbinaryfile.go @@ -6,7 +6,6 @@ import ( "time" "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" ) const ( @@ -14,8 +13,12 @@ const ( Label = "sentinel_app_binary_file" // FieldID holds the string denoting the id field in the database. FieldID = "id" - // FieldSentinelAppBinaryID holds the string denoting the sentinel_app_binary_id field in the database. - FieldSentinelAppBinaryID = "sentinel_app_binary_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. @@ -32,23 +35,16 @@ const ( FieldCreatedAt = "created_at" // FieldAppBinaryReportSequence holds the string denoting the app_binary_report_sequence field in the database. FieldAppBinaryReportSequence = "app_binary_report_sequence" - // EdgeSentinelAppBinary holds the string denoting the sentinel_app_binary edge name in mutations. - EdgeSentinelAppBinary = "sentinel_app_binary" // Table holds the table name of the sentinelappbinaryfile in the database. Table = "sentinel_app_binary_files" - // SentinelAppBinaryTable is the table that holds the sentinel_app_binary relation/edge. - SentinelAppBinaryTable = "sentinel_app_binary_files" - // SentinelAppBinaryInverseTable is the table name for the SentinelAppBinary entity. - // It exists in this package in order to avoid circular dependency with the "sentinelappbinary" package. - SentinelAppBinaryInverseTable = "sentinel_app_binaries" - // SentinelAppBinaryColumn is the table column denoting the sentinel_app_binary relation/edge. - SentinelAppBinaryColumn = "sentinel_app_binary_id" ) // Columns holds all SQL columns for sentinelappbinaryfile fields. var Columns = []string{ FieldID, - FieldSentinelAppBinaryID, + FieldSentinelInfoID, + FieldSentinelLibraryReportedID, + FieldSentinelAppBinaryGeneratedID, FieldName, FieldSizeBytes, FieldSha256, @@ -86,9 +82,19 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } -// BySentinelAppBinaryID orders the results by the sentinel_app_binary_id field. -func BySentinelAppBinaryID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldSentinelAppBinaryID, 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. @@ -125,17 +131,3 @@ func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { func ByAppBinaryReportSequence(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldAppBinaryReportSequence, opts...).ToFunc() } - -// BySentinelAppBinaryField orders the results by sentinel_app_binary field. -func BySentinelAppBinaryField(field string, opts ...sql.OrderTermOption) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newSentinelAppBinaryStep(), sql.OrderByField(field, opts...)) - } -} -func newSentinelAppBinaryStep() *sqlgraph.Step { - return sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(SentinelAppBinaryInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, SentinelAppBinaryTable, SentinelAppBinaryColumn), - ) -} diff --git a/internal/data/internal/ent/sentinelappbinaryfile/where.go b/internal/data/internal/ent/sentinelappbinaryfile/where.go index f6f1ad62..43100946 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile/where.go +++ b/internal/data/internal/ent/sentinelappbinaryfile/where.go @@ -6,8 +6,8 @@ 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. @@ -55,9 +55,20 @@ func IDLTE(id int) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldID, id)) } -// SentinelAppBinaryID applies equality check predicate on the "sentinel_app_binary_id" field. It's identical to SentinelAppBinaryIDEQ. -func SentinelAppBinaryID(v int) predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, v)) +// 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. @@ -100,24 +111,163 @@ func AppBinaryReportSequence(v int64) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldAppBinaryReportSequence, v)) } -// SentinelAppBinaryIDEQ applies the EQ predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDEQ(v int) predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(sql.FieldEQ(FieldSentinelAppBinaryID, 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)) } -// SentinelAppBinaryIDNEQ applies the NEQ predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDNEQ(v int) predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(sql.FieldNEQ(FieldSentinelAppBinaryID, 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)) } -// SentinelAppBinaryIDIn applies the In predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDIn(vs ...int) predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(sql.FieldIn(FieldSentinelAppBinaryID, vs...)) +// 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)) } -// SentinelAppBinaryIDNotIn applies the NotIn predicate on the "sentinel_app_binary_id" field. -func SentinelAppBinaryIDNotIn(vs ...int) predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(sql.FieldNotIn(FieldSentinelAppBinaryID, vs...)) +// 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. @@ -525,29 +675,6 @@ func AppBinaryReportSequenceLTE(v int64) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.FieldLTE(FieldAppBinaryReportSequence, v)) } -// HasSentinelAppBinary applies the HasEdge predicate on the "sentinel_app_binary" edge. -func HasSentinelAppBinary() predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, SentinelAppBinaryTable, SentinelAppBinaryColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasSentinelAppBinaryWith applies the HasEdge predicate on the "sentinel_app_binary" edge with a given conditions (other predicates). -func HasSentinelAppBinaryWith(preds ...predicate.SentinelAppBinary) predicate.SentinelAppBinaryFile { - return predicate.SentinelAppBinaryFile(func(s *sql.Selector) { - step := newSentinelAppBinaryStep() - 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.SentinelAppBinaryFile) predicate.SentinelAppBinaryFile { return predicate.SentinelAppBinaryFile(sql.AndPredicates(predicates...)) diff --git a/internal/data/internal/ent/sentinelappbinaryfile_create.go b/internal/data/internal/ent/sentinelappbinaryfile_create.go index 446b0c5b..128d4f00 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile_create.go +++ b/internal/data/internal/ent/sentinelappbinaryfile_create.go @@ -11,8 +11,8 @@ import ( "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/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryFileCreate is the builder for creating a SentinelAppBinaryFile entity. @@ -23,9 +23,21 @@ type SentinelAppBinaryFileCreate struct { conflict []sql.ConflictOption } -// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (sabfc *SentinelAppBinaryFileCreate) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileCreate { - sabfc.mutation.SetSentinelAppBinaryID(i) +// 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 } @@ -101,11 +113,6 @@ func (sabfc *SentinelAppBinaryFileCreate) SetAppBinaryReportSequence(i int64) *S return sabfc } -// SetSentinelAppBinary sets the "sentinel_app_binary" edge to the SentinelAppBinary entity. -func (sabfc *SentinelAppBinaryFileCreate) SetSentinelAppBinary(s *SentinelAppBinary) *SentinelAppBinaryFileCreate { - return sabfc.SetSentinelAppBinaryID(s.ID) -} - // Mutation returns the SentinelAppBinaryFileMutation object of the builder. func (sabfc *SentinelAppBinaryFileCreate) Mutation() *SentinelAppBinaryFileMutation { return sabfc.mutation @@ -153,8 +160,14 @@ func (sabfc *SentinelAppBinaryFileCreate) defaults() { // check runs all checks and user-defined validators on the builder. func (sabfc *SentinelAppBinaryFileCreate) check() error { - if _, ok := sabfc.mutation.SentinelAppBinaryID(); !ok { - return &ValidationError{Name: "sentinel_app_binary_id", err: errors.New(`ent: missing required field "SentinelAppBinaryFile.sentinel_app_binary_id"`)} + 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"`)} @@ -177,9 +190,6 @@ func (sabfc *SentinelAppBinaryFileCreate) check() error { 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"`)} } - if len(sabfc.mutation.SentinelAppBinaryIDs()) == 0 { - return &ValidationError{Name: "sentinel_app_binary", err: errors.New(`ent: missing required edge "SentinelAppBinaryFile.sentinel_app_binary"`)} - } return nil } @@ -207,6 +217,18 @@ func (sabfc *SentinelAppBinaryFileCreate) createSpec() (*SentinelAppBinaryFile, _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 @@ -239,23 +261,6 @@ func (sabfc *SentinelAppBinaryFileCreate) createSpec() (*SentinelAppBinaryFile, _spec.SetField(sentinelappbinaryfile.FieldAppBinaryReportSequence, field.TypeInt64, value) _node.AppBinaryReportSequence = value } - if nodes := sabfc.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: sentinelappbinaryfile.SentinelAppBinaryTable, - Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _node.SentinelAppBinaryID = nodes[0] - _spec.Edges = append(_spec.Edges, edge) - } return _node, _spec } @@ -263,7 +268,7 @@ func (sabfc *SentinelAppBinaryFileCreate) createSpec() (*SentinelAppBinaryFile, // of the `INSERT` statement. For example: // // client.SentinelAppBinaryFile.Create(). -// SetSentinelAppBinaryID(v). +// SetSentinelInfoID(v). // OnConflict( // // Update the row with the new values // // the was proposed for insertion. @@ -272,7 +277,7 @@ func (sabfc *SentinelAppBinaryFileCreate) createSpec() (*SentinelAppBinaryFile, // // Override some of the fields with custom // // update values. // Update(func(u *ent.SentinelAppBinaryFileUpsert) { -// SetSentinelAppBinaryID(v+v). +// SetSentinelInfoID(v+v). // }). // Exec(ctx) func (sabfc *SentinelAppBinaryFileCreate) OnConflict(opts ...sql.ConflictOption) *SentinelAppBinaryFileUpsertOne { @@ -308,15 +313,51 @@ type ( } ) -// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (u *SentinelAppBinaryFileUpsert) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsert { - u.Set(sentinelappbinaryfile.FieldSentinelAppBinaryID, v) +// 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 } -// UpdateSentinelAppBinaryID sets the "sentinel_app_binary_id" field to the value that was provided on create. -func (u *SentinelAppBinaryFileUpsert) UpdateSentinelAppBinaryID() *SentinelAppBinaryFileUpsert { - u.SetExcluded(sentinelappbinaryfile.FieldSentinelAppBinaryID) +// 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 } @@ -474,17 +515,59 @@ func (u *SentinelAppBinaryFileUpsertOne) Update(set func(*SentinelAppBinaryFileU return u } -// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (u *SentinelAppBinaryFileUpsertOne) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsertOne { +// 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.SetSentinelAppBinaryID(v) + s.AddSentinelInfoID(v) }) } -// UpdateSentinelAppBinaryID sets the "sentinel_app_binary_id" field to the value that was provided on create. -func (u *SentinelAppBinaryFileUpsertOne) UpdateSentinelAppBinaryID() *SentinelAppBinaryFileUpsertOne { +// 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.UpdateSentinelAppBinaryID() + 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() }) } @@ -756,7 +839,7 @@ func (sabfcb *SentinelAppBinaryFileCreateBulk) ExecX(ctx context.Context) { // // Override some of the fields with custom // // update values. // Update(func(u *ent.SentinelAppBinaryFileUpsert) { -// SetSentinelAppBinaryID(v+v). +// SetSentinelInfoID(v+v). // }). // Exec(ctx) func (sabfcb *SentinelAppBinaryFileCreateBulk) OnConflict(opts ...sql.ConflictOption) *SentinelAppBinaryFileUpsertBulk { @@ -825,17 +908,59 @@ func (u *SentinelAppBinaryFileUpsertBulk) Update(set func(*SentinelAppBinaryFile return u } -// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (u *SentinelAppBinaryFileUpsertBulk) SetSentinelAppBinaryID(v int) *SentinelAppBinaryFileUpsertBulk { +// 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.SetSentinelAppBinaryID(v) + s.SetSentinelAppBinaryGeneratedID(v) }) } -// UpdateSentinelAppBinaryID sets the "sentinel_app_binary_id" field to the value that was provided on create. -func (u *SentinelAppBinaryFileUpsertBulk) UpdateSentinelAppBinaryID() *SentinelAppBinaryFileUpsertBulk { +// 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.UpdateSentinelAppBinaryID() + s.UpdateSentinelAppBinaryGeneratedID() }) } diff --git a/internal/data/internal/ent/sentinelappbinaryfile_query.go b/internal/data/internal/ent/sentinelappbinaryfile_query.go index 5dec5c78..ee1eec96 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile_query.go +++ b/internal/data/internal/ent/sentinelappbinaryfile_query.go @@ -12,18 +12,16 @@ import ( "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/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 - withSentinelAppBinary *SentinelAppBinaryQuery + 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) @@ -60,28 +58,6 @@ func (sabfq *SentinelAppBinaryFileQuery) Order(o ...sentinelappbinaryfile.OrderO return sabfq } -// QuerySentinelAppBinary chains the current query on the "sentinel_app_binary" edge. -func (sabfq *SentinelAppBinaryFileQuery) QuerySentinelAppBinary() *SentinelAppBinaryQuery { - query := (&SentinelAppBinaryClient{config: sabfq.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := sabfq.prepareQuery(ctx); err != nil { - return nil, err - } - selector := sabfq.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(sentinelappbinaryfile.Table, sentinelappbinaryfile.FieldID, selector), - sqlgraph.To(sentinelappbinary.Table, sentinelappbinary.FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, sentinelappbinaryfile.SentinelAppBinaryTable, sentinelappbinaryfile.SentinelAppBinaryColumn), - ) - fromU = sqlgraph.SetNeighbors(sabfq.driver.Dialect(), step) - return fromU, nil - } - return query -} - // 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) { @@ -269,41 +245,29 @@ func (sabfq *SentinelAppBinaryFileQuery) Clone() *SentinelAppBinaryFileQuery { 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...), - withSentinelAppBinary: sabfq.withSentinelAppBinary.Clone(), + 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, } } -// WithSentinelAppBinary tells the query-builder to eager-load the nodes that are connected to -// the "sentinel_app_binary" edge. The optional arguments are used to configure the query builder of the edge. -func (sabfq *SentinelAppBinaryFileQuery) WithSentinelAppBinary(opts ...func(*SentinelAppBinaryQuery)) *SentinelAppBinaryFileQuery { - query := (&SentinelAppBinaryClient{config: sabfq.config}).Query() - for _, opt := range opts { - opt(query) - } - sabfq.withSentinelAppBinary = query - return sabfq -} - // 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 { -// SentinelAppBinaryID int `json:"sentinel_app_binary_id,omitempty"` +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` // Count int `json:"count,omitempty"` // } // // client.SentinelAppBinaryFile.Query(). -// GroupBy(sentinelappbinaryfile.FieldSentinelAppBinaryID). +// GroupBy(sentinelappbinaryfile.FieldSentinelInfoID). // Aggregate(ent.Count()). // Scan(ctx, &v) func (sabfq *SentinelAppBinaryFileQuery) GroupBy(field string, fields ...string) *SentinelAppBinaryFileGroupBy { @@ -321,11 +285,11 @@ func (sabfq *SentinelAppBinaryFileQuery) GroupBy(field string, fields ...string) // Example: // // var v []struct { -// SentinelAppBinaryID int `json:"sentinel_app_binary_id,omitempty"` +// SentinelInfoID model.InternalID `json:"sentinel_info_id,omitempty"` // } // // client.SentinelAppBinaryFile.Query(). -// Select(sentinelappbinaryfile.FieldSentinelAppBinaryID). +// Select(sentinelappbinaryfile.FieldSentinelInfoID). // Scan(ctx, &v) func (sabfq *SentinelAppBinaryFileQuery) Select(fields ...string) *SentinelAppBinaryFileSelect { sabfq.ctx.Fields = append(sabfq.ctx.Fields, fields...) @@ -368,11 +332,8 @@ func (sabfq *SentinelAppBinaryFileQuery) prepareQuery(ctx context.Context) error func (sabfq *SentinelAppBinaryFileQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SentinelAppBinaryFile, error) { var ( - nodes = []*SentinelAppBinaryFile{} - _spec = sabfq.querySpec() - loadedTypes = [1]bool{ - sabfq.withSentinelAppBinary != nil, - } + nodes = []*SentinelAppBinaryFile{} + _spec = sabfq.querySpec() ) _spec.ScanValues = func(columns []string) ([]any, error) { return (*SentinelAppBinaryFile).scanValues(nil, columns) @@ -380,7 +341,6 @@ func (sabfq *SentinelAppBinaryFileQuery) sqlAll(ctx context.Context, hooks ...qu _spec.Assign = func(columns []string, values []any) error { node := &SentinelAppBinaryFile{config: sabfq.config} nodes = append(nodes, node) - node.Edges.loadedTypes = loadedTypes return node.assignValues(columns, values) } for i := range hooks { @@ -392,45 +352,9 @@ func (sabfq *SentinelAppBinaryFileQuery) sqlAll(ctx context.Context, hooks ...qu if len(nodes) == 0 { return nodes, nil } - if query := sabfq.withSentinelAppBinary; query != nil { - if err := sabfq.loadSentinelAppBinary(ctx, query, nodes, nil, - func(n *SentinelAppBinaryFile, e *SentinelAppBinary) { n.Edges.SentinelAppBinary = e }); err != nil { - return nil, err - } - } return nodes, nil } -func (sabfq *SentinelAppBinaryFileQuery) loadSentinelAppBinary(ctx context.Context, query *SentinelAppBinaryQuery, nodes []*SentinelAppBinaryFile, init func(*SentinelAppBinaryFile), assign func(*SentinelAppBinaryFile, *SentinelAppBinary)) error { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*SentinelAppBinaryFile) - for i := range nodes { - fk := nodes[i].SentinelAppBinaryID - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - if len(ids) == 0 { - return nil - } - query.Where(sentinelappbinary.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_app_binary_id" returned %v`, n.ID) - } - for i := range nodes { - assign(nodes[i], n) - } - } - return nil -} - func (sabfq *SentinelAppBinaryFileQuery) sqlCount(ctx context.Context) (int, error) { _spec := sabfq.querySpec() _spec.Node.Columns = sabfq.ctx.Fields @@ -456,9 +380,6 @@ func (sabfq *SentinelAppBinaryFileQuery) querySpec() *sqlgraph.QuerySpec { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } - if sabfq.withSentinelAppBinary != nil { - _spec.Node.AddColumnOnce(sentinelappbinaryfile.FieldSentinelAppBinaryID) - } } if ps := sabfq.predicates; len(ps) > 0 { _spec.Predicate = func(selector *sql.Selector) { diff --git a/internal/data/internal/ent/sentinelappbinaryfile_update.go b/internal/data/internal/ent/sentinelappbinaryfile_update.go index 1adb3377..889f00a7 100644 --- a/internal/data/internal/ent/sentinelappbinaryfile_update.go +++ b/internal/data/internal/ent/sentinelappbinaryfile_update.go @@ -12,8 +12,8 @@ import ( "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/data/internal/ent/sentinelappbinaryfile" + "github.com/tuihub/librarian/internal/model" ) // SentinelAppBinaryFileUpdate is the builder for updating SentinelAppBinaryFile entities. @@ -29,16 +29,58 @@ func (sabfu *SentinelAppBinaryFileUpdate) Where(ps ...predicate.SentinelAppBinar return sabfu } -// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileUpdate { - sabfu.mutation.SetSentinelAppBinaryID(i) +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelInfoID(mi model.InternalID) *SentinelAppBinaryFileUpdate { + sabfu.mutation.ResetSentinelInfoID() + sabfu.mutation.SetSentinelInfoID(mi) return sabfu } -// SetNillableSentinelAppBinaryID sets the "sentinel_app_binary_id" field if the given value is not nil. -func (sabfu *SentinelAppBinaryFileUpdate) SetNillableSentinelAppBinaryID(i *int) *SentinelAppBinaryFileUpdate { +// 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.SetSentinelAppBinaryID(*i) + 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 } @@ -159,22 +201,11 @@ func (sabfu *SentinelAppBinaryFileUpdate) AddAppBinaryReportSequence(i int64) *S return sabfu } -// SetSentinelAppBinary sets the "sentinel_app_binary" edge to the SentinelAppBinary entity. -func (sabfu *SentinelAppBinaryFileUpdate) SetSentinelAppBinary(s *SentinelAppBinary) *SentinelAppBinaryFileUpdate { - return sabfu.SetSentinelAppBinaryID(s.ID) -} - // Mutation returns the SentinelAppBinaryFileMutation object of the builder. func (sabfu *SentinelAppBinaryFileUpdate) Mutation() *SentinelAppBinaryFileMutation { return sabfu.mutation } -// ClearSentinelAppBinary clears the "sentinel_app_binary" edge to the SentinelAppBinary entity. -func (sabfu *SentinelAppBinaryFileUpdate) ClearSentinelAppBinary() *SentinelAppBinaryFileUpdate { - sabfu.mutation.ClearSentinelAppBinary() - return sabfu -} - // 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() @@ -211,18 +242,7 @@ func (sabfu *SentinelAppBinaryFileUpdate) defaults() { } } -// check runs all checks and user-defined validators on the builder. -func (sabfu *SentinelAppBinaryFileUpdate) check() error { - if sabfu.mutation.SentinelAppBinaryCleared() && len(sabfu.mutation.SentinelAppBinaryIDs()) > 0 { - return errors.New(`ent: clearing a required unique edge "SentinelAppBinaryFile.sentinel_app_binary"`) - } - return nil -} - func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, err error) { - if err := sabfu.check(); err != nil { - return n, err - } _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) { @@ -231,6 +251,21 @@ func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, e } } } + 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) } @@ -264,35 +299,6 @@ func (sabfu *SentinelAppBinaryFileUpdate) sqlSave(ctx context.Context) (n int, e if value, ok := sabfu.mutation.AddedAppBinaryReportSequence(); ok { _spec.AddField(sentinelappbinaryfile.FieldAppBinaryReportSequence, field.TypeInt64, value) } - if sabfu.mutation.SentinelAppBinaryCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: sentinelappbinaryfile.SentinelAppBinaryTable, - Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := sabfu.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: sentinelappbinaryfile.SentinelAppBinaryTable, - Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.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, sabfu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{sentinelappbinaryfile.Label} @@ -313,16 +319,58 @@ type SentinelAppBinaryFileUpdateOne struct { mutation *SentinelAppBinaryFileMutation } -// SetSentinelAppBinaryID sets the "sentinel_app_binary_id" field. -func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelAppBinaryID(i int) *SentinelAppBinaryFileUpdateOne { - sabfuo.mutation.SetSentinelAppBinaryID(i) +// SetSentinelInfoID sets the "sentinel_info_id" field. +func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelInfoID(mi model.InternalID) *SentinelAppBinaryFileUpdateOne { + sabfuo.mutation.ResetSentinelInfoID() + sabfuo.mutation.SetSentinelInfoID(mi) return sabfuo } -// SetNillableSentinelAppBinaryID sets the "sentinel_app_binary_id" field if the given value is not nil. -func (sabfuo *SentinelAppBinaryFileUpdateOne) SetNillableSentinelAppBinaryID(i *int) *SentinelAppBinaryFileUpdateOne { +// 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.SetSentinelAppBinaryID(*i) + 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 } @@ -443,22 +491,11 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) AddAppBinaryReportSequence(i int64 return sabfuo } -// SetSentinelAppBinary sets the "sentinel_app_binary" edge to the SentinelAppBinary entity. -func (sabfuo *SentinelAppBinaryFileUpdateOne) SetSentinelAppBinary(s *SentinelAppBinary) *SentinelAppBinaryFileUpdateOne { - return sabfuo.SetSentinelAppBinaryID(s.ID) -} - // Mutation returns the SentinelAppBinaryFileMutation object of the builder. func (sabfuo *SentinelAppBinaryFileUpdateOne) Mutation() *SentinelAppBinaryFileMutation { return sabfuo.mutation } -// ClearSentinelAppBinary clears the "sentinel_app_binary" edge to the SentinelAppBinary entity. -func (sabfuo *SentinelAppBinaryFileUpdateOne) ClearSentinelAppBinary() *SentinelAppBinaryFileUpdateOne { - sabfuo.mutation.ClearSentinelAppBinary() - return sabfuo -} - // Where appends a list predicates to the SentinelAppBinaryFileUpdate builder. func (sabfuo *SentinelAppBinaryFileUpdateOne) Where(ps ...predicate.SentinelAppBinaryFile) *SentinelAppBinaryFileUpdateOne { sabfuo.mutation.Where(ps...) @@ -508,18 +545,7 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) defaults() { } } -// check runs all checks and user-defined validators on the builder. -func (sabfuo *SentinelAppBinaryFileUpdateOne) check() error { - if sabfuo.mutation.SentinelAppBinaryCleared() && len(sabfuo.mutation.SentinelAppBinaryIDs()) > 0 { - return errors.New(`ent: clearing a required unique edge "SentinelAppBinaryFile.sentinel_app_binary"`) - } - return nil -} - func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_node *SentinelAppBinaryFile, err error) { - if err := sabfuo.check(); err != nil { - return _node, err - } _spec := sqlgraph.NewUpdateSpec(sentinelappbinaryfile.Table, sentinelappbinaryfile.Columns, sqlgraph.NewFieldSpec(sentinelappbinaryfile.FieldID, field.TypeInt)) id, ok := sabfuo.mutation.ID() if !ok { @@ -545,6 +571,21 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_nod } } } + 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) } @@ -578,35 +619,6 @@ func (sabfuo *SentinelAppBinaryFileUpdateOne) sqlSave(ctx context.Context) (_nod if value, ok := sabfuo.mutation.AddedAppBinaryReportSequence(); ok { _spec.AddField(sentinelappbinaryfile.FieldAppBinaryReportSequence, field.TypeInt64, value) } - if sabfuo.mutation.SentinelAppBinaryCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: sentinelappbinaryfile.SentinelAppBinaryTable, - Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := sabfuo.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: sentinelappbinaryfile.SentinelAppBinaryTable, - Columns: []string{sentinelappbinaryfile.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } _node = &SentinelAppBinaryFile{config: sabfuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues diff --git a/internal/data/internal/ent/sentinellibrary.go b/internal/data/internal/ent/sentinellibrary.go index fd52d3e6..dcc47bed 100644 --- a/internal/data/internal/ent/sentinellibrary.go +++ b/internal/data/internal/ent/sentinellibrary.go @@ -41,11 +41,9 @@ type SentinelLibrary struct { type SentinelLibraryEdges struct { // SentinelInfo holds the value of the sentinel_info edge. SentinelInfo *SentinelInfo `json:"sentinel_info,omitempty"` - // SentinelAppBinary holds the value of the sentinel_app_binary edge. - SentinelAppBinary []*SentinelAppBinary `json:"sentinel_app_binary,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. - loadedTypes [2]bool + loadedTypes [1]bool } // SentinelInfoOrErr returns the SentinelInfo value or an error if the edge @@ -59,15 +57,6 @@ func (e SentinelLibraryEdges) SentinelInfoOrErr() (*SentinelInfo, error) { return nil, &NotLoadedError{edge: "sentinel_info"} } -// SentinelAppBinaryOrErr returns the SentinelAppBinary value or an error if the edge -// was not loaded in eager-loading. -func (e SentinelLibraryEdges) SentinelAppBinaryOrErr() ([]*SentinelAppBinary, error) { - if e.loadedTypes[1] { - return e.SentinelAppBinary, nil - } - return nil, &NotLoadedError{edge: "sentinel_app_binary"} -} - // scanValues returns the types for scanning values from sql.Rows. func (*SentinelLibrary) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) @@ -154,11 +143,6 @@ func (sl *SentinelLibrary) QuerySentinelInfo() *SentinelInfoQuery { return NewSentinelLibraryClient(sl.config).QuerySentinelInfo(sl) } -// QuerySentinelAppBinary queries the "sentinel_app_binary" edge of the SentinelLibrary entity. -func (sl *SentinelLibrary) QuerySentinelAppBinary() *SentinelAppBinaryQuery { - return NewSentinelLibraryClient(sl.config).QuerySentinelAppBinary(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. diff --git a/internal/data/internal/ent/sentinellibrary/sentinellibrary.go b/internal/data/internal/ent/sentinellibrary/sentinellibrary.go index c17d7ede..336036d7 100644 --- a/internal/data/internal/ent/sentinellibrary/sentinellibrary.go +++ b/internal/data/internal/ent/sentinellibrary/sentinellibrary.go @@ -28,8 +28,6 @@ const ( FieldLibraryReportSequence = "library_report_sequence" // EdgeSentinelInfo holds the string denoting the sentinel_info edge name in mutations. EdgeSentinelInfo = "sentinel_info" - // EdgeSentinelAppBinary holds the string denoting the sentinel_app_binary edge name in mutations. - EdgeSentinelAppBinary = "sentinel_app_binary" // 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. @@ -39,13 +37,6 @@ const ( SentinelInfoInverseTable = "sentinel_infos" // SentinelInfoColumn is the table column denoting the sentinel_info relation/edge. SentinelInfoColumn = "sentinel_info_id" - // SentinelAppBinaryTable is the table that holds the sentinel_app_binary relation/edge. - SentinelAppBinaryTable = "sentinel_app_binaries" - // SentinelAppBinaryInverseTable is the table name for the SentinelAppBinary entity. - // It exists in this package in order to avoid circular dependency with the "sentinelappbinary" package. - SentinelAppBinaryInverseTable = "sentinel_app_binaries" - // SentinelAppBinaryColumn is the table column denoting the sentinel_app_binary relation/edge. - SentinelAppBinaryColumn = "sentinel_library_id" ) // Columns holds all SQL columns for sentinellibrary fields. @@ -122,20 +113,6 @@ func BySentinelInfoField(field string, opts ...sql.OrderTermOption) OrderOption sqlgraph.OrderByNeighborTerms(s, newSentinelInfoStep(), sql.OrderByField(field, opts...)) } } - -// BySentinelAppBinaryCount orders the results by sentinel_app_binary count. -func BySentinelAppBinaryCount(opts ...sql.OrderTermOption) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborsCount(s, newSentinelAppBinaryStep(), opts...) - } -} - -// BySentinelAppBinary orders the results by sentinel_app_binary terms. -func BySentinelAppBinary(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newSentinelAppBinaryStep(), append([]sql.OrderTerm{term}, terms...)...) - } -} func newSentinelInfoStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), @@ -143,10 +120,3 @@ func newSentinelInfoStep() *sqlgraph.Step { sqlgraph.Edge(sqlgraph.M2O, false, SentinelInfoTable, SentinelInfoColumn), ) } -func newSentinelAppBinaryStep() *sqlgraph.Step { - return sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(SentinelAppBinaryInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, SentinelAppBinaryTable, SentinelAppBinaryColumn), - ) -} diff --git a/internal/data/internal/ent/sentinellibrary/where.go b/internal/data/internal/ent/sentinellibrary/where.go index 66a2d00f..637c8728 100644 --- a/internal/data/internal/ent/sentinellibrary/where.go +++ b/internal/data/internal/ent/sentinellibrary/where.go @@ -365,29 +365,6 @@ func HasSentinelInfoWith(preds ...predicate.SentinelInfo) predicate.SentinelLibr }) } -// HasSentinelAppBinary applies the HasEdge predicate on the "sentinel_app_binary" edge. -func HasSentinelAppBinary() predicate.SentinelLibrary { - return predicate.SentinelLibrary(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, SentinelAppBinaryTable, SentinelAppBinaryColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasSentinelAppBinaryWith applies the HasEdge predicate on the "sentinel_app_binary" edge with a given conditions (other predicates). -func HasSentinelAppBinaryWith(preds ...predicate.SentinelAppBinary) predicate.SentinelLibrary { - return predicate.SentinelLibrary(func(s *sql.Selector) { - step := newSentinelAppBinaryStep() - 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...)) diff --git a/internal/data/internal/ent/sentinellibrary_create.go b/internal/data/internal/ent/sentinellibrary_create.go index 699d2120..e3cf2537 100644 --- a/internal/data/internal/ent/sentinellibrary_create.go +++ b/internal/data/internal/ent/sentinellibrary_create.go @@ -11,7 +11,6 @@ import ( "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/data/internal/ent/sentinelinfo" "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" "github.com/tuihub/librarian/internal/model" @@ -82,21 +81,6 @@ func (slc *SentinelLibraryCreate) SetSentinelInfo(s *SentinelInfo) *SentinelLibr return slc.SetSentinelInfoID(s.ID) } -// AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (slc *SentinelLibraryCreate) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryCreate { - slc.mutation.AddSentinelAppBinaryIDs(ids...) - return slc -} - -// AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. -func (slc *SentinelLibraryCreate) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryCreate { - ids := make([]int, len(s)) - for i := range s { - ids[i] = s[i].ID - } - return slc.AddSentinelAppBinaryIDs(ids...) -} - // Mutation returns the SentinelLibraryMutation object of the builder. func (slc *SentinelLibraryCreate) Mutation() *SentinelLibraryMutation { return slc.mutation @@ -229,22 +213,6 @@ func (slc *SentinelLibraryCreate) createSpec() (*SentinelLibrary, *sqlgraph.Crea _node.SentinelInfoID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } - if nodes := slc.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinellibrary.SentinelAppBinaryTable, - Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } return _node, _spec } diff --git a/internal/data/internal/ent/sentinellibrary_query.go b/internal/data/internal/ent/sentinellibrary_query.go index 0eb22a2e..a93ad0a5 100644 --- a/internal/data/internal/ent/sentinellibrary_query.go +++ b/internal/data/internal/ent/sentinellibrary_query.go @@ -4,7 +4,6 @@ package ent import ( "context" - "database/sql/driver" "fmt" "math" @@ -13,7 +12,6 @@ import ( "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/data/internal/ent/sentinelinfo" "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" "github.com/tuihub/librarian/internal/model" @@ -22,12 +20,11 @@ import ( // SentinelLibraryQuery is the builder for querying SentinelLibrary entities. type SentinelLibraryQuery struct { config - ctx *QueryContext - order []sentinellibrary.OrderOption - inters []Interceptor - predicates []predicate.SentinelLibrary - withSentinelInfo *SentinelInfoQuery - withSentinelAppBinary *SentinelAppBinaryQuery + 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) @@ -86,28 +83,6 @@ func (slq *SentinelLibraryQuery) QuerySentinelInfo() *SentinelInfoQuery { return query } -// QuerySentinelAppBinary chains the current query on the "sentinel_app_binary" edge. -func (slq *SentinelLibraryQuery) QuerySentinelAppBinary() *SentinelAppBinaryQuery { - query := (&SentinelAppBinaryClient{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(sentinelappbinary.Table, sentinelappbinary.FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, sentinellibrary.SentinelAppBinaryTable, sentinellibrary.SentinelAppBinaryColumn), - ) - 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) { @@ -295,13 +270,12 @@ func (slq *SentinelLibraryQuery) Clone() *SentinelLibraryQuery { 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(), - withSentinelAppBinary: slq.withSentinelAppBinary.Clone(), + 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, @@ -319,17 +293,6 @@ func (slq *SentinelLibraryQuery) WithSentinelInfo(opts ...func(*SentinelInfoQuer return slq } -// WithSentinelAppBinary tells the query-builder to eager-load the nodes that are connected to -// the "sentinel_app_binary" edge. The optional arguments are used to configure the query builder of the edge. -func (slq *SentinelLibraryQuery) WithSentinelAppBinary(opts ...func(*SentinelAppBinaryQuery)) *SentinelLibraryQuery { - query := (&SentinelAppBinaryClient{config: slq.config}).Query() - for _, opt := range opts { - opt(query) - } - slq.withSentinelAppBinary = 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. // @@ -408,9 +371,8 @@ func (slq *SentinelLibraryQuery) sqlAll(ctx context.Context, hooks ...queryHook) var ( nodes = []*SentinelLibrary{} _spec = slq.querySpec() - loadedTypes = [2]bool{ + loadedTypes = [1]bool{ slq.withSentinelInfo != nil, - slq.withSentinelAppBinary != nil, } ) _spec.ScanValues = func(columns []string) ([]any, error) { @@ -437,15 +399,6 @@ func (slq *SentinelLibraryQuery) sqlAll(ctx context.Context, hooks ...queryHook) return nil, err } } - if query := slq.withSentinelAppBinary; query != nil { - if err := slq.loadSentinelAppBinary(ctx, query, nodes, - func(n *SentinelLibrary) { n.Edges.SentinelAppBinary = []*SentinelAppBinary{} }, - func(n *SentinelLibrary, e *SentinelAppBinary) { - n.Edges.SentinelAppBinary = append(n.Edges.SentinelAppBinary, e) - }); err != nil { - return nil, err - } - } return nodes, nil } @@ -478,36 +431,6 @@ func (slq *SentinelLibraryQuery) loadSentinelInfo(ctx context.Context, query *Se } return nil } -func (slq *SentinelLibraryQuery) loadSentinelAppBinary(ctx context.Context, query *SentinelAppBinaryQuery, nodes []*SentinelLibrary, init func(*SentinelLibrary), assign func(*SentinelLibrary, *SentinelAppBinary)) error { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*SentinelLibrary) - 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(sentinelappbinary.FieldSentinelLibraryID) - } - query.Where(predicate.SentinelAppBinary(func(s *sql.Selector) { - s.Where(sql.InValues(s.C(sentinellibrary.SentinelAppBinaryColumn), fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - fk := n.SentinelLibraryID - node, ok := nodeids[fk] - if !ok { - return fmt.Errorf(`unexpected referenced foreign-key "sentinel_library_id" returned %v for node %v`, fk, n.ID) - } - assign(node, n) - } - return nil -} func (slq *SentinelLibraryQuery) sqlCount(ctx context.Context) (int, error) { _spec := slq.querySpec() diff --git a/internal/data/internal/ent/sentinellibrary_update.go b/internal/data/internal/ent/sentinellibrary_update.go index ea6e18d1..fecd6d81 100644 --- a/internal/data/internal/ent/sentinellibrary_update.go +++ b/internal/data/internal/ent/sentinellibrary_update.go @@ -12,7 +12,6 @@ import ( "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/data/internal/ent/sentinelinfo" "github.com/tuihub/librarian/internal/data/internal/ent/sentinellibrary" "github.com/tuihub/librarian/internal/model" @@ -126,21 +125,6 @@ func (slu *SentinelLibraryUpdate) SetSentinelInfo(s *SentinelInfo) *SentinelLibr return slu.SetSentinelInfoID(s.ID) } -// AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (slu *SentinelLibraryUpdate) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdate { - slu.mutation.AddSentinelAppBinaryIDs(ids...) - return slu -} - -// AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. -func (slu *SentinelLibraryUpdate) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdate { - ids := make([]int, len(s)) - for i := range s { - ids[i] = s[i].ID - } - return slu.AddSentinelAppBinaryIDs(ids...) -} - // Mutation returns the SentinelLibraryMutation object of the builder. func (slu *SentinelLibraryUpdate) Mutation() *SentinelLibraryMutation { return slu.mutation @@ -152,27 +136,6 @@ func (slu *SentinelLibraryUpdate) ClearSentinelInfo() *SentinelLibraryUpdate { return slu } -// ClearSentinelAppBinary clears all "sentinel_app_binary" edges to the SentinelAppBinary entity. -func (slu *SentinelLibraryUpdate) ClearSentinelAppBinary() *SentinelLibraryUpdate { - slu.mutation.ClearSentinelAppBinary() - return slu -} - -// RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to SentinelAppBinary entities by IDs. -func (slu *SentinelLibraryUpdate) RemoveSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdate { - slu.mutation.RemoveSentinelAppBinaryIDs(ids...) - return slu -} - -// RemoveSentinelAppBinary removes "sentinel_app_binary" edges to SentinelAppBinary entities. -func (slu *SentinelLibraryUpdate) RemoveSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdate { - ids := make([]int, len(s)) - for i := range s { - ids[i] = s[i].ID - } - return slu.RemoveSentinelAppBinaryIDs(ids...) -} - // 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() @@ -279,51 +242,6 @@ func (slu *SentinelLibraryUpdate) sqlSave(ctx context.Context) (n int, err error } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if slu.mutation.SentinelAppBinaryCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinellibrary.SentinelAppBinaryTable, - Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := slu.mutation.RemovedSentinelAppBinaryIDs(); len(nodes) > 0 && !slu.mutation.SentinelAppBinaryCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinellibrary.SentinelAppBinaryTable, - Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.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 := slu.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinellibrary.SentinelAppBinaryTable, - Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.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, slu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{sentinellibrary.Label} @@ -439,21 +357,6 @@ func (sluo *SentinelLibraryUpdateOne) SetSentinelInfo(s *SentinelInfo) *Sentinel return sluo.SetSentinelInfoID(s.ID) } -// AddSentinelAppBinaryIDs adds the "sentinel_app_binary" edge to the SentinelAppBinary entity by IDs. -func (sluo *SentinelLibraryUpdateOne) AddSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdateOne { - sluo.mutation.AddSentinelAppBinaryIDs(ids...) - return sluo -} - -// AddSentinelAppBinary adds the "sentinel_app_binary" edges to the SentinelAppBinary entity. -func (sluo *SentinelLibraryUpdateOne) AddSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdateOne { - ids := make([]int, len(s)) - for i := range s { - ids[i] = s[i].ID - } - return sluo.AddSentinelAppBinaryIDs(ids...) -} - // Mutation returns the SentinelLibraryMutation object of the builder. func (sluo *SentinelLibraryUpdateOne) Mutation() *SentinelLibraryMutation { return sluo.mutation @@ -465,27 +368,6 @@ func (sluo *SentinelLibraryUpdateOne) ClearSentinelInfo() *SentinelLibraryUpdate return sluo } -// ClearSentinelAppBinary clears all "sentinel_app_binary" edges to the SentinelAppBinary entity. -func (sluo *SentinelLibraryUpdateOne) ClearSentinelAppBinary() *SentinelLibraryUpdateOne { - sluo.mutation.ClearSentinelAppBinary() - return sluo -} - -// RemoveSentinelAppBinaryIDs removes the "sentinel_app_binary" edge to SentinelAppBinary entities by IDs. -func (sluo *SentinelLibraryUpdateOne) RemoveSentinelAppBinaryIDs(ids ...int) *SentinelLibraryUpdateOne { - sluo.mutation.RemoveSentinelAppBinaryIDs(ids...) - return sluo -} - -// RemoveSentinelAppBinary removes "sentinel_app_binary" edges to SentinelAppBinary entities. -func (sluo *SentinelLibraryUpdateOne) RemoveSentinelAppBinary(s ...*SentinelAppBinary) *SentinelLibraryUpdateOne { - ids := make([]int, len(s)) - for i := range s { - ids[i] = s[i].ID - } - return sluo.RemoveSentinelAppBinaryIDs(ids...) -} - // Where appends a list predicates to the SentinelLibraryUpdate builder. func (sluo *SentinelLibraryUpdateOne) Where(ps ...predicate.SentinelLibrary) *SentinelLibraryUpdateOne { sluo.mutation.Where(ps...) @@ -622,51 +504,6 @@ func (sluo *SentinelLibraryUpdateOne) sqlSave(ctx context.Context) (_node *Senti } _spec.Edges.Add = append(_spec.Edges.Add, edge) } - if sluo.mutation.SentinelAppBinaryCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinellibrary.SentinelAppBinaryTable, - Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := sluo.mutation.RemovedSentinelAppBinaryIDs(); len(nodes) > 0 && !sluo.mutation.SentinelAppBinaryCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinellibrary.SentinelAppBinaryTable, - Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.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 := sluo.mutation.SentinelAppBinaryIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: sentinellibrary.SentinelAppBinaryTable, - Columns: []string{sentinellibrary.SentinelAppBinaryColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(sentinelappbinary.FieldID, field.TypeInt), - }, - } - 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 From 8cece4b2f04f77e77b0f138bd86aa8691589d0ef Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Fri, 11 Apr 2025 17:20:27 +0800 Subject: [PATCH 14/16] fix(sentinel): set appBinaryReportSeq in UpsertSentinelInfo --- internal/data/gebura.go | 6 +++++- internal/data/internal/ent/schema/sentinel_app_binary.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/data/gebura.go b/internal/data/gebura.go index 11e0d742..2cc6dd38 100644 --- a/internal/data/gebura.go +++ b/internal/data/gebura.go @@ -627,13 +627,16 @@ func (g *GeburaRepo) UpsertSentinelInfo( Where(sentinelinfo.IDEQ(info.ID)). Only(ctx) var libReportSeq int64 + var appBinaryReportSeq int64 if err != nil { if !ent.IsNotFound(err) { return err } libReportSeq = 0 + appBinaryReportSeq = 0 } else { libReportSeq = sInfo.LibraryReportSequence + 1 + appBinaryReportSeq = sInfo.AppBinaryReportSequence } // upsert sentinel info q := tx.SentinelInfo.Create(). @@ -642,7 +645,8 @@ func (g *GeburaRepo) UpsertSentinelInfo( SetAlternativeUrls(info.AlternativeUrls). SetGetTokenPath(info.GetTokenPath). SetDownloadFileBasePath(info.DownloadFileBasePath). - SetLibraryReportSequence(libReportSeq) + SetLibraryReportSequence(libReportSeq). + SetAppBinaryReportSequence(appBinaryReportSeq) err = q.OnConflict(sql.ConflictColumns(sentinelinfo.FieldID)). UpdateNewValues(). Exec(ctx) diff --git a/internal/data/internal/ent/schema/sentinel_app_binary.go b/internal/data/internal/ent/schema/sentinel_app_binary.go index 5c0d8aca..9b76e87a 100644 --- a/internal/data/internal/ent/schema/sentinel_app_binary.go +++ b/internal/data/internal/ent/schema/sentinel_app_binary.go @@ -51,7 +51,7 @@ func (SentinelAppBinary) Edges() []ent.Edge { // Required(). // Unique(). // Field("sentinel_library_id"), - //edge.From("sentinel_app_binary_file", SentinelAppBinaryFile.Type). + // edge.From("sentinel_app_binary_file", SentinelAppBinaryFile.Type). // Ref("sentinel_app_binary"), } } From d4acc953f7507ef8f68ef78ff27865eaafc1db43 Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Sat, 12 Apr 2025 13:18:06 +0800 Subject: [PATCH 15/16] fix(sentinel): change to UpdateSentinelInfo --- internal/biz/bizgebura/sentinel.go | 2 +- internal/data/gebura.go | 39 +++++++----------------------- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/internal/biz/bizgebura/sentinel.go b/internal/biz/bizgebura/sentinel.go index 2ee2e9dc..4702b57a 100644 --- a/internal/biz/bizgebura/sentinel.go +++ b/internal/biz/bizgebura/sentinel.go @@ -18,7 +18,7 @@ func (g *Gebura) UpsertSentinelInfo( return bizutils.NoPermissionError() } info.ID = claims.UserID - err := g.repo.UpsertSentinelInfo(ctx, info) + err := g.repo.UpdateSentinelInfo(ctx, info) if err != nil { return pb.ErrorErrorReasonUnspecified("%s", err.Error()) } diff --git a/internal/data/gebura.go b/internal/data/gebura.go index 2cc6dd38..49c41994 100644 --- a/internal/data/gebura.go +++ b/internal/data/gebura.go @@ -618,49 +618,28 @@ func (g *GeburaRepo) DeleteAppCategory( }) } -func (g *GeburaRepo) UpsertSentinelInfo( +func (g *GeburaRepo) UpdateSentinelInfo( ctx context.Context, info *modelgebura.SentinelInfo, ) error { return g.data.WithTx(ctx, func(tx *ent.Tx) error { - sInfo, err := tx.SentinelInfo.Query(). - Where(sentinelinfo.IDEQ(info.ID)). - Only(ctx) - var libReportSeq int64 - var appBinaryReportSeq int64 - if err != nil { - if !ent.IsNotFound(err) { - return err - } - libReportSeq = 0 - appBinaryReportSeq = 0 - } else { - libReportSeq = sInfo.LibraryReportSequence + 1 - appBinaryReportSeq = sInfo.AppBinaryReportSequence - } - // upsert sentinel info - q := tx.SentinelInfo.Create(). - SetID(info.ID). + // update sentinel info + err := tx.SentinelInfo.UpdateOneID(info.ID). SetURL(info.Url). SetAlternativeUrls(info.AlternativeUrls). SetGetTokenPath(info.GetTokenPath). SetDownloadFileBasePath(info.DownloadFileBasePath). - SetLibraryReportSequence(libReportSeq). - SetAppBinaryReportSequence(appBinaryReportSeq) - err = q.OnConflict(sql.ConflictColumns(sentinelinfo.FieldID)). - UpdateNewValues(). + AddLibraryReportSequence(1). Exec(ctx) if err != nil { return err } // upsert libraries - if libReportSeq == 0 { - sInfo, err = tx.SentinelInfo.Query(). - Where(sentinelinfo.IDEQ(info.ID)). - Only(ctx) - if err != nil { - return err - } + 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 { From 64faebfdc162384cc18236abaf40084eacf3eda2 Mon Sep 17 00:00:00 2001 From: Tabing010102 Date: Sat, 12 Apr 2025 13:26:56 +0800 Subject: [PATCH 16/16] fix(sentinel): update SentinelInfo by UpdateOneID --- internal/data/gebura.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/data/gebura.go b/internal/data/gebura.go index 49c41994..1a507b28 100644 --- a/internal/data/gebura.go +++ b/internal/data/gebura.go @@ -669,8 +669,7 @@ func (g *GeburaRepo) UpsertAppBinaries( ) error { return g.data.WithTx(ctx, func(tx *ent.Tx) error { // update AppBinaryReportSequence - err := tx.SentinelInfo.Update(). - Where(sentinelinfo.IDEQ(sentinelID)). + err := tx.SentinelInfo.UpdateOneID(sentinelID). AddAppBinaryReportSequence(1). Exec(ctx) if err != nil {