diff --git a/batch-service/database/seed/seeders/init_seed.go b/batch-service/database/seed/seeders/init_seed.go index db67dc61..e96d7ff6 100644 --- a/batch-service/database/seed/seeders/init_seed.go +++ b/batch-service/database/seed/seeders/init_seed.go @@ -1693,5 +1693,16 @@ func getSeedPlatformAndFeeds() []seedPlatformFeed { FaviconURL: "https://frontier-assets.toptal.com/1fafc84237661afb2281.png", IsEng: true, }, + { + PlatformName: "Findy", + FeedName: "Findy", + seedCategoryID: 1, + RssURL: "https://tech.findy.co.jp/rss", + PlatformSiteURL: "https://tech.findy.co.jp/", + FeedSiteURL: "https://tech.findy.co.jp/", + PlatformType: domain.PlatformTypeCompany, + FaviconURL: "https://tech.findy.co.jp/icon/favicon", + IsEng: false, + }, } } diff --git a/batch-service/entity/boil_table_names.go b/batch-service/entity/boil_table_names.go index cd8e0274..fa1af8f9 100644 --- a/batch-service/entity/boil_table_names.go +++ b/batch-service/entity/boil_table_names.go @@ -9,6 +9,8 @@ var TableNames = struct { Categories string FeedArticleRelations string Feeds string + MyFeedLists string + MyFeeds string Platforms string Profiles string }{ @@ -17,6 +19,8 @@ var TableNames = struct { Categories: "categories", FeedArticleRelations: "feed_article_relations", Feeds: "feeds", + MyFeedLists: "my_feed_lists", + MyFeeds: "my_feeds", Platforms: "platforms", Profiles: "profiles", } diff --git a/batch-service/entity/feeds.go b/batch-service/entity/feeds.go index 3d55ddd2..5b3eeadd 100644 --- a/batch-service/entity/feeds.go +++ b/batch-service/entity/feeds.go @@ -118,10 +118,12 @@ var FeedRels = struct { Category string Platform string FeedArticleRelations string + MyFeeds string }{ Category: "Category", Platform: "Platform", FeedArticleRelations: "FeedArticleRelations", + MyFeeds: "MyFeeds", } // feedR is where relationships are stored. @@ -129,6 +131,7 @@ type feedR struct { Category *Category `boil:"Category" json:"Category" toml:"Category" yaml:"Category"` Platform *Platform `boil:"Platform" json:"Platform" toml:"Platform" yaml:"Platform"` FeedArticleRelations FeedArticleRelationSlice `boil:"FeedArticleRelations" json:"FeedArticleRelations" toml:"FeedArticleRelations" yaml:"FeedArticleRelations"` + MyFeeds MyFeedSlice `boil:"MyFeeds" json:"MyFeeds" toml:"MyFeeds" yaml:"MyFeeds"` } // NewStruct creates a new relationship struct @@ -157,6 +160,13 @@ func (r *feedR) GetFeedArticleRelations() FeedArticleRelationSlice { return r.FeedArticleRelations } +func (r *feedR) GetMyFeeds() MyFeedSlice { + if r == nil { + return nil + } + return r.MyFeeds +} + // feedL is where Load methods for each relationship are stored. type feedL struct{} @@ -509,6 +519,20 @@ func (o *Feed) FeedArticleRelations(mods ...qm.QueryMod) feedArticleRelationQuer return FeedArticleRelations(queryMods...) } +// MyFeeds retrieves all the my_feed's MyFeeds with an executor. +func (o *Feed) MyFeeds(mods ...qm.QueryMod) myFeedQuery { + var queryMods []qm.QueryMod + if len(mods) != 0 { + queryMods = append(queryMods, mods...) + } + + queryMods = append(queryMods, + qm.Where("\"my_feeds\".\"feed_id\"=?", o.ID), + ) + + return MyFeeds(queryMods...) +} + // LoadCategory allows an eager lookup of values, cached into the // loaded structs of the objects. This is for an N-1 relationship. func (feedL) LoadCategory(ctx context.Context, e boil.ContextExecutor, singular bool, maybeFeed interface{}, mods queries.Applicator) error { @@ -862,6 +886,119 @@ func (feedL) LoadFeedArticleRelations(ctx context.Context, e boil.ContextExecuto return nil } +// LoadMyFeeds allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for a 1-M or N-M relationship. +func (feedL) LoadMyFeeds(ctx context.Context, e boil.ContextExecutor, singular bool, maybeFeed interface{}, mods queries.Applicator) error { + var slice []*Feed + var object *Feed + + if singular { + var ok bool + object, ok = maybeFeed.(*Feed) + if !ok { + object = new(Feed) + ok = queries.SetFromEmbeddedStruct(&object, &maybeFeed) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeFeed)) + } + } + } else { + s, ok := maybeFeed.(*[]*Feed) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeFeed) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeFeed)) + } + } + } + + args := make(map[interface{}]struct{}) + if singular { + if object.R == nil { + object.R = &feedR{} + } + args[object.ID] = struct{}{} + } else { + for _, obj := range slice { + if obj.R == nil { + obj.R = &feedR{} + } + args[obj.ID] = struct{}{} + } + } + + if len(args) == 0 { + return nil + } + + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`my_feeds`), + qm.WhereIn(`my_feeds.feed_id in ?`, argsSlice...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load my_feeds") + } + + var resultSlice []*MyFeed + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice my_feeds") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results in eager load on my_feeds") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for my_feeds") + } + + if len(myFeedAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + if singular { + object.R.MyFeeds = resultSlice + for _, foreign := range resultSlice { + if foreign.R == nil { + foreign.R = &myFeedR{} + } + foreign.R.Feed = object + } + return nil + } + + for _, foreign := range resultSlice { + for _, local := range slice { + if local.ID == foreign.FeedID { + local.R.MyFeeds = append(local.R.MyFeeds, foreign) + if foreign.R == nil { + foreign.R = &myFeedR{} + } + foreign.R.Feed = local + break + } + } + } + + return nil +} + // SetCategory of the feed to the related item. // Sets o.R.Category to related. // Adds o to related.R.Feeds. @@ -1009,6 +1146,59 @@ func (o *Feed) AddFeedArticleRelations(ctx context.Context, exec boil.ContextExe return nil } +// AddMyFeeds adds the given related objects to the existing relationships +// of the feed, optionally inserting them as new records. +// Appends related to o.R.MyFeeds. +// Sets related.R.Feed appropriately. +func (o *Feed) AddMyFeeds(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*MyFeed) error { + var err error + for _, rel := range related { + if insert { + rel.FeedID = o.ID + if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } else { + updateQuery := fmt.Sprintf( + "UPDATE \"my_feeds\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"feed_id"}), + strmangle.WhereClause("\"", "\"", 2, myFeedPrimaryKeyColumns), + ) + values := []interface{}{o.ID, rel.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update foreign table") + } + + rel.FeedID = o.ID + } + } + + if o.R == nil { + o.R = &feedR{ + MyFeeds: related, + } + } else { + o.R.MyFeeds = append(o.R.MyFeeds, related...) + } + + for _, rel := range related { + if rel.R == nil { + rel.R = &myFeedR{ + Feed: o, + } + } else { + rel.R.Feed = o + } + } + return nil +} + // Feeds retrieves all the records using an executor. func Feeds(mods ...qm.QueryMod) feedQuery { mods = append(mods, qm.From("\"feeds\"")) diff --git a/batch-service/entity/my_feed_lists.go b/batch-service/entity/my_feed_lists.go new file mode 100644 index 00000000..bdbfc6b5 --- /dev/null +++ b/batch-service/entity/my_feed_lists.go @@ -0,0 +1,1360 @@ +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package entity + +import ( + "context" + "database/sql" + "fmt" + "reflect" + "strconv" + "strings" + "sync" + "time" + + "github.com/friendsofgo/errors" + "github.com/volatiletech/null/v8" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" +) + +// MyFeedList is an object representing the database table. +type MyFeedList struct { + ID string `boil:"id" json:"id" toml:"id" yaml:"id"` + UserID string `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"` + Title string `boil:"title" json:"title" toml:"title" yaml:"title"` + Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"` + CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"` + UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"` + + R *myFeedListR `boil:"-" json:"-" toml:"-" yaml:"-"` + L myFeedListL `boil:"-" json:"-" toml:"-" yaml:"-"` +} + +var MyFeedListColumns = struct { + ID string + UserID string + Title string + Description string + CreatedAt string + UpdatedAt string +}{ + ID: "id", + UserID: "user_id", + Title: "title", + Description: "description", + CreatedAt: "created_at", + UpdatedAt: "updated_at", +} + +var MyFeedListTableColumns = struct { + ID string + UserID string + Title string + Description string + CreatedAt string + UpdatedAt string +}{ + ID: "my_feed_lists.id", + UserID: "my_feed_lists.user_id", + Title: "my_feed_lists.title", + Description: "my_feed_lists.description", + CreatedAt: "my_feed_lists.created_at", + UpdatedAt: "my_feed_lists.updated_at", +} + +// Generated where + +var MyFeedListWhere = struct { + ID whereHelperstring + UserID whereHelperstring + Title whereHelperstring + Description whereHelpernull_String + CreatedAt whereHelpertime_Time + UpdatedAt whereHelpertime_Time +}{ + ID: whereHelperstring{field: "\"my_feed_lists\".\"id\""}, + UserID: whereHelperstring{field: "\"my_feed_lists\".\"user_id\""}, + Title: whereHelperstring{field: "\"my_feed_lists\".\"title\""}, + Description: whereHelpernull_String{field: "\"my_feed_lists\".\"description\""}, + CreatedAt: whereHelpertime_Time{field: "\"my_feed_lists\".\"created_at\""}, + UpdatedAt: whereHelpertime_Time{field: "\"my_feed_lists\".\"updated_at\""}, +} + +// MyFeedListRels is where relationship names are stored. +var MyFeedListRels = struct { + User string + MyFeeds string +}{ + User: "User", + MyFeeds: "MyFeeds", +} + +// myFeedListR is where relationships are stored. +type myFeedListR struct { + User *Profile `boil:"User" json:"User" toml:"User" yaml:"User"` + MyFeeds MyFeedSlice `boil:"MyFeeds" json:"MyFeeds" toml:"MyFeeds" yaml:"MyFeeds"` +} + +// NewStruct creates a new relationship struct +func (*myFeedListR) NewStruct() *myFeedListR { + return &myFeedListR{} +} + +func (r *myFeedListR) GetUser() *Profile { + if r == nil { + return nil + } + return r.User +} + +func (r *myFeedListR) GetMyFeeds() MyFeedSlice { + if r == nil { + return nil + } + return r.MyFeeds +} + +// myFeedListL is where Load methods for each relationship are stored. +type myFeedListL struct{} + +var ( + myFeedListAllColumns = []string{"id", "user_id", "title", "description", "created_at", "updated_at"} + myFeedListColumnsWithoutDefault = []string{"user_id", "title"} + myFeedListColumnsWithDefault = []string{"id", "description", "created_at", "updated_at"} + myFeedListPrimaryKeyColumns = []string{"id"} + myFeedListGeneratedColumns = []string{} +) + +type ( + // MyFeedListSlice is an alias for a slice of pointers to MyFeedList. + // This should almost always be used instead of []MyFeedList. + MyFeedListSlice []*MyFeedList + // MyFeedListHook is the signature for custom MyFeedList hook methods + MyFeedListHook func(context.Context, boil.ContextExecutor, *MyFeedList) error + + myFeedListQuery struct { + *queries.Query + } +) + +// Cache for insert, update and upsert +var ( + myFeedListType = reflect.TypeOf(&MyFeedList{}) + myFeedListMapping = queries.MakeStructMapping(myFeedListType) + myFeedListPrimaryKeyMapping, _ = queries.BindMapping(myFeedListType, myFeedListMapping, myFeedListPrimaryKeyColumns) + myFeedListInsertCacheMut sync.RWMutex + myFeedListInsertCache = make(map[string]insertCache) + myFeedListUpdateCacheMut sync.RWMutex + myFeedListUpdateCache = make(map[string]updateCache) + myFeedListUpsertCacheMut sync.RWMutex + myFeedListUpsertCache = make(map[string]insertCache) +) + +var ( + // Force time package dependency for automated UpdatedAt/CreatedAt. + _ = time.Second + // Force qmhelper dependency for where clause generation (which doesn't + // always happen) + _ = qmhelper.Where +) + +var myFeedListAfterSelectMu sync.Mutex +var myFeedListAfterSelectHooks []MyFeedListHook + +var myFeedListBeforeInsertMu sync.Mutex +var myFeedListBeforeInsertHooks []MyFeedListHook +var myFeedListAfterInsertMu sync.Mutex +var myFeedListAfterInsertHooks []MyFeedListHook + +var myFeedListBeforeUpdateMu sync.Mutex +var myFeedListBeforeUpdateHooks []MyFeedListHook +var myFeedListAfterUpdateMu sync.Mutex +var myFeedListAfterUpdateHooks []MyFeedListHook + +var myFeedListBeforeDeleteMu sync.Mutex +var myFeedListBeforeDeleteHooks []MyFeedListHook +var myFeedListAfterDeleteMu sync.Mutex +var myFeedListAfterDeleteHooks []MyFeedListHook + +var myFeedListBeforeUpsertMu sync.Mutex +var myFeedListBeforeUpsertHooks []MyFeedListHook +var myFeedListAfterUpsertMu sync.Mutex +var myFeedListAfterUpsertHooks []MyFeedListHook + +// doAfterSelectHooks executes all "after Select" hooks. +func (o *MyFeedList) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedListAfterSelectHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeInsertHooks executes all "before insert" hooks. +func (o *MyFeedList) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedListBeforeInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterInsertHooks executes all "after Insert" hooks. +func (o *MyFeedList) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedListAfterInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpdateHooks executes all "before Update" hooks. +func (o *MyFeedList) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedListBeforeUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpdateHooks executes all "after Update" hooks. +func (o *MyFeedList) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedListAfterUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeDeleteHooks executes all "before Delete" hooks. +func (o *MyFeedList) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedListBeforeDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterDeleteHooks executes all "after Delete" hooks. +func (o *MyFeedList) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedListAfterDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpsertHooks executes all "before Upsert" hooks. +func (o *MyFeedList) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedListBeforeUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpsertHooks executes all "after Upsert" hooks. +func (o *MyFeedList) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedListAfterUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// AddMyFeedListHook registers your hook function for all future operations. +func AddMyFeedListHook(hookPoint boil.HookPoint, myFeedListHook MyFeedListHook) { + switch hookPoint { + case boil.AfterSelectHook: + myFeedListAfterSelectMu.Lock() + myFeedListAfterSelectHooks = append(myFeedListAfterSelectHooks, myFeedListHook) + myFeedListAfterSelectMu.Unlock() + case boil.BeforeInsertHook: + myFeedListBeforeInsertMu.Lock() + myFeedListBeforeInsertHooks = append(myFeedListBeforeInsertHooks, myFeedListHook) + myFeedListBeforeInsertMu.Unlock() + case boil.AfterInsertHook: + myFeedListAfterInsertMu.Lock() + myFeedListAfterInsertHooks = append(myFeedListAfterInsertHooks, myFeedListHook) + myFeedListAfterInsertMu.Unlock() + case boil.BeforeUpdateHook: + myFeedListBeforeUpdateMu.Lock() + myFeedListBeforeUpdateHooks = append(myFeedListBeforeUpdateHooks, myFeedListHook) + myFeedListBeforeUpdateMu.Unlock() + case boil.AfterUpdateHook: + myFeedListAfterUpdateMu.Lock() + myFeedListAfterUpdateHooks = append(myFeedListAfterUpdateHooks, myFeedListHook) + myFeedListAfterUpdateMu.Unlock() + case boil.BeforeDeleteHook: + myFeedListBeforeDeleteMu.Lock() + myFeedListBeforeDeleteHooks = append(myFeedListBeforeDeleteHooks, myFeedListHook) + myFeedListBeforeDeleteMu.Unlock() + case boil.AfterDeleteHook: + myFeedListAfterDeleteMu.Lock() + myFeedListAfterDeleteHooks = append(myFeedListAfterDeleteHooks, myFeedListHook) + myFeedListAfterDeleteMu.Unlock() + case boil.BeforeUpsertHook: + myFeedListBeforeUpsertMu.Lock() + myFeedListBeforeUpsertHooks = append(myFeedListBeforeUpsertHooks, myFeedListHook) + myFeedListBeforeUpsertMu.Unlock() + case boil.AfterUpsertHook: + myFeedListAfterUpsertMu.Lock() + myFeedListAfterUpsertHooks = append(myFeedListAfterUpsertHooks, myFeedListHook) + myFeedListAfterUpsertMu.Unlock() + } +} + +// One returns a single myFeedList record from the query. +func (q myFeedListQuery) One(ctx context.Context, exec boil.ContextExecutor) (*MyFeedList, error) { + o := &MyFeedList{} + + queries.SetLimit(q.Query, 1) + + err := q.Bind(ctx, exec, o) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return nil, sql.ErrNoRows + } + return nil, errors.Wrap(err, "entity: failed to execute a one query for my_feed_lists") + } + + if err := o.doAfterSelectHooks(ctx, exec); err != nil { + return o, err + } + + return o, nil +} + +// All returns all MyFeedList records from the query. +func (q myFeedListQuery) All(ctx context.Context, exec boil.ContextExecutor) (MyFeedListSlice, error) { + var o []*MyFeedList + + err := q.Bind(ctx, exec, &o) + if err != nil { + return nil, errors.Wrap(err, "entity: failed to assign all query results to MyFeedList slice") + } + + if len(myFeedListAfterSelectHooks) != 0 { + for _, obj := range o { + if err := obj.doAfterSelectHooks(ctx, exec); err != nil { + return o, err + } + } + } + + return o, nil +} + +// Count returns the count of all MyFeedList records in the query. +func (q myFeedListQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + var count int64 + + queries.SetSelect(q.Query, nil) + queries.SetCount(q.Query) + + err := q.Query.QueryRowContext(ctx, exec).Scan(&count) + if err != nil { + return 0, errors.Wrap(err, "entity: failed to count my_feed_lists rows") + } + + return count, nil +} + +// Exists checks if the row exists in the table. +func (q myFeedListQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + var count int64 + + queries.SetSelect(q.Query, nil) + queries.SetCount(q.Query) + queries.SetLimit(q.Query, 1) + + err := q.Query.QueryRowContext(ctx, exec).Scan(&count) + if err != nil { + return false, errors.Wrap(err, "entity: failed to check if my_feed_lists exists") + } + + return count > 0, nil +} + +// User pointed to by the foreign key. +func (o *MyFeedList) User(mods ...qm.QueryMod) profileQuery { + queryMods := []qm.QueryMod{ + qm.Where("\"id\" = ?", o.UserID), + } + + queryMods = append(queryMods, mods...) + + return Profiles(queryMods...) +} + +// MyFeeds retrieves all the my_feed's MyFeeds with an executor. +func (o *MyFeedList) MyFeeds(mods ...qm.QueryMod) myFeedQuery { + var queryMods []qm.QueryMod + if len(mods) != 0 { + queryMods = append(queryMods, mods...) + } + + queryMods = append(queryMods, + qm.Where("\"my_feeds\".\"my_feed_list_id\"=?", o.ID), + ) + + return MyFeeds(queryMods...) +} + +// LoadUser allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for an N-1 relationship. +func (myFeedListL) LoadUser(ctx context.Context, e boil.ContextExecutor, singular bool, maybeMyFeedList interface{}, mods queries.Applicator) error { + var slice []*MyFeedList + var object *MyFeedList + + if singular { + var ok bool + object, ok = maybeMyFeedList.(*MyFeedList) + if !ok { + object = new(MyFeedList) + ok = queries.SetFromEmbeddedStruct(&object, &maybeMyFeedList) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeMyFeedList)) + } + } + } else { + s, ok := maybeMyFeedList.(*[]*MyFeedList) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeMyFeedList) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeMyFeedList)) + } + } + } + + args := make(map[interface{}]struct{}) + if singular { + if object.R == nil { + object.R = &myFeedListR{} + } + args[object.UserID] = struct{}{} + + } else { + for _, obj := range slice { + if obj.R == nil { + obj.R = &myFeedListR{} + } + + args[obj.UserID] = struct{}{} + + } + } + + if len(args) == 0 { + return nil + } + + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`profiles`), + qm.WhereIn(`profiles.id in ?`, argsSlice...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load Profile") + } + + var resultSlice []*Profile + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice Profile") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results of eager load for profiles") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for profiles") + } + + if len(profileAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + + if len(resultSlice) == 0 { + return nil + } + + if singular { + foreign := resultSlice[0] + object.R.User = foreign + if foreign.R == nil { + foreign.R = &profileR{} + } + foreign.R.UserMyFeedLists = append(foreign.R.UserMyFeedLists, object) + return nil + } + + for _, local := range slice { + for _, foreign := range resultSlice { + if local.UserID == foreign.ID { + local.R.User = foreign + if foreign.R == nil { + foreign.R = &profileR{} + } + foreign.R.UserMyFeedLists = append(foreign.R.UserMyFeedLists, local) + break + } + } + } + + return nil +} + +// LoadMyFeeds allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for a 1-M or N-M relationship. +func (myFeedListL) LoadMyFeeds(ctx context.Context, e boil.ContextExecutor, singular bool, maybeMyFeedList interface{}, mods queries.Applicator) error { + var slice []*MyFeedList + var object *MyFeedList + + if singular { + var ok bool + object, ok = maybeMyFeedList.(*MyFeedList) + if !ok { + object = new(MyFeedList) + ok = queries.SetFromEmbeddedStruct(&object, &maybeMyFeedList) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeMyFeedList)) + } + } + } else { + s, ok := maybeMyFeedList.(*[]*MyFeedList) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeMyFeedList) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeMyFeedList)) + } + } + } + + args := make(map[interface{}]struct{}) + if singular { + if object.R == nil { + object.R = &myFeedListR{} + } + args[object.ID] = struct{}{} + } else { + for _, obj := range slice { + if obj.R == nil { + obj.R = &myFeedListR{} + } + args[obj.ID] = struct{}{} + } + } + + if len(args) == 0 { + return nil + } + + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`my_feeds`), + qm.WhereIn(`my_feeds.my_feed_list_id in ?`, argsSlice...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load my_feeds") + } + + var resultSlice []*MyFeed + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice my_feeds") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results in eager load on my_feeds") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for my_feeds") + } + + if len(myFeedAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + if singular { + object.R.MyFeeds = resultSlice + for _, foreign := range resultSlice { + if foreign.R == nil { + foreign.R = &myFeedR{} + } + foreign.R.MyFeedList = object + } + return nil + } + + for _, foreign := range resultSlice { + for _, local := range slice { + if local.ID == foreign.MyFeedListID { + local.R.MyFeeds = append(local.R.MyFeeds, foreign) + if foreign.R == nil { + foreign.R = &myFeedR{} + } + foreign.R.MyFeedList = local + break + } + } + } + + return nil +} + +// SetUser of the myFeedList to the related item. +// Sets o.R.User to related. +// Adds o to related.R.UserMyFeedLists. +func (o *MyFeedList) SetUser(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Profile) error { + var err error + if insert { + if err = related.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } + + updateQuery := fmt.Sprintf( + "UPDATE \"my_feed_lists\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}), + strmangle.WhereClause("\"", "\"", 2, myFeedListPrimaryKeyColumns), + ) + values := []interface{}{related.ID, o.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update local table") + } + + o.UserID = related.ID + if o.R == nil { + o.R = &myFeedListR{ + User: related, + } + } else { + o.R.User = related + } + + if related.R == nil { + related.R = &profileR{ + UserMyFeedLists: MyFeedListSlice{o}, + } + } else { + related.R.UserMyFeedLists = append(related.R.UserMyFeedLists, o) + } + + return nil +} + +// AddMyFeeds adds the given related objects to the existing relationships +// of the my_feed_list, optionally inserting them as new records. +// Appends related to o.R.MyFeeds. +// Sets related.R.MyFeedList appropriately. +func (o *MyFeedList) AddMyFeeds(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*MyFeed) error { + var err error + for _, rel := range related { + if insert { + rel.MyFeedListID = o.ID + if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } else { + updateQuery := fmt.Sprintf( + "UPDATE \"my_feeds\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"my_feed_list_id"}), + strmangle.WhereClause("\"", "\"", 2, myFeedPrimaryKeyColumns), + ) + values := []interface{}{o.ID, rel.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update foreign table") + } + + rel.MyFeedListID = o.ID + } + } + + if o.R == nil { + o.R = &myFeedListR{ + MyFeeds: related, + } + } else { + o.R.MyFeeds = append(o.R.MyFeeds, related...) + } + + for _, rel := range related { + if rel.R == nil { + rel.R = &myFeedR{ + MyFeedList: o, + } + } else { + rel.R.MyFeedList = o + } + } + return nil +} + +// MyFeedLists retrieves all the records using an executor. +func MyFeedLists(mods ...qm.QueryMod) myFeedListQuery { + mods = append(mods, qm.From("\"my_feed_lists\"")) + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"my_feed_lists\".*"}) + } + + return myFeedListQuery{q} +} + +// FindMyFeedList retrieves a single record by ID with an executor. +// If selectCols is empty Find will return all columns. +func FindMyFeedList(ctx context.Context, exec boil.ContextExecutor, iD string, selectCols ...string) (*MyFeedList, error) { + myFeedListObj := &MyFeedList{} + + sel := "*" + if len(selectCols) > 0 { + sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") + } + query := fmt.Sprintf( + "select %s from \"my_feed_lists\" where \"id\"=$1", sel, + ) + + q := queries.Raw(query, iD) + + err := q.Bind(ctx, exec, myFeedListObj) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return nil, sql.ErrNoRows + } + return nil, errors.Wrap(err, "entity: unable to select from my_feed_lists") + } + + if err = myFeedListObj.doAfterSelectHooks(ctx, exec); err != nil { + return myFeedListObj, err + } + + return myFeedListObj, nil +} + +// Insert a single record using an executor. +// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. +func (o *MyFeedList) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error { + if o == nil { + return errors.New("entity: no my_feed_lists provided for insertion") + } + + var err error + if !boil.TimestampsAreSkipped(ctx) { + currTime := time.Now().In(boil.GetLocation()) + + if o.CreatedAt.IsZero() { + o.CreatedAt = currTime + } + if o.UpdatedAt.IsZero() { + o.UpdatedAt = currTime + } + } + + if err := o.doBeforeInsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(myFeedListColumnsWithDefault, o) + + key := makeCacheKey(columns, nzDefaults) + myFeedListInsertCacheMut.RLock() + cache, cached := myFeedListInsertCache[key] + myFeedListInsertCacheMut.RUnlock() + + if !cached { + wl, returnColumns := columns.InsertColumnSet( + myFeedListAllColumns, + myFeedListColumnsWithDefault, + myFeedListColumnsWithoutDefault, + nzDefaults, + ) + + cache.valueMapping, err = queries.BindMapping(myFeedListType, myFeedListMapping, wl) + if err != nil { + return err + } + cache.retMapping, err = queries.BindMapping(myFeedListType, myFeedListMapping, returnColumns) + if err != nil { + return err + } + if len(wl) != 0 { + cache.query = fmt.Sprintf("INSERT INTO \"my_feed_lists\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) + } else { + cache.query = "INSERT INTO \"my_feed_lists\" %sDEFAULT VALUES%s" + } + + var queryOutput, queryReturning string + + if len(cache.retMapping) != 0 { + queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\"")) + } + + cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning) + } + + value := reflect.Indirect(reflect.ValueOf(o)) + vals := queries.ValuesFromMapping(value, cache.valueMapping) + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) + } + + if len(cache.retMapping) != 0 { + err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...) + } else { + _, err = exec.ExecContext(ctx, cache.query, vals...) + } + + if err != nil { + return errors.Wrap(err, "entity: unable to insert into my_feed_lists") + } + + if !cached { + myFeedListInsertCacheMut.Lock() + myFeedListInsertCache[key] = cache + myFeedListInsertCacheMut.Unlock() + } + + return o.doAfterInsertHooks(ctx, exec) +} + +// Update uses an executor to update the MyFeedList. +// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates. +// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records. +func (o *MyFeedList) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) { + if !boil.TimestampsAreSkipped(ctx) { + currTime := time.Now().In(boil.GetLocation()) + + o.UpdatedAt = currTime + } + + var err error + if err = o.doBeforeUpdateHooks(ctx, exec); err != nil { + return 0, err + } + key := makeCacheKey(columns, nil) + myFeedListUpdateCacheMut.RLock() + cache, cached := myFeedListUpdateCache[key] + myFeedListUpdateCacheMut.RUnlock() + + if !cached { + wl := columns.UpdateColumnSet( + myFeedListAllColumns, + myFeedListPrimaryKeyColumns, + ) + + if !columns.IsWhitelist() { + wl = strmangle.SetComplement(wl, []string{"created_at"}) + } + if len(wl) == 0 { + return 0, errors.New("entity: unable to update my_feed_lists, could not build whitelist") + } + + cache.query = fmt.Sprintf("UPDATE \"my_feed_lists\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, wl), + strmangle.WhereClause("\"", "\"", len(wl)+1, myFeedListPrimaryKeyColumns), + ) + cache.valueMapping, err = queries.BindMapping(myFeedListType, myFeedListMapping, append(wl, myFeedListPrimaryKeyColumns...)) + if err != nil { + return 0, err + } + } + + values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) + } + var result sql.Result + result, err = exec.ExecContext(ctx, cache.query, values...) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to update my_feed_lists row") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: failed to get rows affected by update for my_feed_lists") + } + + if !cached { + myFeedListUpdateCacheMut.Lock() + myFeedListUpdateCache[key] = cache + myFeedListUpdateCacheMut.Unlock() + } + + return rowsAff, o.doAfterUpdateHooks(ctx, exec) +} + +// UpdateAll updates all rows with the specified column values. +func (q myFeedListQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) { + queries.SetUpdate(q.Query, cols) + + result, err := q.Query.ExecContext(ctx, exec) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to update all for my_feed_lists") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: unable to retrieve rows affected for my_feed_lists") + } + + return rowsAff, nil +} + +// UpdateAll updates all rows with the specified column values, using an executor. +func (o MyFeedListSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) { + ln := int64(len(o)) + if ln == 0 { + return 0, nil + } + + if len(cols) == 0 { + return 0, errors.New("entity: update all requires at least one column argument") + } + + colNames := make([]string, len(cols)) + args := make([]interface{}, len(cols)) + + i := 0 + for name, value := range cols { + colNames[i] = name + args[i] = value + i++ + } + + // Append all of the primary key values for each column + for _, obj := range o { + pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), myFeedListPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := fmt.Sprintf("UPDATE \"my_feed_lists\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, colNames), + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, myFeedListPrimaryKeyColumns, len(o))) + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) + } + result, err := exec.ExecContext(ctx, sql, args...) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to update all in myFeedList slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: unable to retrieve rows affected all in update all myFeedList") + } + return rowsAff, nil +} + +// Upsert attempts an insert using an executor, and does an update or ignore on conflict. +// See boil.Columns documentation for how to properly use updateColumns and insertColumns. +func (o *MyFeedList) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + if o == nil { + return errors.New("entity: no my_feed_lists provided for upsert") + } + if !boil.TimestampsAreSkipped(ctx) { + currTime := time.Now().In(boil.GetLocation()) + + if o.CreatedAt.IsZero() { + o.CreatedAt = currTime + } + o.UpdatedAt = currTime + } + + if err := o.doBeforeUpsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(myFeedListColumnsWithDefault, o) + + // Build cache key in-line uglily - mysql vs psql problems + buf := strmangle.GetBuffer() + if updateOnConflict { + buf.WriteByte('t') + } else { + buf.WriteByte('f') + } + buf.WriteByte('.') + for _, c := range conflictColumns { + buf.WriteString(c) + } + buf.WriteByte('.') + buf.WriteString(strconv.Itoa(updateColumns.Kind)) + for _, c := range updateColumns.Cols { + buf.WriteString(c) + } + buf.WriteByte('.') + buf.WriteString(strconv.Itoa(insertColumns.Kind)) + for _, c := range insertColumns.Cols { + buf.WriteString(c) + } + buf.WriteByte('.') + for _, c := range nzDefaults { + buf.WriteString(c) + } + key := buf.String() + strmangle.PutBuffer(buf) + + myFeedListUpsertCacheMut.RLock() + cache, cached := myFeedListUpsertCache[key] + myFeedListUpsertCacheMut.RUnlock() + + var err error + + if !cached { + insert, _ := insertColumns.InsertColumnSet( + myFeedListAllColumns, + myFeedListColumnsWithDefault, + myFeedListColumnsWithoutDefault, + nzDefaults, + ) + + update := updateColumns.UpdateColumnSet( + myFeedListAllColumns, + myFeedListPrimaryKeyColumns, + ) + + if updateOnConflict && len(update) == 0 { + return errors.New("entity: unable to upsert my_feed_lists, could not build update column list") + } + + ret := strmangle.SetComplement(myFeedListAllColumns, strmangle.SetIntersect(insert, update)) + + conflict := conflictColumns + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(myFeedListPrimaryKeyColumns) == 0 { + return errors.New("entity: unable to upsert my_feed_lists, could not build conflict column list") + } + + conflict = make([]string, len(myFeedListPrimaryKeyColumns)) + copy(conflict, myFeedListPrimaryKeyColumns) + } + cache.query = buildUpsertQueryPostgres(dialect, "\"my_feed_lists\"", updateOnConflict, ret, update, conflict, insert, opts...) + + cache.valueMapping, err = queries.BindMapping(myFeedListType, myFeedListMapping, insert) + if err != nil { + return err + } + if len(ret) != 0 { + cache.retMapping, err = queries.BindMapping(myFeedListType, myFeedListMapping, ret) + if err != nil { + return err + } + } + } + + value := reflect.Indirect(reflect.ValueOf(o)) + vals := queries.ValuesFromMapping(value, cache.valueMapping) + var returns []interface{} + if len(cache.retMapping) != 0 { + returns = queries.PtrsFromMapping(value, cache.retMapping) + } + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) + } + if len(cache.retMapping) != 0 { + err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) + if errors.Is(err, sql.ErrNoRows) { + err = nil // Postgres doesn't return anything when there's no update + } + } else { + _, err = exec.ExecContext(ctx, cache.query, vals...) + } + if err != nil { + return errors.Wrap(err, "entity: unable to upsert my_feed_lists") + } + + if !cached { + myFeedListUpsertCacheMut.Lock() + myFeedListUpsertCache[key] = cache + myFeedListUpsertCacheMut.Unlock() + } + + return o.doAfterUpsertHooks(ctx, exec) +} + +// Delete deletes a single MyFeedList record with an executor. +// Delete will match against the primary key column to find the record to delete. +func (o *MyFeedList) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if o == nil { + return 0, errors.New("entity: no MyFeedList provided for delete") + } + + if err := o.doBeforeDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), myFeedListPrimaryKeyMapping) + sql := "DELETE FROM \"my_feed_lists\" WHERE \"id\"=$1" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) + } + result, err := exec.ExecContext(ctx, sql, args...) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to delete from my_feed_lists") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: failed to get rows affected by delete for my_feed_lists") + } + + if err := o.doAfterDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + return rowsAff, nil +} + +// DeleteAll deletes all matching rows. +func (q myFeedListQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if q.Query == nil { + return 0, errors.New("entity: no myFeedListQuery provided for delete all") + } + + queries.SetDelete(q.Query) + + result, err := q.Query.ExecContext(ctx, exec) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to delete all from my_feed_lists") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: failed to get rows affected by deleteall for my_feed_lists") + } + + return rowsAff, nil +} + +// DeleteAll deletes all rows in the slice, using an executor. +func (o MyFeedListSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if len(o) == 0 { + return 0, nil + } + + if len(myFeedListBeforeDeleteHooks) != 0 { + for _, obj := range o { + if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil { + return 0, err + } + } + } + + var args []interface{} + for _, obj := range o { + pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), myFeedListPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "DELETE FROM \"my_feed_lists\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, myFeedListPrimaryKeyColumns, len(o)) + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) + } + result, err := exec.ExecContext(ctx, sql, args...) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to delete all from myFeedList slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: failed to get rows affected by deleteall for my_feed_lists") + } + + if len(myFeedListAfterDeleteHooks) != 0 { + for _, obj := range o { + if err := obj.doAfterDeleteHooks(ctx, exec); err != nil { + return 0, err + } + } + } + + return rowsAff, nil +} + +// Reload refetches the object from the database +// using the primary keys with an executor. +func (o *MyFeedList) Reload(ctx context.Context, exec boil.ContextExecutor) error { + ret, err := FindMyFeedList(ctx, exec, o.ID) + if err != nil { + return err + } + + *o = *ret + return nil +} + +// ReloadAll refetches every row with matching primary key column values +// and overwrites the original object slice with the newly updated slice. +func (o *MyFeedListSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error { + if o == nil || len(*o) == 0 { + return nil + } + + slice := MyFeedListSlice{} + var args []interface{} + for _, obj := range *o { + pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), myFeedListPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "SELECT \"my_feed_lists\".* FROM \"my_feed_lists\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, myFeedListPrimaryKeyColumns, len(*o)) + + q := queries.Raw(sql, args...) + + err := q.Bind(ctx, exec, &slice) + if err != nil { + return errors.Wrap(err, "entity: unable to reload all in MyFeedListSlice") + } + + *o = slice + + return nil +} + +// MyFeedListExists checks if the MyFeedList row exists. +func MyFeedListExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bool, error) { + var exists bool + sql := "select exists(select 1 from \"my_feed_lists\" where \"id\"=$1 limit 1)" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) + } + row := exec.QueryRowContext(ctx, sql, iD) + + err := row.Scan(&exists) + if err != nil { + return false, errors.Wrap(err, "entity: unable to check if my_feed_lists exists") + } + + return exists, nil +} + +// Exists checks if the MyFeedList row exists. +func (o *MyFeedList) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return MyFeedListExists(ctx, exec, o.ID) +} diff --git a/batch-service/entity/my_feeds.go b/batch-service/entity/my_feeds.go new file mode 100644 index 00000000..7410d952 --- /dev/null +++ b/batch-service/entity/my_feeds.go @@ -0,0 +1,1545 @@ +// Code generated by SQLBoiler 4.16.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package entity + +import ( + "context" + "database/sql" + "fmt" + "reflect" + "strconv" + "strings" + "sync" + "time" + + "github.com/friendsofgo/errors" + "github.com/volatiletech/sqlboiler/v4/boil" + "github.com/volatiletech/sqlboiler/v4/queries" + "github.com/volatiletech/sqlboiler/v4/queries/qm" + "github.com/volatiletech/sqlboiler/v4/queries/qmhelper" + "github.com/volatiletech/strmangle" +) + +// MyFeed is an object representing the database table. +type MyFeed struct { + ID string `boil:"id" json:"id" toml:"id" yaml:"id"` + UserID string `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"` + MyFeedListID string `boil:"my_feed_list_id" json:"my_feed_list_id" toml:"my_feed_list_id" yaml:"my_feed_list_id"` + FeedID string `boil:"feed_id" json:"feed_id" toml:"feed_id" yaml:"feed_id"` + CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"` + UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"` + + R *myFeedR `boil:"-" json:"-" toml:"-" yaml:"-"` + L myFeedL `boil:"-" json:"-" toml:"-" yaml:"-"` +} + +var MyFeedColumns = struct { + ID string + UserID string + MyFeedListID string + FeedID string + CreatedAt string + UpdatedAt string +}{ + ID: "id", + UserID: "user_id", + MyFeedListID: "my_feed_list_id", + FeedID: "feed_id", + CreatedAt: "created_at", + UpdatedAt: "updated_at", +} + +var MyFeedTableColumns = struct { + ID string + UserID string + MyFeedListID string + FeedID string + CreatedAt string + UpdatedAt string +}{ + ID: "my_feeds.id", + UserID: "my_feeds.user_id", + MyFeedListID: "my_feeds.my_feed_list_id", + FeedID: "my_feeds.feed_id", + CreatedAt: "my_feeds.created_at", + UpdatedAt: "my_feeds.updated_at", +} + +// Generated where + +var MyFeedWhere = struct { + ID whereHelperstring + UserID whereHelperstring + MyFeedListID whereHelperstring + FeedID whereHelperstring + CreatedAt whereHelpertime_Time + UpdatedAt whereHelpertime_Time +}{ + ID: whereHelperstring{field: "\"my_feeds\".\"id\""}, + UserID: whereHelperstring{field: "\"my_feeds\".\"user_id\""}, + MyFeedListID: whereHelperstring{field: "\"my_feeds\".\"my_feed_list_id\""}, + FeedID: whereHelperstring{field: "\"my_feeds\".\"feed_id\""}, + CreatedAt: whereHelpertime_Time{field: "\"my_feeds\".\"created_at\""}, + UpdatedAt: whereHelpertime_Time{field: "\"my_feeds\".\"updated_at\""}, +} + +// MyFeedRels is where relationship names are stored. +var MyFeedRels = struct { + Feed string + MyFeedList string + User string +}{ + Feed: "Feed", + MyFeedList: "MyFeedList", + User: "User", +} + +// myFeedR is where relationships are stored. +type myFeedR struct { + Feed *Feed `boil:"Feed" json:"Feed" toml:"Feed" yaml:"Feed"` + MyFeedList *MyFeedList `boil:"MyFeedList" json:"MyFeedList" toml:"MyFeedList" yaml:"MyFeedList"` + User *Profile `boil:"User" json:"User" toml:"User" yaml:"User"` +} + +// NewStruct creates a new relationship struct +func (*myFeedR) NewStruct() *myFeedR { + return &myFeedR{} +} + +func (r *myFeedR) GetFeed() *Feed { + if r == nil { + return nil + } + return r.Feed +} + +func (r *myFeedR) GetMyFeedList() *MyFeedList { + if r == nil { + return nil + } + return r.MyFeedList +} + +func (r *myFeedR) GetUser() *Profile { + if r == nil { + return nil + } + return r.User +} + +// myFeedL is where Load methods for each relationship are stored. +type myFeedL struct{} + +var ( + myFeedAllColumns = []string{"id", "user_id", "my_feed_list_id", "feed_id", "created_at", "updated_at"} + myFeedColumnsWithoutDefault = []string{"user_id", "my_feed_list_id", "feed_id"} + myFeedColumnsWithDefault = []string{"id", "created_at", "updated_at"} + myFeedPrimaryKeyColumns = []string{"id"} + myFeedGeneratedColumns = []string{} +) + +type ( + // MyFeedSlice is an alias for a slice of pointers to MyFeed. + // This should almost always be used instead of []MyFeed. + MyFeedSlice []*MyFeed + // MyFeedHook is the signature for custom MyFeed hook methods + MyFeedHook func(context.Context, boil.ContextExecutor, *MyFeed) error + + myFeedQuery struct { + *queries.Query + } +) + +// Cache for insert, update and upsert +var ( + myFeedType = reflect.TypeOf(&MyFeed{}) + myFeedMapping = queries.MakeStructMapping(myFeedType) + myFeedPrimaryKeyMapping, _ = queries.BindMapping(myFeedType, myFeedMapping, myFeedPrimaryKeyColumns) + myFeedInsertCacheMut sync.RWMutex + myFeedInsertCache = make(map[string]insertCache) + myFeedUpdateCacheMut sync.RWMutex + myFeedUpdateCache = make(map[string]updateCache) + myFeedUpsertCacheMut sync.RWMutex + myFeedUpsertCache = make(map[string]insertCache) +) + +var ( + // Force time package dependency for automated UpdatedAt/CreatedAt. + _ = time.Second + // Force qmhelper dependency for where clause generation (which doesn't + // always happen) + _ = qmhelper.Where +) + +var myFeedAfterSelectMu sync.Mutex +var myFeedAfterSelectHooks []MyFeedHook + +var myFeedBeforeInsertMu sync.Mutex +var myFeedBeforeInsertHooks []MyFeedHook +var myFeedAfterInsertMu sync.Mutex +var myFeedAfterInsertHooks []MyFeedHook + +var myFeedBeforeUpdateMu sync.Mutex +var myFeedBeforeUpdateHooks []MyFeedHook +var myFeedAfterUpdateMu sync.Mutex +var myFeedAfterUpdateHooks []MyFeedHook + +var myFeedBeforeDeleteMu sync.Mutex +var myFeedBeforeDeleteHooks []MyFeedHook +var myFeedAfterDeleteMu sync.Mutex +var myFeedAfterDeleteHooks []MyFeedHook + +var myFeedBeforeUpsertMu sync.Mutex +var myFeedBeforeUpsertHooks []MyFeedHook +var myFeedAfterUpsertMu sync.Mutex +var myFeedAfterUpsertHooks []MyFeedHook + +// doAfterSelectHooks executes all "after Select" hooks. +func (o *MyFeed) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedAfterSelectHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeInsertHooks executes all "before insert" hooks. +func (o *MyFeed) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedBeforeInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterInsertHooks executes all "after Insert" hooks. +func (o *MyFeed) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedAfterInsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpdateHooks executes all "before Update" hooks. +func (o *MyFeed) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedBeforeUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpdateHooks executes all "after Update" hooks. +func (o *MyFeed) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedAfterUpdateHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeDeleteHooks executes all "before Delete" hooks. +func (o *MyFeed) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedBeforeDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterDeleteHooks executes all "after Delete" hooks. +func (o *MyFeed) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedAfterDeleteHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doBeforeUpsertHooks executes all "before Upsert" hooks. +func (o *MyFeed) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedBeforeUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// doAfterUpsertHooks executes all "after Upsert" hooks. +func (o *MyFeed) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { + if boil.HooksAreSkipped(ctx) { + return nil + } + + for _, hook := range myFeedAfterUpsertHooks { + if err := hook(ctx, exec, o); err != nil { + return err + } + } + + return nil +} + +// AddMyFeedHook registers your hook function for all future operations. +func AddMyFeedHook(hookPoint boil.HookPoint, myFeedHook MyFeedHook) { + switch hookPoint { + case boil.AfterSelectHook: + myFeedAfterSelectMu.Lock() + myFeedAfterSelectHooks = append(myFeedAfterSelectHooks, myFeedHook) + myFeedAfterSelectMu.Unlock() + case boil.BeforeInsertHook: + myFeedBeforeInsertMu.Lock() + myFeedBeforeInsertHooks = append(myFeedBeforeInsertHooks, myFeedHook) + myFeedBeforeInsertMu.Unlock() + case boil.AfterInsertHook: + myFeedAfterInsertMu.Lock() + myFeedAfterInsertHooks = append(myFeedAfterInsertHooks, myFeedHook) + myFeedAfterInsertMu.Unlock() + case boil.BeforeUpdateHook: + myFeedBeforeUpdateMu.Lock() + myFeedBeforeUpdateHooks = append(myFeedBeforeUpdateHooks, myFeedHook) + myFeedBeforeUpdateMu.Unlock() + case boil.AfterUpdateHook: + myFeedAfterUpdateMu.Lock() + myFeedAfterUpdateHooks = append(myFeedAfterUpdateHooks, myFeedHook) + myFeedAfterUpdateMu.Unlock() + case boil.BeforeDeleteHook: + myFeedBeforeDeleteMu.Lock() + myFeedBeforeDeleteHooks = append(myFeedBeforeDeleteHooks, myFeedHook) + myFeedBeforeDeleteMu.Unlock() + case boil.AfterDeleteHook: + myFeedAfterDeleteMu.Lock() + myFeedAfterDeleteHooks = append(myFeedAfterDeleteHooks, myFeedHook) + myFeedAfterDeleteMu.Unlock() + case boil.BeforeUpsertHook: + myFeedBeforeUpsertMu.Lock() + myFeedBeforeUpsertHooks = append(myFeedBeforeUpsertHooks, myFeedHook) + myFeedBeforeUpsertMu.Unlock() + case boil.AfterUpsertHook: + myFeedAfterUpsertMu.Lock() + myFeedAfterUpsertHooks = append(myFeedAfterUpsertHooks, myFeedHook) + myFeedAfterUpsertMu.Unlock() + } +} + +// One returns a single myFeed record from the query. +func (q myFeedQuery) One(ctx context.Context, exec boil.ContextExecutor) (*MyFeed, error) { + o := &MyFeed{} + + queries.SetLimit(q.Query, 1) + + err := q.Bind(ctx, exec, o) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return nil, sql.ErrNoRows + } + return nil, errors.Wrap(err, "entity: failed to execute a one query for my_feeds") + } + + if err := o.doAfterSelectHooks(ctx, exec); err != nil { + return o, err + } + + return o, nil +} + +// All returns all MyFeed records from the query. +func (q myFeedQuery) All(ctx context.Context, exec boil.ContextExecutor) (MyFeedSlice, error) { + var o []*MyFeed + + err := q.Bind(ctx, exec, &o) + if err != nil { + return nil, errors.Wrap(err, "entity: failed to assign all query results to MyFeed slice") + } + + if len(myFeedAfterSelectHooks) != 0 { + for _, obj := range o { + if err := obj.doAfterSelectHooks(ctx, exec); err != nil { + return o, err + } + } + } + + return o, nil +} + +// Count returns the count of all MyFeed records in the query. +func (q myFeedQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + var count int64 + + queries.SetSelect(q.Query, nil) + queries.SetCount(q.Query) + + err := q.Query.QueryRowContext(ctx, exec).Scan(&count) + if err != nil { + return 0, errors.Wrap(err, "entity: failed to count my_feeds rows") + } + + return count, nil +} + +// Exists checks if the row exists in the table. +func (q myFeedQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + var count int64 + + queries.SetSelect(q.Query, nil) + queries.SetCount(q.Query) + queries.SetLimit(q.Query, 1) + + err := q.Query.QueryRowContext(ctx, exec).Scan(&count) + if err != nil { + return false, errors.Wrap(err, "entity: failed to check if my_feeds exists") + } + + return count > 0, nil +} + +// Feed pointed to by the foreign key. +func (o *MyFeed) Feed(mods ...qm.QueryMod) feedQuery { + queryMods := []qm.QueryMod{ + qm.Where("\"id\" = ?", o.FeedID), + } + + queryMods = append(queryMods, mods...) + + return Feeds(queryMods...) +} + +// MyFeedList pointed to by the foreign key. +func (o *MyFeed) MyFeedList(mods ...qm.QueryMod) myFeedListQuery { + queryMods := []qm.QueryMod{ + qm.Where("\"id\" = ?", o.MyFeedListID), + } + + queryMods = append(queryMods, mods...) + + return MyFeedLists(queryMods...) +} + +// User pointed to by the foreign key. +func (o *MyFeed) User(mods ...qm.QueryMod) profileQuery { + queryMods := []qm.QueryMod{ + qm.Where("\"id\" = ?", o.UserID), + } + + queryMods = append(queryMods, mods...) + + return Profiles(queryMods...) +} + +// LoadFeed allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for an N-1 relationship. +func (myFeedL) LoadFeed(ctx context.Context, e boil.ContextExecutor, singular bool, maybeMyFeed interface{}, mods queries.Applicator) error { + var slice []*MyFeed + var object *MyFeed + + if singular { + var ok bool + object, ok = maybeMyFeed.(*MyFeed) + if !ok { + object = new(MyFeed) + ok = queries.SetFromEmbeddedStruct(&object, &maybeMyFeed) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeMyFeed)) + } + } + } else { + s, ok := maybeMyFeed.(*[]*MyFeed) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeMyFeed) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeMyFeed)) + } + } + } + + args := make(map[interface{}]struct{}) + if singular { + if object.R == nil { + object.R = &myFeedR{} + } + args[object.FeedID] = struct{}{} + + } else { + for _, obj := range slice { + if obj.R == nil { + obj.R = &myFeedR{} + } + + args[obj.FeedID] = struct{}{} + + } + } + + if len(args) == 0 { + return nil + } + + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`feeds`), + qm.WhereIn(`feeds.id in ?`, argsSlice...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load Feed") + } + + var resultSlice []*Feed + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice Feed") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results of eager load for feeds") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for feeds") + } + + if len(feedAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + + if len(resultSlice) == 0 { + return nil + } + + if singular { + foreign := resultSlice[0] + object.R.Feed = foreign + if foreign.R == nil { + foreign.R = &feedR{} + } + foreign.R.MyFeeds = append(foreign.R.MyFeeds, object) + return nil + } + + for _, local := range slice { + for _, foreign := range resultSlice { + if local.FeedID == foreign.ID { + local.R.Feed = foreign + if foreign.R == nil { + foreign.R = &feedR{} + } + foreign.R.MyFeeds = append(foreign.R.MyFeeds, local) + break + } + } + } + + return nil +} + +// LoadMyFeedList allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for an N-1 relationship. +func (myFeedL) LoadMyFeedList(ctx context.Context, e boil.ContextExecutor, singular bool, maybeMyFeed interface{}, mods queries.Applicator) error { + var slice []*MyFeed + var object *MyFeed + + if singular { + var ok bool + object, ok = maybeMyFeed.(*MyFeed) + if !ok { + object = new(MyFeed) + ok = queries.SetFromEmbeddedStruct(&object, &maybeMyFeed) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeMyFeed)) + } + } + } else { + s, ok := maybeMyFeed.(*[]*MyFeed) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeMyFeed) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeMyFeed)) + } + } + } + + args := make(map[interface{}]struct{}) + if singular { + if object.R == nil { + object.R = &myFeedR{} + } + args[object.MyFeedListID] = struct{}{} + + } else { + for _, obj := range slice { + if obj.R == nil { + obj.R = &myFeedR{} + } + + args[obj.MyFeedListID] = struct{}{} + + } + } + + if len(args) == 0 { + return nil + } + + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`my_feed_lists`), + qm.WhereIn(`my_feed_lists.id in ?`, argsSlice...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load MyFeedList") + } + + var resultSlice []*MyFeedList + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice MyFeedList") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results of eager load for my_feed_lists") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for my_feed_lists") + } + + if len(myFeedListAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + + if len(resultSlice) == 0 { + return nil + } + + if singular { + foreign := resultSlice[0] + object.R.MyFeedList = foreign + if foreign.R == nil { + foreign.R = &myFeedListR{} + } + foreign.R.MyFeeds = append(foreign.R.MyFeeds, object) + return nil + } + + for _, local := range slice { + for _, foreign := range resultSlice { + if local.MyFeedListID == foreign.ID { + local.R.MyFeedList = foreign + if foreign.R == nil { + foreign.R = &myFeedListR{} + } + foreign.R.MyFeeds = append(foreign.R.MyFeeds, local) + break + } + } + } + + return nil +} + +// LoadUser allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for an N-1 relationship. +func (myFeedL) LoadUser(ctx context.Context, e boil.ContextExecutor, singular bool, maybeMyFeed interface{}, mods queries.Applicator) error { + var slice []*MyFeed + var object *MyFeed + + if singular { + var ok bool + object, ok = maybeMyFeed.(*MyFeed) + if !ok { + object = new(MyFeed) + ok = queries.SetFromEmbeddedStruct(&object, &maybeMyFeed) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeMyFeed)) + } + } + } else { + s, ok := maybeMyFeed.(*[]*MyFeed) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeMyFeed) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeMyFeed)) + } + } + } + + args := make(map[interface{}]struct{}) + if singular { + if object.R == nil { + object.R = &myFeedR{} + } + args[object.UserID] = struct{}{} + + } else { + for _, obj := range slice { + if obj.R == nil { + obj.R = &myFeedR{} + } + + args[obj.UserID] = struct{}{} + + } + } + + if len(args) == 0 { + return nil + } + + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`profiles`), + qm.WhereIn(`profiles.id in ?`, argsSlice...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load Profile") + } + + var resultSlice []*Profile + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice Profile") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results of eager load for profiles") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for profiles") + } + + if len(profileAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + + if len(resultSlice) == 0 { + return nil + } + + if singular { + foreign := resultSlice[0] + object.R.User = foreign + if foreign.R == nil { + foreign.R = &profileR{} + } + foreign.R.UserMyFeeds = append(foreign.R.UserMyFeeds, object) + return nil + } + + for _, local := range slice { + for _, foreign := range resultSlice { + if local.UserID == foreign.ID { + local.R.User = foreign + if foreign.R == nil { + foreign.R = &profileR{} + } + foreign.R.UserMyFeeds = append(foreign.R.UserMyFeeds, local) + break + } + } + } + + return nil +} + +// SetFeed of the myFeed to the related item. +// Sets o.R.Feed to related. +// Adds o to related.R.MyFeeds. +func (o *MyFeed) SetFeed(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Feed) error { + var err error + if insert { + if err = related.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } + + updateQuery := fmt.Sprintf( + "UPDATE \"my_feeds\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"feed_id"}), + strmangle.WhereClause("\"", "\"", 2, myFeedPrimaryKeyColumns), + ) + values := []interface{}{related.ID, o.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update local table") + } + + o.FeedID = related.ID + if o.R == nil { + o.R = &myFeedR{ + Feed: related, + } + } else { + o.R.Feed = related + } + + if related.R == nil { + related.R = &feedR{ + MyFeeds: MyFeedSlice{o}, + } + } else { + related.R.MyFeeds = append(related.R.MyFeeds, o) + } + + return nil +} + +// SetMyFeedList of the myFeed to the related item. +// Sets o.R.MyFeedList to related. +// Adds o to related.R.MyFeeds. +func (o *MyFeed) SetMyFeedList(ctx context.Context, exec boil.ContextExecutor, insert bool, related *MyFeedList) error { + var err error + if insert { + if err = related.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } + + updateQuery := fmt.Sprintf( + "UPDATE \"my_feeds\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"my_feed_list_id"}), + strmangle.WhereClause("\"", "\"", 2, myFeedPrimaryKeyColumns), + ) + values := []interface{}{related.ID, o.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update local table") + } + + o.MyFeedListID = related.ID + if o.R == nil { + o.R = &myFeedR{ + MyFeedList: related, + } + } else { + o.R.MyFeedList = related + } + + if related.R == nil { + related.R = &myFeedListR{ + MyFeeds: MyFeedSlice{o}, + } + } else { + related.R.MyFeeds = append(related.R.MyFeeds, o) + } + + return nil +} + +// SetUser of the myFeed to the related item. +// Sets o.R.User to related. +// Adds o to related.R.UserMyFeeds. +func (o *MyFeed) SetUser(ctx context.Context, exec boil.ContextExecutor, insert bool, related *Profile) error { + var err error + if insert { + if err = related.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } + + updateQuery := fmt.Sprintf( + "UPDATE \"my_feeds\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}), + strmangle.WhereClause("\"", "\"", 2, myFeedPrimaryKeyColumns), + ) + values := []interface{}{related.ID, o.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update local table") + } + + o.UserID = related.ID + if o.R == nil { + o.R = &myFeedR{ + User: related, + } + } else { + o.R.User = related + } + + if related.R == nil { + related.R = &profileR{ + UserMyFeeds: MyFeedSlice{o}, + } + } else { + related.R.UserMyFeeds = append(related.R.UserMyFeeds, o) + } + + return nil +} + +// MyFeeds retrieves all the records using an executor. +func MyFeeds(mods ...qm.QueryMod) myFeedQuery { + mods = append(mods, qm.From("\"my_feeds\"")) + q := NewQuery(mods...) + if len(queries.GetSelect(q)) == 0 { + queries.SetSelect(q, []string{"\"my_feeds\".*"}) + } + + return myFeedQuery{q} +} + +// FindMyFeed retrieves a single record by ID with an executor. +// If selectCols is empty Find will return all columns. +func FindMyFeed(ctx context.Context, exec boil.ContextExecutor, iD string, selectCols ...string) (*MyFeed, error) { + myFeedObj := &MyFeed{} + + sel := "*" + if len(selectCols) > 0 { + sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") + } + query := fmt.Sprintf( + "select %s from \"my_feeds\" where \"id\"=$1", sel, + ) + + q := queries.Raw(query, iD) + + err := q.Bind(ctx, exec, myFeedObj) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return nil, sql.ErrNoRows + } + return nil, errors.Wrap(err, "entity: unable to select from my_feeds") + } + + if err = myFeedObj.doAfterSelectHooks(ctx, exec); err != nil { + return myFeedObj, err + } + + return myFeedObj, nil +} + +// Insert a single record using an executor. +// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. +func (o *MyFeed) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error { + if o == nil { + return errors.New("entity: no my_feeds provided for insertion") + } + + var err error + if !boil.TimestampsAreSkipped(ctx) { + currTime := time.Now().In(boil.GetLocation()) + + if o.CreatedAt.IsZero() { + o.CreatedAt = currTime + } + if o.UpdatedAt.IsZero() { + o.UpdatedAt = currTime + } + } + + if err := o.doBeforeInsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(myFeedColumnsWithDefault, o) + + key := makeCacheKey(columns, nzDefaults) + myFeedInsertCacheMut.RLock() + cache, cached := myFeedInsertCache[key] + myFeedInsertCacheMut.RUnlock() + + if !cached { + wl, returnColumns := columns.InsertColumnSet( + myFeedAllColumns, + myFeedColumnsWithDefault, + myFeedColumnsWithoutDefault, + nzDefaults, + ) + + cache.valueMapping, err = queries.BindMapping(myFeedType, myFeedMapping, wl) + if err != nil { + return err + } + cache.retMapping, err = queries.BindMapping(myFeedType, myFeedMapping, returnColumns) + if err != nil { + return err + } + if len(wl) != 0 { + cache.query = fmt.Sprintf("INSERT INTO \"my_feeds\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) + } else { + cache.query = "INSERT INTO \"my_feeds\" %sDEFAULT VALUES%s" + } + + var queryOutput, queryReturning string + + if len(cache.retMapping) != 0 { + queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\"")) + } + + cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning) + } + + value := reflect.Indirect(reflect.ValueOf(o)) + vals := queries.ValuesFromMapping(value, cache.valueMapping) + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) + } + + if len(cache.retMapping) != 0 { + err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...) + } else { + _, err = exec.ExecContext(ctx, cache.query, vals...) + } + + if err != nil { + return errors.Wrap(err, "entity: unable to insert into my_feeds") + } + + if !cached { + myFeedInsertCacheMut.Lock() + myFeedInsertCache[key] = cache + myFeedInsertCacheMut.Unlock() + } + + return o.doAfterInsertHooks(ctx, exec) +} + +// Update uses an executor to update the MyFeed. +// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates. +// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records. +func (o *MyFeed) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) { + if !boil.TimestampsAreSkipped(ctx) { + currTime := time.Now().In(boil.GetLocation()) + + o.UpdatedAt = currTime + } + + var err error + if err = o.doBeforeUpdateHooks(ctx, exec); err != nil { + return 0, err + } + key := makeCacheKey(columns, nil) + myFeedUpdateCacheMut.RLock() + cache, cached := myFeedUpdateCache[key] + myFeedUpdateCacheMut.RUnlock() + + if !cached { + wl := columns.UpdateColumnSet( + myFeedAllColumns, + myFeedPrimaryKeyColumns, + ) + + if !columns.IsWhitelist() { + wl = strmangle.SetComplement(wl, []string{"created_at"}) + } + if len(wl) == 0 { + return 0, errors.New("entity: unable to update my_feeds, could not build whitelist") + } + + cache.query = fmt.Sprintf("UPDATE \"my_feeds\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, wl), + strmangle.WhereClause("\"", "\"", len(wl)+1, myFeedPrimaryKeyColumns), + ) + cache.valueMapping, err = queries.BindMapping(myFeedType, myFeedMapping, append(wl, myFeedPrimaryKeyColumns...)) + if err != nil { + return 0, err + } + } + + values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping) + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, values) + } + var result sql.Result + result, err = exec.ExecContext(ctx, cache.query, values...) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to update my_feeds row") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: failed to get rows affected by update for my_feeds") + } + + if !cached { + myFeedUpdateCacheMut.Lock() + myFeedUpdateCache[key] = cache + myFeedUpdateCacheMut.Unlock() + } + + return rowsAff, o.doAfterUpdateHooks(ctx, exec) +} + +// UpdateAll updates all rows with the specified column values. +func (q myFeedQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) { + queries.SetUpdate(q.Query, cols) + + result, err := q.Query.ExecContext(ctx, exec) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to update all for my_feeds") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: unable to retrieve rows affected for my_feeds") + } + + return rowsAff, nil +} + +// UpdateAll updates all rows with the specified column values, using an executor. +func (o MyFeedSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) { + ln := int64(len(o)) + if ln == 0 { + return 0, nil + } + + if len(cols) == 0 { + return 0, errors.New("entity: update all requires at least one column argument") + } + + colNames := make([]string, len(cols)) + args := make([]interface{}, len(cols)) + + i := 0 + for name, value := range cols { + colNames[i] = name + args[i] = value + i++ + } + + // Append all of the primary key values for each column + for _, obj := range o { + pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), myFeedPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := fmt.Sprintf("UPDATE \"my_feeds\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, colNames), + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, myFeedPrimaryKeyColumns, len(o))) + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) + } + result, err := exec.ExecContext(ctx, sql, args...) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to update all in myFeed slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: unable to retrieve rows affected all in update all myFeed") + } + return rowsAff, nil +} + +// Upsert attempts an insert using an executor, and does an update or ignore on conflict. +// See boil.Columns documentation for how to properly use updateColumns and insertColumns. +func (o *MyFeed) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { + if o == nil { + return errors.New("entity: no my_feeds provided for upsert") + } + if !boil.TimestampsAreSkipped(ctx) { + currTime := time.Now().In(boil.GetLocation()) + + if o.CreatedAt.IsZero() { + o.CreatedAt = currTime + } + o.UpdatedAt = currTime + } + + if err := o.doBeforeUpsertHooks(ctx, exec); err != nil { + return err + } + + nzDefaults := queries.NonZeroDefaultSet(myFeedColumnsWithDefault, o) + + // Build cache key in-line uglily - mysql vs psql problems + buf := strmangle.GetBuffer() + if updateOnConflict { + buf.WriteByte('t') + } else { + buf.WriteByte('f') + } + buf.WriteByte('.') + for _, c := range conflictColumns { + buf.WriteString(c) + } + buf.WriteByte('.') + buf.WriteString(strconv.Itoa(updateColumns.Kind)) + for _, c := range updateColumns.Cols { + buf.WriteString(c) + } + buf.WriteByte('.') + buf.WriteString(strconv.Itoa(insertColumns.Kind)) + for _, c := range insertColumns.Cols { + buf.WriteString(c) + } + buf.WriteByte('.') + for _, c := range nzDefaults { + buf.WriteString(c) + } + key := buf.String() + strmangle.PutBuffer(buf) + + myFeedUpsertCacheMut.RLock() + cache, cached := myFeedUpsertCache[key] + myFeedUpsertCacheMut.RUnlock() + + var err error + + if !cached { + insert, _ := insertColumns.InsertColumnSet( + myFeedAllColumns, + myFeedColumnsWithDefault, + myFeedColumnsWithoutDefault, + nzDefaults, + ) + + update := updateColumns.UpdateColumnSet( + myFeedAllColumns, + myFeedPrimaryKeyColumns, + ) + + if updateOnConflict && len(update) == 0 { + return errors.New("entity: unable to upsert my_feeds, could not build update column list") + } + + ret := strmangle.SetComplement(myFeedAllColumns, strmangle.SetIntersect(insert, update)) + + conflict := conflictColumns + if len(conflict) == 0 && updateOnConflict && len(update) != 0 { + if len(myFeedPrimaryKeyColumns) == 0 { + return errors.New("entity: unable to upsert my_feeds, could not build conflict column list") + } + + conflict = make([]string, len(myFeedPrimaryKeyColumns)) + copy(conflict, myFeedPrimaryKeyColumns) + } + cache.query = buildUpsertQueryPostgres(dialect, "\"my_feeds\"", updateOnConflict, ret, update, conflict, insert, opts...) + + cache.valueMapping, err = queries.BindMapping(myFeedType, myFeedMapping, insert) + if err != nil { + return err + } + if len(ret) != 0 { + cache.retMapping, err = queries.BindMapping(myFeedType, myFeedMapping, ret) + if err != nil { + return err + } + } + } + + value := reflect.Indirect(reflect.ValueOf(o)) + vals := queries.ValuesFromMapping(value, cache.valueMapping) + var returns []interface{} + if len(cache.retMapping) != 0 { + returns = queries.PtrsFromMapping(value, cache.retMapping) + } + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, cache.query) + fmt.Fprintln(writer, vals) + } + if len(cache.retMapping) != 0 { + err = exec.QueryRowContext(ctx, cache.query, vals...).Scan(returns...) + if errors.Is(err, sql.ErrNoRows) { + err = nil // Postgres doesn't return anything when there's no update + } + } else { + _, err = exec.ExecContext(ctx, cache.query, vals...) + } + if err != nil { + return errors.Wrap(err, "entity: unable to upsert my_feeds") + } + + if !cached { + myFeedUpsertCacheMut.Lock() + myFeedUpsertCache[key] = cache + myFeedUpsertCacheMut.Unlock() + } + + return o.doAfterUpsertHooks(ctx, exec) +} + +// Delete deletes a single MyFeed record with an executor. +// Delete will match against the primary key column to find the record to delete. +func (o *MyFeed) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if o == nil { + return 0, errors.New("entity: no MyFeed provided for delete") + } + + if err := o.doBeforeDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), myFeedPrimaryKeyMapping) + sql := "DELETE FROM \"my_feeds\" WHERE \"id\"=$1" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args...) + } + result, err := exec.ExecContext(ctx, sql, args...) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to delete from my_feeds") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: failed to get rows affected by delete for my_feeds") + } + + if err := o.doAfterDeleteHooks(ctx, exec); err != nil { + return 0, err + } + + return rowsAff, nil +} + +// DeleteAll deletes all matching rows. +func (q myFeedQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if q.Query == nil { + return 0, errors.New("entity: no myFeedQuery provided for delete all") + } + + queries.SetDelete(q.Query) + + result, err := q.Query.ExecContext(ctx, exec) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to delete all from my_feeds") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: failed to get rows affected by deleteall for my_feeds") + } + + return rowsAff, nil +} + +// DeleteAll deletes all rows in the slice, using an executor. +func (o MyFeedSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { + if len(o) == 0 { + return 0, nil + } + + if len(myFeedBeforeDeleteHooks) != 0 { + for _, obj := range o { + if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil { + return 0, err + } + } + } + + var args []interface{} + for _, obj := range o { + pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), myFeedPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "DELETE FROM \"my_feeds\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, myFeedPrimaryKeyColumns, len(o)) + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, args) + } + result, err := exec.ExecContext(ctx, sql, args...) + if err != nil { + return 0, errors.Wrap(err, "entity: unable to delete all from myFeed slice") + } + + rowsAff, err := result.RowsAffected() + if err != nil { + return 0, errors.Wrap(err, "entity: failed to get rows affected by deleteall for my_feeds") + } + + if len(myFeedAfterDeleteHooks) != 0 { + for _, obj := range o { + if err := obj.doAfterDeleteHooks(ctx, exec); err != nil { + return 0, err + } + } + } + + return rowsAff, nil +} + +// Reload refetches the object from the database +// using the primary keys with an executor. +func (o *MyFeed) Reload(ctx context.Context, exec boil.ContextExecutor) error { + ret, err := FindMyFeed(ctx, exec, o.ID) + if err != nil { + return err + } + + *o = *ret + return nil +} + +// ReloadAll refetches every row with matching primary key column values +// and overwrites the original object slice with the newly updated slice. +func (o *MyFeedSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error { + if o == nil || len(*o) == 0 { + return nil + } + + slice := MyFeedSlice{} + var args []interface{} + for _, obj := range *o { + pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), myFeedPrimaryKeyMapping) + args = append(args, pkeyArgs...) + } + + sql := "SELECT \"my_feeds\".* FROM \"my_feeds\" WHERE " + + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, myFeedPrimaryKeyColumns, len(*o)) + + q := queries.Raw(sql, args...) + + err := q.Bind(ctx, exec, &slice) + if err != nil { + return errors.Wrap(err, "entity: unable to reload all in MyFeedSlice") + } + + *o = slice + + return nil +} + +// MyFeedExists checks if the MyFeed row exists. +func MyFeedExists(ctx context.Context, exec boil.ContextExecutor, iD string) (bool, error) { + var exists bool + sql := "select exists(select 1 from \"my_feeds\" where \"id\"=$1 limit 1)" + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, sql) + fmt.Fprintln(writer, iD) + } + row := exec.QueryRowContext(ctx, sql, iD) + + err := row.Scan(&exists) + if err != nil { + return false, errors.Wrap(err, "entity: unable to check if my_feeds exists") + } + + return exists, nil +} + +// Exists checks if the MyFeed row exists. +func (o *MyFeed) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { + return MyFeedExists(ctx, exec, o.ID) +} diff --git a/batch-service/entity/profiles.go b/batch-service/entity/profiles.go index c941af03..e054d612 100644 --- a/batch-service/entity/profiles.go +++ b/batch-service/entity/profiles.go @@ -115,14 +115,20 @@ var ProfileWhere = struct { // ProfileRels is where relationship names are stored. var ProfileRels = struct { - UserBookmarks string + UserBookmarks string + UserMyFeedLists string + UserMyFeeds string }{ - UserBookmarks: "UserBookmarks", + UserBookmarks: "UserBookmarks", + UserMyFeedLists: "UserMyFeedLists", + UserMyFeeds: "UserMyFeeds", } // profileR is where relationships are stored. type profileR struct { - UserBookmarks BookmarkSlice `boil:"UserBookmarks" json:"UserBookmarks" toml:"UserBookmarks" yaml:"UserBookmarks"` + UserBookmarks BookmarkSlice `boil:"UserBookmarks" json:"UserBookmarks" toml:"UserBookmarks" yaml:"UserBookmarks"` + UserMyFeedLists MyFeedListSlice `boil:"UserMyFeedLists" json:"UserMyFeedLists" toml:"UserMyFeedLists" yaml:"UserMyFeedLists"` + UserMyFeeds MyFeedSlice `boil:"UserMyFeeds" json:"UserMyFeeds" toml:"UserMyFeeds" yaml:"UserMyFeeds"` } // NewStruct creates a new relationship struct @@ -137,6 +143,20 @@ func (r *profileR) GetUserBookmarks() BookmarkSlice { return r.UserBookmarks } +func (r *profileR) GetUserMyFeedLists() MyFeedListSlice { + if r == nil { + return nil + } + return r.UserMyFeedLists +} + +func (r *profileR) GetUserMyFeeds() MyFeedSlice { + if r == nil { + return nil + } + return r.UserMyFeeds +} + // profileL is where Load methods for each relationship are stored. type profileL struct{} @@ -467,6 +487,34 @@ func (o *Profile) UserBookmarks(mods ...qm.QueryMod) bookmarkQuery { return Bookmarks(queryMods...) } +// UserMyFeedLists retrieves all the my_feed_list's MyFeedLists with an executor via user_id column. +func (o *Profile) UserMyFeedLists(mods ...qm.QueryMod) myFeedListQuery { + var queryMods []qm.QueryMod + if len(mods) != 0 { + queryMods = append(queryMods, mods...) + } + + queryMods = append(queryMods, + qm.Where("\"my_feed_lists\".\"user_id\"=?", o.ID), + ) + + return MyFeedLists(queryMods...) +} + +// UserMyFeeds retrieves all the my_feed's MyFeeds with an executor via user_id column. +func (o *Profile) UserMyFeeds(mods ...qm.QueryMod) myFeedQuery { + var queryMods []qm.QueryMod + if len(mods) != 0 { + queryMods = append(queryMods, mods...) + } + + queryMods = append(queryMods, + qm.Where("\"my_feeds\".\"user_id\"=?", o.ID), + ) + + return MyFeeds(queryMods...) +} + // LoadUserBookmarks allows an eager lookup of values, cached into the // loaded structs of the objects. This is for a 1-M or N-M relationship. func (profileL) LoadUserBookmarks(ctx context.Context, e boil.ContextExecutor, singular bool, maybeProfile interface{}, mods queries.Applicator) error { @@ -580,6 +628,232 @@ func (profileL) LoadUserBookmarks(ctx context.Context, e boil.ContextExecutor, s return nil } +// LoadUserMyFeedLists allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for a 1-M or N-M relationship. +func (profileL) LoadUserMyFeedLists(ctx context.Context, e boil.ContextExecutor, singular bool, maybeProfile interface{}, mods queries.Applicator) error { + var slice []*Profile + var object *Profile + + if singular { + var ok bool + object, ok = maybeProfile.(*Profile) + if !ok { + object = new(Profile) + ok = queries.SetFromEmbeddedStruct(&object, &maybeProfile) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeProfile)) + } + } + } else { + s, ok := maybeProfile.(*[]*Profile) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeProfile) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeProfile)) + } + } + } + + args := make(map[interface{}]struct{}) + if singular { + if object.R == nil { + object.R = &profileR{} + } + args[object.ID] = struct{}{} + } else { + for _, obj := range slice { + if obj.R == nil { + obj.R = &profileR{} + } + args[obj.ID] = struct{}{} + } + } + + if len(args) == 0 { + return nil + } + + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`my_feed_lists`), + qm.WhereIn(`my_feed_lists.user_id in ?`, argsSlice...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load my_feed_lists") + } + + var resultSlice []*MyFeedList + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice my_feed_lists") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results in eager load on my_feed_lists") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for my_feed_lists") + } + + if len(myFeedListAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + if singular { + object.R.UserMyFeedLists = resultSlice + for _, foreign := range resultSlice { + if foreign.R == nil { + foreign.R = &myFeedListR{} + } + foreign.R.User = object + } + return nil + } + + for _, foreign := range resultSlice { + for _, local := range slice { + if local.ID == foreign.UserID { + local.R.UserMyFeedLists = append(local.R.UserMyFeedLists, foreign) + if foreign.R == nil { + foreign.R = &myFeedListR{} + } + foreign.R.User = local + break + } + } + } + + return nil +} + +// LoadUserMyFeeds allows an eager lookup of values, cached into the +// loaded structs of the objects. This is for a 1-M or N-M relationship. +func (profileL) LoadUserMyFeeds(ctx context.Context, e boil.ContextExecutor, singular bool, maybeProfile interface{}, mods queries.Applicator) error { + var slice []*Profile + var object *Profile + + if singular { + var ok bool + object, ok = maybeProfile.(*Profile) + if !ok { + object = new(Profile) + ok = queries.SetFromEmbeddedStruct(&object, &maybeProfile) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybeProfile)) + } + } + } else { + s, ok := maybeProfile.(*[]*Profile) + if ok { + slice = *s + } else { + ok = queries.SetFromEmbeddedStruct(&slice, maybeProfile) + if !ok { + return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybeProfile)) + } + } + } + + args := make(map[interface{}]struct{}) + if singular { + if object.R == nil { + object.R = &profileR{} + } + args[object.ID] = struct{}{} + } else { + for _, obj := range slice { + if obj.R == nil { + obj.R = &profileR{} + } + args[obj.ID] = struct{}{} + } + } + + if len(args) == 0 { + return nil + } + + argsSlice := make([]interface{}, len(args)) + i := 0 + for arg := range args { + argsSlice[i] = arg + i++ + } + + query := NewQuery( + qm.From(`my_feeds`), + qm.WhereIn(`my_feeds.user_id in ?`, argsSlice...), + ) + if mods != nil { + mods.Apply(query) + } + + results, err := query.QueryContext(ctx, e) + if err != nil { + return errors.Wrap(err, "failed to eager load my_feeds") + } + + var resultSlice []*MyFeed + if err = queries.Bind(results, &resultSlice); err != nil { + return errors.Wrap(err, "failed to bind eager loaded slice my_feeds") + } + + if err = results.Close(); err != nil { + return errors.Wrap(err, "failed to close results in eager load on my_feeds") + } + if err = results.Err(); err != nil { + return errors.Wrap(err, "error occurred during iteration of eager loaded relations for my_feeds") + } + + if len(myFeedAfterSelectHooks) != 0 { + for _, obj := range resultSlice { + if err := obj.doAfterSelectHooks(ctx, e); err != nil { + return err + } + } + } + if singular { + object.R.UserMyFeeds = resultSlice + for _, foreign := range resultSlice { + if foreign.R == nil { + foreign.R = &myFeedR{} + } + foreign.R.User = object + } + return nil + } + + for _, foreign := range resultSlice { + for _, local := range slice { + if local.ID == foreign.UserID { + local.R.UserMyFeeds = append(local.R.UserMyFeeds, foreign) + if foreign.R == nil { + foreign.R = &myFeedR{} + } + foreign.R.User = local + break + } + } + } + + return nil +} + // AddUserBookmarks adds the given related objects to the existing relationships // of the profile, optionally inserting them as new records. // Appends related to o.R.UserBookmarks. @@ -633,6 +907,112 @@ func (o *Profile) AddUserBookmarks(ctx context.Context, exec boil.ContextExecuto return nil } +// AddUserMyFeedLists adds the given related objects to the existing relationships +// of the profile, optionally inserting them as new records. +// Appends related to o.R.UserMyFeedLists. +// Sets related.R.User appropriately. +func (o *Profile) AddUserMyFeedLists(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*MyFeedList) error { + var err error + for _, rel := range related { + if insert { + rel.UserID = o.ID + if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } else { + updateQuery := fmt.Sprintf( + "UPDATE \"my_feed_lists\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}), + strmangle.WhereClause("\"", "\"", 2, myFeedListPrimaryKeyColumns), + ) + values := []interface{}{o.ID, rel.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update foreign table") + } + + rel.UserID = o.ID + } + } + + if o.R == nil { + o.R = &profileR{ + UserMyFeedLists: related, + } + } else { + o.R.UserMyFeedLists = append(o.R.UserMyFeedLists, related...) + } + + for _, rel := range related { + if rel.R == nil { + rel.R = &myFeedListR{ + User: o, + } + } else { + rel.R.User = o + } + } + return nil +} + +// AddUserMyFeeds adds the given related objects to the existing relationships +// of the profile, optionally inserting them as new records. +// Appends related to o.R.UserMyFeeds. +// Sets related.R.User appropriately. +func (o *Profile) AddUserMyFeeds(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*MyFeed) error { + var err error + for _, rel := range related { + if insert { + rel.UserID = o.ID + if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { + return errors.Wrap(err, "failed to insert into foreign table") + } + } else { + updateQuery := fmt.Sprintf( + "UPDATE \"my_feeds\" SET %s WHERE %s", + strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}), + strmangle.WhereClause("\"", "\"", 2, myFeedPrimaryKeyColumns), + ) + values := []interface{}{o.ID, rel.ID} + + if boil.IsDebug(ctx) { + writer := boil.DebugWriterFrom(ctx) + fmt.Fprintln(writer, updateQuery) + fmt.Fprintln(writer, values) + } + if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil { + return errors.Wrap(err, "failed to update foreign table") + } + + rel.UserID = o.ID + } + } + + if o.R == nil { + o.R = &profileR{ + UserMyFeeds: related, + } + } else { + o.R.UserMyFeeds = append(o.R.UserMyFeeds, related...) + } + + for _, rel := range related { + if rel.R == nil { + rel.R = &myFeedR{ + User: o, + } + } else { + rel.R.User = o + } + } + return nil +} + // Profiles retrieves all the records using an executor. func Profiles(mods ...qm.QueryMod) profileQuery { mods = append(mods, qm.From("\"profiles\"")) diff --git a/supabase/er.dio b/supabase/er.dio index 519a1262..f1e797f9 100644 --- a/supabase/er.dio +++ b/supabase/er.dio @@ -1,6 +1,6 @@ - + @@ -334,15 +334,15 @@ - + - + - + @@ -519,15 +519,15 @@ - + - + - + @@ -545,80 +545,80 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -941,7 +941,7 @@ - + @@ -956,9 +956,22 @@ - + + + + + + + + + + + + + + @@ -970,7 +983,7 @@ - + @@ -983,7 +996,7 @@ - + @@ -996,7 +1009,7 @@ - + @@ -1009,7 +1022,7 @@ - + @@ -1384,7 +1397,7 @@ - + @@ -1448,15 +1461,15 @@ - + - + - + @@ -1837,7 +1850,7 @@ - + diff --git a/supabase/migrations/20240418143923_create_my_feed_lists.sql b/supabase/migrations/20240418143923_create_my_feed_lists.sql new file mode 100644 index 00000000..d9a3574c --- /dev/null +++ b/supabase/migrations/20240418143923_create_my_feed_lists.sql @@ -0,0 +1,17 @@ +CREATE FUNCTION set_my_feed_lists_update_time() + RETURNS TRIGGER AS $$ BEGIN NEW.updated_at = NOW(); RETURN NEW; END; $$ LANGUAGE plpgsql; + +CREATE TABLE my_feed_lists +( + id uuid NOT NULL DEFAULT uuid_generate_v4(), + user_id uuid NOT NULL, + title VARCHAR(255) NOT NULL, + description TEXT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (id), + + CONSTRAINT fk_my_feed_lists_user_id FOREIGN KEY (user_id) REFERENCES profiles(id) ON UPDATE RESTRICT ON DELETE CASCADE +); + +CREATE TRIGGER my_feed_lists_update_tri BEFORE UPDATE ON my_feed_lists FOR EACH ROW EXECUTE PROCEDURE set_my_feed_lists_update_time(); \ No newline at end of file diff --git a/supabase/migrations/20240418144221_create_my_feeds.sql b/supabase/migrations/20240418144221_create_my_feeds.sql new file mode 100644 index 00000000..32d60505 --- /dev/null +++ b/supabase/migrations/20240418144221_create_my_feeds.sql @@ -0,0 +1,19 @@ +CREATE FUNCTION set_my_feeds_update_time() + RETURNS TRIGGER AS $$ BEGIN NEW.updated_at = NOW(); RETURN NEW; END; $$ LANGUAGE plpgsql; + +CREATE TABLE my_feeds +( + id uuid NOT NULL DEFAULT uuid_generate_v4(), + user_id uuid NOT NULL, + my_feed_list_id uuid NOT NULL, + feed_id uuid NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (id), + + CONSTRAINT fk_my_feeds_user_id FOREIGN KEY (user_id) REFERENCES profiles(id) ON UPDATE RESTRICT ON DELETE CASCADE, + CONSTRAINT fk_my_feeds_my_feed_list_id FOREIGN KEY (my_feed_list_id) REFERENCES my_feed_lists(id) ON UPDATE RESTRICT ON DELETE CASCADE, + CONSTRAINT fk_my_feeds_feed_id FOREIGN KEY (feed_id) REFERENCES feeds(id) ON UPDATE RESTRICT ON DELETE CASCADE +); + +CREATE TRIGGER my_feeds_update_tri BEFORE UPDATE ON my_feeds FOR EACH ROW EXECUTE PROCEDURE set_my_feeds_update_time(); \ No newline at end of file diff --git a/web/client/prisma/schema.prisma b/web/client/prisma/schema.prisma index 6e0cac51..a3116429 100644 --- a/web/client/prisma/schema.prisma +++ b/web/client/prisma/schema.prisma @@ -13,6 +13,38 @@ datasource db { url = env("DATABASE_URL") } +model MyFeed { + id String @id @default(uuid()) + userId String @map("user_id") + myFeedListId String @map("my_feed_list_id") + feedId String @map("feed_id") + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + + profile Profile @relation(fields: [userId], references: [id], onDelete: Cascade) + myFeedList MyFeedList @relation(fields: [myFeedListId], references: [id], onDelete: Cascade) + feed Feed @relation(fields: [feedId], references: [id], onDelete: Cascade) + + @@map("my_feeds") + + +} + +model MyFeedList { + id String @id @default(uuid()) + userId String @map("user_id") + title String + description String + createdAt DateTime @default(now()) @map("created_at") + updatedAt DateTime @updatedAt @map("updated_at") + myFeeds MyFeed[] + + profile Profile @relation(fields: [userId], references: [id], onDelete: Cascade) + + @@map("my_feed_lists") + +} + model Bookmark { id String @id @default(uuid()) userId String @map("user_id") @@ -51,7 +83,9 @@ model Profile { createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime @updatedAt @map("updated_at") deletedAt DateTime? @map("deleted_at") - bookmarks Bookmark[] + bookmarks Bookmark[] + myFeedLists MyFeedList[] + myFeeds MyFeed[] @@map("profiles") } @@ -105,6 +139,7 @@ model Feed { platform Platform @relation(fields: [platformId], references: [id], onDelete: Cascade) category Category @relation(fields: [categoryId], references: [id], onDelete: Cascade) + myFeeds MyFeed[] feedArticleRelatoins FeedArticleRelation[]