// Code generated by SQLBoiler 4.16.1 (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 models 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" ) // Post is an object representing the database table. type Post struct { ID int `boil:"id" json:"id" toml:"id" yaml:"id"` Title string `boil:"title" json:"title" toml:"title" yaml:"title"` Description null.String `boil:"description" json:"description,omitempty" toml:"description" yaml:"description,omitempty"` URL null.String `boil:"url" json:"url,omitempty" toml:"url" yaml:"url,omitempty"` UserID int `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"` State null.String `boil:"state" json:"state,omitempty" toml:"state" yaml:"state,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 *postR `boil:"-" json:"-" toml:"-" yaml:"-"` L postL `boil:"-" json:"-" toml:"-" yaml:"-"` } var PostColumns = struct { ID string Title string Description string URL string UserID string State string CreatedAt string UpdatedAt string }{ ID: "id", Title: "title", Description: "description", URL: "url", UserID: "user_id", State: "state", CreatedAt: "created_at", UpdatedAt: "updated_at", } var PostTableColumns = struct { ID string Title string Description string URL string UserID string State string CreatedAt string UpdatedAt string }{ ID: "posts.id", Title: "posts.title", Description: "posts.description", URL: "posts.url", UserID: "posts.user_id", State: "posts.state", CreatedAt: "posts.created_at", UpdatedAt: "posts.updated_at", } // Generated where var PostWhere = struct { ID whereHelperint Title whereHelperstring Description whereHelpernull_String URL whereHelpernull_String UserID whereHelperint State whereHelpernull_String CreatedAt whereHelpertime_Time UpdatedAt whereHelpertime_Time }{ ID: whereHelperint{field: "\"posts\".\"id\""}, Title: whereHelperstring{field: "\"posts\".\"title\""}, Description: whereHelpernull_String{field: "\"posts\".\"description\""}, URL: whereHelpernull_String{field: "\"posts\".\"url\""}, UserID: whereHelperint{field: "\"posts\".\"user_id\""}, State: whereHelpernull_String{field: "\"posts\".\"state\""}, CreatedAt: whereHelpertime_Time{field: "\"posts\".\"created_at\""}, UpdatedAt: whereHelpertime_Time{field: "\"posts\".\"updated_at\""}, } // PostRels is where relationship names are stored. var PostRels = struct { User string Comments string Tags string Votes string }{ User: "User", Comments: "Comments", Tags: "Tags", Votes: "Votes", } // postR is where relationships are stored. type postR struct { User *User `boil:"User" json:"User" toml:"User" yaml:"User"` Comments CommentSlice `boil:"Comments" json:"Comments" toml:"Comments" yaml:"Comments"` Tags TagSlice `boil:"Tags" json:"Tags" toml:"Tags" yaml:"Tags"` Votes VoteSlice `boil:"Votes" json:"Votes" toml:"Votes" yaml:"Votes"` } // NewStruct creates a new relationship struct func (*postR) NewStruct() *postR { return &postR{} } func (r *postR) GetUser() *User { if r == nil { return nil } return r.User } func (r *postR) GetComments() CommentSlice { if r == nil { return nil } return r.Comments } func (r *postR) GetTags() TagSlice { if r == nil { return nil } return r.Tags } func (r *postR) GetVotes() VoteSlice { if r == nil { return nil } return r.Votes } // postL is where Load methods for each relationship are stored. type postL struct{} var ( postAllColumns = []string{"id", "title", "description", "url", "user_id", "state", "created_at", "updated_at"} postColumnsWithoutDefault = []string{"title", "user_id"} postColumnsWithDefault = []string{"id", "description", "url", "state", "created_at", "updated_at"} postPrimaryKeyColumns = []string{"id"} postGeneratedColumns = []string{} ) type ( // PostSlice is an alias for a slice of pointers to Post. // This should almost always be used instead of []Post. PostSlice []*Post // PostHook is the signature for custom Post hook methods PostHook func(context.Context, boil.ContextExecutor, *Post) error postQuery struct { *queries.Query } ) // Cache for insert, update and upsert var ( postType = reflect.TypeOf(&Post{}) postMapping = queries.MakeStructMapping(postType) postPrimaryKeyMapping, _ = queries.BindMapping(postType, postMapping, postPrimaryKeyColumns) postInsertCacheMut sync.RWMutex postInsertCache = make(map[string]insertCache) postUpdateCacheMut sync.RWMutex postUpdateCache = make(map[string]updateCache) postUpsertCacheMut sync.RWMutex postUpsertCache = 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 postAfterSelectMu sync.Mutex var postAfterSelectHooks []PostHook var postBeforeInsertMu sync.Mutex var postBeforeInsertHooks []PostHook var postAfterInsertMu sync.Mutex var postAfterInsertHooks []PostHook var postBeforeUpdateMu sync.Mutex var postBeforeUpdateHooks []PostHook var postAfterUpdateMu sync.Mutex var postAfterUpdateHooks []PostHook var postBeforeDeleteMu sync.Mutex var postBeforeDeleteHooks []PostHook var postAfterDeleteMu sync.Mutex var postAfterDeleteHooks []PostHook var postBeforeUpsertMu sync.Mutex var postBeforeUpsertHooks []PostHook var postAfterUpsertMu sync.Mutex var postAfterUpsertHooks []PostHook // doAfterSelectHooks executes all "after Select" hooks. func (o *Post) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { if boil.HooksAreSkipped(ctx) { return nil } for _, hook := range postAfterSelectHooks { if err := hook(ctx, exec, o); err != nil { return err } } return nil } // doBeforeInsertHooks executes all "before insert" hooks. func (o *Post) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { if boil.HooksAreSkipped(ctx) { return nil } for _, hook := range postBeforeInsertHooks { if err := hook(ctx, exec, o); err != nil { return err } } return nil } // doAfterInsertHooks executes all "after Insert" hooks. func (o *Post) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { if boil.HooksAreSkipped(ctx) { return nil } for _, hook := range postAfterInsertHooks { if err := hook(ctx, exec, o); err != nil { return err } } return nil } // doBeforeUpdateHooks executes all "before Update" hooks. func (o *Post) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { if boil.HooksAreSkipped(ctx) { return nil } for _, hook := range postBeforeUpdateHooks { if err := hook(ctx, exec, o); err != nil { return err } } return nil } // doAfterUpdateHooks executes all "after Update" hooks. func (o *Post) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { if boil.HooksAreSkipped(ctx) { return nil } for _, hook := range postAfterUpdateHooks { if err := hook(ctx, exec, o); err != nil { return err } } return nil } // doBeforeDeleteHooks executes all "before Delete" hooks. func (o *Post) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { if boil.HooksAreSkipped(ctx) { return nil } for _, hook := range postBeforeDeleteHooks { if err := hook(ctx, exec, o); err != nil { return err } } return nil } // doAfterDeleteHooks executes all "after Delete" hooks. func (o *Post) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { if boil.HooksAreSkipped(ctx) { return nil } for _, hook := range postAfterDeleteHooks { if err := hook(ctx, exec, o); err != nil { return err } } return nil } // doBeforeUpsertHooks executes all "before Upsert" hooks. func (o *Post) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { if boil.HooksAreSkipped(ctx) { return nil } for _, hook := range postBeforeUpsertHooks { if err := hook(ctx, exec, o); err != nil { return err } } return nil } // doAfterUpsertHooks executes all "after Upsert" hooks. func (o *Post) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) { if boil.HooksAreSkipped(ctx) { return nil } for _, hook := range postAfterUpsertHooks { if err := hook(ctx, exec, o); err != nil { return err } } return nil } // AddPostHook registers your hook function for all future operations. func AddPostHook(hookPoint boil.HookPoint, postHook PostHook) { switch hookPoint { case boil.AfterSelectHook: postAfterSelectMu.Lock() postAfterSelectHooks = append(postAfterSelectHooks, postHook) postAfterSelectMu.Unlock() case boil.BeforeInsertHook: postBeforeInsertMu.Lock() postBeforeInsertHooks = append(postBeforeInsertHooks, postHook) postBeforeInsertMu.Unlock() case boil.AfterInsertHook: postAfterInsertMu.Lock() postAfterInsertHooks = append(postAfterInsertHooks, postHook) postAfterInsertMu.Unlock() case boil.BeforeUpdateHook: postBeforeUpdateMu.Lock() postBeforeUpdateHooks = append(postBeforeUpdateHooks, postHook) postBeforeUpdateMu.Unlock() case boil.AfterUpdateHook: postAfterUpdateMu.Lock() postAfterUpdateHooks = append(postAfterUpdateHooks, postHook) postAfterUpdateMu.Unlock() case boil.BeforeDeleteHook: postBeforeDeleteMu.Lock() postBeforeDeleteHooks = append(postBeforeDeleteHooks, postHook) postBeforeDeleteMu.Unlock() case boil.AfterDeleteHook: postAfterDeleteMu.Lock() postAfterDeleteHooks = append(postAfterDeleteHooks, postHook) postAfterDeleteMu.Unlock() case boil.BeforeUpsertHook: postBeforeUpsertMu.Lock() postBeforeUpsertHooks = append(postBeforeUpsertHooks, postHook) postBeforeUpsertMu.Unlock() case boil.AfterUpsertHook: postAfterUpsertMu.Lock() postAfterUpsertHooks = append(postAfterUpsertHooks, postHook) postAfterUpsertMu.Unlock() } } // One returns a single post record from the query. func (q postQuery) One(ctx context.Context, exec boil.ContextExecutor) (*Post, error) { o := &Post{} 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, "models: failed to execute a one query for posts") } if err := o.doAfterSelectHooks(ctx, exec); err != nil { return o, err } return o, nil } // All returns all Post records from the query. func (q postQuery) All(ctx context.Context, exec boil.ContextExecutor) (PostSlice, error) { var o []*Post err := q.Bind(ctx, exec, &o) if err != nil { return nil, errors.Wrap(err, "models: failed to assign all query results to Post slice") } if len(postAfterSelectHooks) != 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 Post records in the query. func (q postQuery) 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, "models: failed to count posts rows") } return count, nil } // Exists checks if the row exists in the table. func (q postQuery) 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, "models: failed to check if posts exists") } return count > 0, nil } // User pointed to by the foreign key. func (o *Post) User(mods ...qm.QueryMod) userQuery { queryMods := []qm.QueryMod{ qm.Where("\"id\" = ?", o.UserID), } queryMods = append(queryMods, mods...) return Users(queryMods...) } // Comments retrieves all the comment's Comments with an executor. func (o *Post) Comments(mods ...qm.QueryMod) commentQuery { var queryMods []qm.QueryMod if len(mods) != 0 { queryMods = append(queryMods, mods...) } queryMods = append(queryMods, qm.Where("\"comments\".\"post_id\"=?", o.ID), ) return Comments(queryMods...) } // Tags retrieves all the tag's Tags with an executor. func (o *Post) Tags(mods ...qm.QueryMod) tagQuery { var queryMods []qm.QueryMod if len(mods) != 0 { queryMods = append(queryMods, mods...) } queryMods = append(queryMods, qm.InnerJoin("\"post_tags\" on \"tags\".\"id\" = \"post_tags\".\"tag_id\""), qm.Where("\"post_tags\".\"post_id\"=?", o.ID), ) return Tags(queryMods...) } // Votes retrieves all the vote's Votes with an executor. func (o *Post) Votes(mods ...qm.QueryMod) voteQuery { var queryMods []qm.QueryMod if len(mods) != 0 { queryMods = append(queryMods, mods...) } queryMods = append(queryMods, qm.Where("\"votes\".\"post_id\"=?", o.ID), ) return Votes(queryMods...) } // LoadUser allows an eager lookup of values, cached into the // loaded structs of the objects. This is for an N-1 relationship. func (postL) LoadUser(ctx context.Context, e boil.ContextExecutor, singular bool, maybePost interface{}, mods queries.Applicator) error { var slice []*Post var object *Post if singular { var ok bool object, ok = maybePost.(*Post) if !ok { object = new(Post) ok = queries.SetFromEmbeddedStruct(&object, &maybePost) if !ok { return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybePost)) } } } else { s, ok := maybePost.(*[]*Post) if ok { slice = *s } else { ok = queries.SetFromEmbeddedStruct(&slice, maybePost) if !ok { return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybePost)) } } } args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &postR{} } args[object.UserID] = struct{}{} } else { for _, obj := range slice { if obj.R == nil { obj.R = &postR{} } 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(`users`), qm.WhereIn(`users.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 User") } var resultSlice []*User if err = queries.Bind(results, &resultSlice); err != nil { return errors.Wrap(err, "failed to bind eager loaded slice User") } if err = results.Close(); err != nil { return errors.Wrap(err, "failed to close results of eager load for users") } if err = results.Err(); err != nil { return errors.Wrap(err, "error occurred during iteration of eager loaded relations for users") } if len(userAfterSelectHooks) != 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 = &userR{} } foreign.R.Posts = append(foreign.R.Posts, 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 = &userR{} } foreign.R.Posts = append(foreign.R.Posts, local) break } } } return nil } // LoadComments 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 (postL) LoadComments(ctx context.Context, e boil.ContextExecutor, singular bool, maybePost interface{}, mods queries.Applicator) error { var slice []*Post var object *Post if singular { var ok bool object, ok = maybePost.(*Post) if !ok { object = new(Post) ok = queries.SetFromEmbeddedStruct(&object, &maybePost) if !ok { return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybePost)) } } } else { s, ok := maybePost.(*[]*Post) if ok { slice = *s } else { ok = queries.SetFromEmbeddedStruct(&slice, maybePost) if !ok { return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybePost)) } } } args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &postR{} } args[object.ID] = struct{}{} } else { for _, obj := range slice { if obj.R == nil { obj.R = &postR{} } 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(`comments`), qm.WhereIn(`comments.post_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 comments") } var resultSlice []*Comment if err = queries.Bind(results, &resultSlice); err != nil { return errors.Wrap(err, "failed to bind eager loaded slice comments") } if err = results.Close(); err != nil { return errors.Wrap(err, "failed to close results in eager load on comments") } if err = results.Err(); err != nil { return errors.Wrap(err, "error occurred during iteration of eager loaded relations for comments") } if len(commentAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err } } } if singular { object.R.Comments = resultSlice for _, foreign := range resultSlice { if foreign.R == nil { foreign.R = &commentR{} } foreign.R.Post = object } return nil } for _, foreign := range resultSlice { for _, local := range slice { if local.ID == foreign.PostID { local.R.Comments = append(local.R.Comments, foreign) if foreign.R == nil { foreign.R = &commentR{} } foreign.R.Post = local break } } } return nil } // LoadTags 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 (postL) LoadTags(ctx context.Context, e boil.ContextExecutor, singular bool, maybePost interface{}, mods queries.Applicator) error { var slice []*Post var object *Post if singular { var ok bool object, ok = maybePost.(*Post) if !ok { object = new(Post) ok = queries.SetFromEmbeddedStruct(&object, &maybePost) if !ok { return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybePost)) } } } else { s, ok := maybePost.(*[]*Post) if ok { slice = *s } else { ok = queries.SetFromEmbeddedStruct(&slice, maybePost) if !ok { return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybePost)) } } } args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &postR{} } args[object.ID] = struct{}{} } else { for _, obj := range slice { if obj.R == nil { obj.R = &postR{} } 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.Select("\"tags\".\"id\", \"tags\".\"tag\", \"tags\".\"description\", \"tags\".\"user_id\", \"tags\".\"created_at\", \"tags\".\"updated_at\", \"a\".\"post_id\""), qm.From("\"tags\""), qm.InnerJoin("\"post_tags\" as \"a\" on \"tags\".\"id\" = \"a\".\"tag_id\""), qm.WhereIn("\"a\".\"post_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 tags") } var resultSlice []*Tag var localJoinCols []int for results.Next() { one := new(Tag) var localJoinCol int err = results.Scan(&one.ID, &one.Tag, &one.Description, &one.UserID, &one.CreatedAt, &one.UpdatedAt, &localJoinCol) if err != nil { return errors.Wrap(err, "failed to scan eager loaded results for tags") } if err = results.Err(); err != nil { return errors.Wrap(err, "failed to plebian-bind eager loaded slice tags") } resultSlice = append(resultSlice, one) localJoinCols = append(localJoinCols, localJoinCol) } if err = results.Close(); err != nil { return errors.Wrap(err, "failed to close results in eager load on tags") } if err = results.Err(); err != nil { return errors.Wrap(err, "error occurred during iteration of eager loaded relations for tags") } if len(tagAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err } } } if singular { object.R.Tags = resultSlice for _, foreign := range resultSlice { if foreign.R == nil { foreign.R = &tagR{} } foreign.R.Posts = append(foreign.R.Posts, object) } return nil } for i, foreign := range resultSlice { localJoinCol := localJoinCols[i] for _, local := range slice { if local.ID == localJoinCol { local.R.Tags = append(local.R.Tags, foreign) if foreign.R == nil { foreign.R = &tagR{} } foreign.R.Posts = append(foreign.R.Posts, local) break } } } return nil } // LoadVotes 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 (postL) LoadVotes(ctx context.Context, e boil.ContextExecutor, singular bool, maybePost interface{}, mods queries.Applicator) error { var slice []*Post var object *Post if singular { var ok bool object, ok = maybePost.(*Post) if !ok { object = new(Post) ok = queries.SetFromEmbeddedStruct(&object, &maybePost) if !ok { return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", object, maybePost)) } } } else { s, ok := maybePost.(*[]*Post) if ok { slice = *s } else { ok = queries.SetFromEmbeddedStruct(&slice, maybePost) if !ok { return errors.New(fmt.Sprintf("failed to set %T from embedded struct %T", slice, maybePost)) } } } args := make(map[interface{}]struct{}) if singular { if object.R == nil { object.R = &postR{} } args[object.ID] = struct{}{} } else { for _, obj := range slice { if obj.R == nil { obj.R = &postR{} } 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(`votes`), qm.WhereIn(`votes.post_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 votes") } var resultSlice []*Vote if err = queries.Bind(results, &resultSlice); err != nil { return errors.Wrap(err, "failed to bind eager loaded slice votes") } if err = results.Close(); err != nil { return errors.Wrap(err, "failed to close results in eager load on votes") } if err = results.Err(); err != nil { return errors.Wrap(err, "error occurred during iteration of eager loaded relations for votes") } if len(voteAfterSelectHooks) != 0 { for _, obj := range resultSlice { if err := obj.doAfterSelectHooks(ctx, e); err != nil { return err } } } if singular { object.R.Votes = resultSlice for _, foreign := range resultSlice { if foreign.R == nil { foreign.R = &voteR{} } foreign.R.Post = object } return nil } for _, foreign := range resultSlice { for _, local := range slice { if queries.Equal(local.ID, foreign.PostID) { local.R.Votes = append(local.R.Votes, foreign) if foreign.R == nil { foreign.R = &voteR{} } foreign.R.Post = local break } } } return nil } // SetUser of the post to the related item. // Sets o.R.User to related. // Adds o to related.R.Posts. func (o *Post) SetUser(ctx context.Context, exec boil.ContextExecutor, insert bool, related *User) 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 \"posts\" SET %s WHERE %s", strmangle.SetParamNames("\"", "\"", 1, []string{"user_id"}), strmangle.WhereClause("\"", "\"", 2, postPrimaryKeyColumns), ) 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 = &postR{ User: related, } } else { o.R.User = related } if related.R == nil { related.R = &userR{ Posts: PostSlice{o}, } } else { related.R.Posts = append(related.R.Posts, o) } return nil } // AddComments adds the given related objects to the existing relationships // of the post, optionally inserting them as new records. // Appends related to o.R.Comments. // Sets related.R.Post appropriately. func (o *Post) AddComments(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Comment) error { var err error for _, rel := range related { if insert { rel.PostID = 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 \"comments\" SET %s WHERE %s", strmangle.SetParamNames("\"", "\"", 1, []string{"post_id"}), strmangle.WhereClause("\"", "\"", 2, commentPrimaryKeyColumns), ) 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.PostID = o.ID } } if o.R == nil { o.R = &postR{ Comments: related, } } else { o.R.Comments = append(o.R.Comments, related...) } for _, rel := range related { if rel.R == nil { rel.R = &commentR{ Post: o, } } else { rel.R.Post = o } } return nil } // AddTags adds the given related objects to the existing relationships // of the post, optionally inserting them as new records. // Appends related to o.R.Tags. // Sets related.R.Posts appropriately. func (o *Post) AddTags(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Tag) error { var err error for _, rel := range related { if insert { if err = rel.Insert(ctx, exec, boil.Infer()); err != nil { return errors.Wrap(err, "failed to insert into foreign table") } } } for _, rel := range related { query := "insert into \"post_tags\" (\"post_id\", \"tag_id\") values ($1, $2)" values := []interface{}{o.ID, rel.ID} if boil.IsDebug(ctx) { writer := boil.DebugWriterFrom(ctx) fmt.Fprintln(writer, query) fmt.Fprintln(writer, values) } _, err = exec.ExecContext(ctx, query, values...) if err != nil { return errors.Wrap(err, "failed to insert into join table") } } if o.R == nil { o.R = &postR{ Tags: related, } } else { o.R.Tags = append(o.R.Tags, related...) } for _, rel := range related { if rel.R == nil { rel.R = &tagR{ Posts: PostSlice{o}, } } else { rel.R.Posts = append(rel.R.Posts, o) } } return nil } // SetTags removes all previously related items of the // post replacing them completely with the passed // in related items, optionally inserting them as new records. // Sets o.R.Posts's Tags accordingly. // Replaces o.R.Tags with related. // Sets related.R.Posts's Tags accordingly. func (o *Post) SetTags(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Tag) error { query := "delete from \"post_tags\" where \"post_id\" = $1" values := []interface{}{o.ID} if boil.IsDebug(ctx) { writer := boil.DebugWriterFrom(ctx) fmt.Fprintln(writer, query) fmt.Fprintln(writer, values) } _, err := exec.ExecContext(ctx, query, values...) if err != nil { return errors.Wrap(err, "failed to remove relationships before set") } removeTagsFromPostsSlice(o, related) if o.R != nil { o.R.Tags = nil } return o.AddTags(ctx, exec, insert, related...) } // RemoveTags relationships from objects passed in. // Removes related items from R.Tags (uses pointer comparison, removal does not keep order) // Sets related.R.Posts. func (o *Post) RemoveTags(ctx context.Context, exec boil.ContextExecutor, related ...*Tag) error { if len(related) == 0 { return nil } var err error query := fmt.Sprintf( "delete from \"post_tags\" where \"post_id\" = $1 and \"tag_id\" in (%s)", strmangle.Placeholders(dialect.UseIndexPlaceholders, len(related), 2, 1), ) values := []interface{}{o.ID} for _, rel := range related { values = append(values, rel.ID) } if boil.IsDebug(ctx) { writer := boil.DebugWriterFrom(ctx) fmt.Fprintln(writer, query) fmt.Fprintln(writer, values) } _, err = exec.ExecContext(ctx, query, values...) if err != nil { return errors.Wrap(err, "failed to remove relationships before set") } removeTagsFromPostsSlice(o, related) if o.R == nil { return nil } for _, rel := range related { for i, ri := range o.R.Tags { if rel != ri { continue } ln := len(o.R.Tags) if ln > 1 && i < ln-1 { o.R.Tags[i] = o.R.Tags[ln-1] } o.R.Tags = o.R.Tags[:ln-1] break } } return nil } func removeTagsFromPostsSlice(o *Post, related []*Tag) { for _, rel := range related { if rel.R == nil { continue } for i, ri := range rel.R.Posts { if o.ID != ri.ID { continue } ln := len(rel.R.Posts) if ln > 1 && i < ln-1 { rel.R.Posts[i] = rel.R.Posts[ln-1] } rel.R.Posts = rel.R.Posts[:ln-1] break } } } // AddVotes adds the given related objects to the existing relationships // of the post, optionally inserting them as new records. // Appends related to o.R.Votes. // Sets related.R.Post appropriately. func (o *Post) AddVotes(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Vote) error { var err error for _, rel := range related { if insert { queries.Assign(&rel.PostID, 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 \"votes\" SET %s WHERE %s", strmangle.SetParamNames("\"", "\"", 1, []string{"post_id"}), strmangle.WhereClause("\"", "\"", 2, votePrimaryKeyColumns), ) 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") } queries.Assign(&rel.PostID, o.ID) } } if o.R == nil { o.R = &postR{ Votes: related, } } else { o.R.Votes = append(o.R.Votes, related...) } for _, rel := range related { if rel.R == nil { rel.R = &voteR{ Post: o, } } else { rel.R.Post = o } } return nil } // SetVotes removes all previously related items of the // post replacing them completely with the passed // in related items, optionally inserting them as new records. // Sets o.R.Post's Votes accordingly. // Replaces o.R.Votes with related. // Sets related.R.Post's Votes accordingly. func (o *Post) SetVotes(ctx context.Context, exec boil.ContextExecutor, insert bool, related ...*Vote) error { query := "update \"votes\" set \"post_id\" = null where \"post_id\" = $1" values := []interface{}{o.ID} if boil.IsDebug(ctx) { writer := boil.DebugWriterFrom(ctx) fmt.Fprintln(writer, query) fmt.Fprintln(writer, values) } _, err := exec.ExecContext(ctx, query, values...) if err != nil { return errors.Wrap(err, "failed to remove relationships before set") } if o.R != nil { for _, rel := range o.R.Votes { queries.SetScanner(&rel.PostID, nil) if rel.R == nil { continue } rel.R.Post = nil } o.R.Votes = nil } return o.AddVotes(ctx, exec, insert, related...) } // RemoveVotes relationships from objects passed in. // Removes related items from R.Votes (uses pointer comparison, removal does not keep order) // Sets related.R.Post. func (o *Post) RemoveVotes(ctx context.Context, exec boil.ContextExecutor, related ...*Vote) error { if len(related) == 0 { return nil } var err error for _, rel := range related { queries.SetScanner(&rel.PostID, nil) if rel.R != nil { rel.R.Post = nil } if _, err = rel.Update(ctx, exec, boil.Whitelist("post_id")); err != nil { return err } } if o.R == nil { return nil } for _, rel := range related { for i, ri := range o.R.Votes { if rel != ri { continue } ln := len(o.R.Votes) if ln > 1 && i < ln-1 { o.R.Votes[i] = o.R.Votes[ln-1] } o.R.Votes = o.R.Votes[:ln-1] break } } return nil } // Posts retrieves all the records using an executor. func Posts(mods ...qm.QueryMod) postQuery { mods = append(mods, qm.From("\"posts\"")) q := NewQuery(mods...) if len(queries.GetSelect(q)) == 0 { queries.SetSelect(q, []string{"\"posts\".*"}) } return postQuery{q} } // FindPost retrieves a single record by ID with an executor. // If selectCols is empty Find will return all columns. func FindPost(ctx context.Context, exec boil.ContextExecutor, iD int, selectCols ...string) (*Post, error) { postObj := &Post{} sel := "*" if len(selectCols) > 0 { sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",") } query := fmt.Sprintf( "select %s from \"posts\" where \"id\"=$1", sel, ) q := queries.Raw(query, iD) err := q.Bind(ctx, exec, postObj) if err != nil { if errors.Is(err, sql.ErrNoRows) { return nil, sql.ErrNoRows } return nil, errors.Wrap(err, "models: unable to select from posts") } if err = postObj.doAfterSelectHooks(ctx, exec); err != nil { return postObj, err } return postObj, nil } // Insert a single record using an executor. // See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts. func (o *Post) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error { if o == nil { return errors.New("models: no posts 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(postColumnsWithDefault, o) key := makeCacheKey(columns, nzDefaults) postInsertCacheMut.RLock() cache, cached := postInsertCache[key] postInsertCacheMut.RUnlock() if !cached { wl, returnColumns := columns.InsertColumnSet( postAllColumns, postColumnsWithDefault, postColumnsWithoutDefault, nzDefaults, ) cache.valueMapping, err = queries.BindMapping(postType, postMapping, wl) if err != nil { return err } cache.retMapping, err = queries.BindMapping(postType, postMapping, returnColumns) if err != nil { return err } if len(wl) != 0 { cache.query = fmt.Sprintf("INSERT INTO \"posts\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1)) } else { cache.query = "INSERT INTO \"posts\" %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, "models: unable to insert into posts") } if !cached { postInsertCacheMut.Lock() postInsertCache[key] = cache postInsertCacheMut.Unlock() } return o.doAfterInsertHooks(ctx, exec) } // Update uses an executor to update the Post. // 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 *Post) 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) postUpdateCacheMut.RLock() cache, cached := postUpdateCache[key] postUpdateCacheMut.RUnlock() if !cached { wl := columns.UpdateColumnSet( postAllColumns, postPrimaryKeyColumns, ) if !columns.IsWhitelist() { wl = strmangle.SetComplement(wl, []string{"created_at"}) } if len(wl) == 0 { return 0, errors.New("models: unable to update posts, could not build whitelist") } cache.query = fmt.Sprintf("UPDATE \"posts\" SET %s WHERE %s", strmangle.SetParamNames("\"", "\"", 1, wl), strmangle.WhereClause("\"", "\"", len(wl)+1, postPrimaryKeyColumns), ) cache.valueMapping, err = queries.BindMapping(postType, postMapping, append(wl, postPrimaryKeyColumns...)) 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, "models: unable to update posts row") } rowsAff, err := result.RowsAffected() if err != nil { return 0, errors.Wrap(err, "models: failed to get rows affected by update for posts") } if !cached { postUpdateCacheMut.Lock() postUpdateCache[key] = cache postUpdateCacheMut.Unlock() } return rowsAff, o.doAfterUpdateHooks(ctx, exec) } // UpdateAll updates all rows with the specified column values. func (q postQuery) 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, "models: unable to update all for posts") } rowsAff, err := result.RowsAffected() if err != nil { return 0, errors.Wrap(err, "models: unable to retrieve rows affected for posts") } return rowsAff, nil } // UpdateAll updates all rows with the specified column values, using an executor. func (o PostSlice) 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("models: 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)), postPrimaryKeyMapping) args = append(args, pkeyArgs...) } sql := fmt.Sprintf("UPDATE \"posts\" SET %s WHERE %s", strmangle.SetParamNames("\"", "\"", 1, colNames), strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, postPrimaryKeyColumns, 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, "models: unable to update all in post slice") } rowsAff, err := result.RowsAffected() if err != nil { return 0, errors.Wrap(err, "models: unable to retrieve rows affected all in update all post") } 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 *Post) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns, opts ...UpsertOptionFunc) error { if o == nil { return errors.New("models: no posts 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(postColumnsWithDefault, 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) postUpsertCacheMut.RLock() cache, cached := postUpsertCache[key] postUpsertCacheMut.RUnlock() var err error if !cached { insert, _ := insertColumns.InsertColumnSet( postAllColumns, postColumnsWithDefault, postColumnsWithoutDefault, nzDefaults, ) update := updateColumns.UpdateColumnSet( postAllColumns, postPrimaryKeyColumns, ) if updateOnConflict && len(update) == 0 { return errors.New("models: unable to upsert posts, could not build update column list") } ret := strmangle.SetComplement(postAllColumns, strmangle.SetIntersect(insert, update)) conflict := conflictColumns if len(conflict) == 0 && updateOnConflict && len(update) != 0 { if len(postPrimaryKeyColumns) == 0 { return errors.New("models: unable to upsert posts, could not build conflict column list") } conflict = make([]string, len(postPrimaryKeyColumns)) copy(conflict, postPrimaryKeyColumns) } cache.query = buildUpsertQueryPostgres(dialect, "\"posts\"", updateOnConflict, ret, update, conflict, insert, opts...) cache.valueMapping, err = queries.BindMapping(postType, postMapping, insert) if err != nil { return err } if len(ret) != 0 { cache.retMapping, err = queries.BindMapping(postType, postMapping, 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, "models: unable to upsert posts") } if !cached { postUpsertCacheMut.Lock() postUpsertCache[key] = cache postUpsertCacheMut.Unlock() } return o.doAfterUpsertHooks(ctx, exec) } // Delete deletes a single Post record with an executor. // Delete will match against the primary key column to find the record to delete. func (o *Post) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if o == nil { return 0, errors.New("models: no Post provided for delete") } if err := o.doBeforeDeleteHooks(ctx, exec); err != nil { return 0, err } args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), postPrimaryKeyMapping) sql := "DELETE FROM \"posts\" 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, "models: unable to delete from posts") } rowsAff, err := result.RowsAffected() if err != nil { return 0, errors.Wrap(err, "models: failed to get rows affected by delete for posts") } if err := o.doAfterDeleteHooks(ctx, exec); err != nil { return 0, err } return rowsAff, nil } // DeleteAll deletes all matching rows. func (q postQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if q.Query == nil { return 0, errors.New("models: no postQuery provided for delete all") } queries.SetDelete(q.Query) result, err := q.Query.ExecContext(ctx, exec) if err != nil { return 0, errors.Wrap(err, "models: unable to delete all from posts") } rowsAff, err := result.RowsAffected() if err != nil { return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for posts") } return rowsAff, nil } // DeleteAll deletes all rows in the slice, using an executor. func (o PostSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) { if len(o) == 0 { return 0, nil } if len(postBeforeDeleteHooks) != 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)), postPrimaryKeyMapping) args = append(args, pkeyArgs...) } sql := "DELETE FROM \"posts\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, postPrimaryKeyColumns, 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, "models: unable to delete all from post slice") } rowsAff, err := result.RowsAffected() if err != nil { return 0, errors.Wrap(err, "models: failed to get rows affected by deleteall for posts") } if len(postAfterDeleteHooks) != 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 *Post) Reload(ctx context.Context, exec boil.ContextExecutor) error { ret, err := FindPost(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 *PostSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error { if o == nil || len(*o) == 0 { return nil } slice := PostSlice{} var args []interface{} for _, obj := range *o { pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), postPrimaryKeyMapping) args = append(args, pkeyArgs...) } sql := "SELECT \"posts\".* FROM \"posts\" WHERE " + strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 1, postPrimaryKeyColumns, len(*o)) q := queries.Raw(sql, args...) err := q.Bind(ctx, exec, &slice) if err != nil { return errors.Wrap(err, "models: unable to reload all in PostSlice") } *o = slice return nil } // PostExists checks if the Post row exists. func PostExists(ctx context.Context, exec boil.ContextExecutor, iD int) (bool, error) { var exists bool sql := "select exists(select 1 from \"posts\" 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, "models: unable to check if posts exists") } return exists, nil } // Exists checks if the Post row exists. func (o *Post) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) { return PostExists(ctx, exec, o.ID) }