func (q blogPostQuery) DeleteAllP() {
	if err := q.DeleteAll(); err != nil {
		panic(boil.WrapErr(err))
	}
}
DeleteAllP deletes all rows, and panics on error.
package mdbmodels
import (
	"bytes"
	"database/sql"
	"fmt"
	"reflect"
	"strings"
	"sync"
	"time"
	"github.com/Bnei-Baruch/sqlboiler/boil"
	"github.com/Bnei-Baruch/sqlboiler/queries"
	"github.com/Bnei-Baruch/sqlboiler/queries/qm"
	"github.com/Bnei-Baruch/sqlboiler/strmangle"
	"github.com/pkg/errors"
)
type BlogPost struct {
	ID        int64     `boil:"id" json:"id" toml:"id" yaml:"id"`
	BlogID    int64     `boil:"blog_id" json:"blog_id" toml:"blog_id" yaml:"blog_id"`
	WPID      int64     `boil:"wp_id" json:"wp_id" toml:"wp_id" yaml:"wp_id"`
	Title     string    `boil:"title" json:"title" toml:"title" yaml:"title"`
	Content   string    `boil:"content" json:"content" toml:"content" yaml:"content"`
	PostedAt  time.Time `boil:"posted_at" json:"posted_at" toml:"posted_at" yaml:"posted_at"`
	CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
	Link      string    `boil:"link" json:"link" toml:"link" yaml:"link"`
	Filtered  bool      `boil:"filtered" json:"filtered" toml:"filtered" yaml:"filtered"`
	R *blogPostR `boil:"-" json:"-" toml:"-" yaml:"-"`
	L blogPostL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
var BlogPostColumns = struct {
	ID        string
	BlogID    string
	WPID      string
	Title     string
	Content   string
	PostedAt  string
	CreatedAt string
	Link      string
	Filtered  string
}{
	ID:        "id",
	BlogID:    "blog_id",
	WPID:      "wp_id",
	Title:     "title",
	Content:   "content",
	PostedAt:  "posted_at",
	CreatedAt: "created_at",
	Link:      "link",
	Filtered:  "filtered",
}
type blogPostR struct {
	Blog *Blog
}
type blogPostL struct{}
var (
	blogPostColumns               = []string{"id", "blog_id", "wp_id", "title", "content", "posted_at", "created_at", "link", "filtered"}
	blogPostColumnsWithoutDefault = []string{"blog_id", "wp_id", "title", "content", "posted_at"}
	blogPostColumnsWithDefault    = []string{"id", "created_at", "link", "filtered"}
	blogPostPrimaryKeyColumns     = []string{"id"}
)
type (
	BlogPostSlice []*BlogPost
	blogPostQuery struct {
		*queries.Query
	}
)
var (
	blogPostType                 = reflect.TypeOf(&BlogPost{})
	blogPostMapping              = queries.MakeStructMapping(blogPostType)
	blogPostPrimaryKeyMapping, _ = queries.BindMapping(blogPostType, blogPostMapping, blogPostPrimaryKeyColumns)
	blogPostInsertCacheMut       sync.RWMutex
	blogPostInsertCache          = make(map[string]insertCache)
	blogPostUpdateCacheMut       sync.RWMutex
	blogPostUpdateCache          = make(map[string]updateCache)
	blogPostUpsertCacheMut       sync.RWMutex
	blogPostUpsertCache          = make(map[string]insertCache)
)
var (
	_ = time.Second
	_ = bytes.MinRead
)
func (q blogPostQuery) OneP() *BlogPost {
	o, err := q.One()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q blogPostQuery) One() (*BlogPost, error) {
	o := &BlogPost{}
	queries.SetLimit(q.Query, 1)
	err := q.Bind(o)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: failed to execute a one query for blog_posts")
	}
	return o, nil
}
func (q blogPostQuery) AllP() BlogPostSlice {
	o, err := q.All()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return o
}
func (q blogPostQuery) All() (BlogPostSlice, error) {
	var o []*BlogPost
	err := q.Bind(&o)
	if err != nil {
		return nil, errors.Wrap(err, "mdbmodels: failed to assign all query results to BlogPost slice")
	}
	return o, nil
}
func (q blogPostQuery) CountP() int64 {
	c, err := q.Count()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return c
}
func (q blogPostQuery) Count() (int64, error) {
	var count int64
	queries.SetSelect(q.Query, nil)
	queries.SetCount(q.Query)
	err := q.Query.QueryRow().Scan(&count)
	if err != nil {
		return 0, errors.Wrap(err, "mdbmodels: failed to count blog_posts rows")
	}
	return count, nil
}
func (q blogPostQuery) ExistsP() bool {
	e, err := q.Exists()
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return e
}
func (q blogPostQuery) Exists() (bool, error) {
	var count int64
	queries.SetCount(q.Query)
	queries.SetLimit(q.Query, 1)
	err := q.Query.QueryRow().Scan(&count)
	if err != nil {
		return false, errors.Wrap(err, "mdbmodels: failed to check if blog_posts exists")
	}
	return count > 0, nil
}
func (o *BlogPost) BlogG(mods ...qm.QueryMod) blogQuery {
	return o.Blog(boil.GetDB(), mods...)
}
func (o *BlogPost) Blog(exec boil.Executor, mods ...qm.QueryMod) blogQuery {
	queryMods := []qm.QueryMod{
		qm.Where("id=?", o.BlogID),
	}
	queryMods = append(queryMods, mods...)
	query := Blogs(exec, queryMods...)
	queries.SetFrom(query.Query, "\"blogs\"")
	return query
}  
func (blogPostL) LoadBlog(e boil.Executor, singular bool, maybeBlogPost interface{}) error {
	var slice []*BlogPost
	var object *BlogPost
	count := 1
	if singular {
		object = maybeBlogPost.(*BlogPost)
	} else {
		slice = *maybeBlogPost.(*[]*BlogPost)
		count = len(slice)
	}
	args := make([]interface{}, count)
	if singular {
		if object.R == nil {
			object.R = &blogPostR{}
		}
		args[0] = object.BlogID
	} else {
		for i, obj := range slice {
			if obj.R == nil {
				obj.R = &blogPostR{}
			}
			args[i] = obj.BlogID
		}
	}
	query := fmt.Sprintf(
		"select * from \"blogs\" where \"id\" in (%s)",
		strmangle.Placeholders(dialect.IndexPlaceholders, count, 1, 1),
	)
	if boil.DebugMode {
		fmt.Fprintf(boil.DebugWriter, "%s\n%v\n", query, args)
	}
	results, err := e.Query(query, args...)
	if err != nil {
		return errors.Wrap(err, "failed to eager load Blog")
	}
	defer results.Close()
	var resultSlice []*Blog
	if err = queries.Bind(results, &resultSlice); err != nil {
		return errors.Wrap(err, "failed to bind eager loaded slice Blog")
	}
	if len(resultSlice) == 0 {
		return nil
	}
	if singular {
		object.R.Blog = resultSlice[0]
		return nil
	}
	for _, local := range slice {
		for _, foreign := range resultSlice {
			if local.BlogID == foreign.ID {
				local.R.Blog = foreign
				break
			}
		}
	}
	return nil
}
func (o *BlogPost) SetBlogG(insert bool, related *Blog) error {
	return o.SetBlog(boil.GetDB(), insert, related)
}
func (o *BlogPost) SetBlogP(exec boil.Executor, insert bool, related *Blog) {
	if err := o.SetBlog(exec, insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *BlogPost) SetBlogGP(insert bool, related *Blog) {
	if err := o.SetBlog(boil.GetDB(), insert, related); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *BlogPost) SetBlog(exec boil.Executor, insert bool, related *Blog) error {
	var err error
	if insert {
		if err = related.Insert(exec); err != nil {
			return errors.Wrap(err, "failed to insert into foreign table")
		}
	}
	updateQuery := fmt.Sprintf(
		"UPDATE \"blog_posts\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, []string{"blog_id"}),
		strmangle.WhereClause("\"", "\"", 2, blogPostPrimaryKeyColumns),
	)
	values := []interface{}{related.ID, o.ID}
	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, updateQuery)
		fmt.Fprintln(boil.DebugWriter, values)
	}
	if _, err = exec.Exec(updateQuery, values...); err != nil {
		return errors.Wrap(err, "failed to update local table")
	}
	o.BlogID = related.ID
	if o.R == nil {
		o.R = &blogPostR{
			Blog: related,
		}
	} else {
		o.R.Blog = related
	}
	if related.R == nil {
		related.R = &blogR{
			BlogPosts: BlogPostSlice{o},
		}
	} else {
		related.R.BlogPosts = append(related.R.BlogPosts, o)
	}
	return nil
}
func BlogPostsG(mods ...qm.QueryMod) blogPostQuery {
	return BlogPosts(boil.GetDB(), mods...)
}
func BlogPosts(exec boil.Executor, mods ...qm.QueryMod) blogPostQuery {
	mods = append(mods, qm.From("\"blog_posts\""))
	return blogPostQuery{NewQuery(exec, mods...)}
}
func FindBlogPostG(id int64, selectCols ...string) (*BlogPost, error) {
	return FindBlogPost(boil.GetDB(), id, selectCols...)
}
func FindBlogPostGP(id int64, selectCols ...string) *BlogPost {
	retobj, err := FindBlogPost(boil.GetDB(), id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func FindBlogPost(exec boil.Executor, id int64, selectCols ...string) (*BlogPost, error) {
	blogPostObj := &BlogPost{}
	sel := "*"
	if len(selectCols) > 0 {
		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
	}
	query := fmt.Sprintf(
		"select %s from \"blog_posts\" where \"id\"=$1", sel,
	)
	q := queries.Raw(exec, query, id)
	err := q.Bind(blogPostObj)
	if err != nil {
		if errors.Cause(err) == sql.ErrNoRows {
			return nil, sql.ErrNoRows
		}
		return nil, errors.Wrap(err, "mdbmodels: unable to select from blog_posts")
	}
	return blogPostObj, nil
}
func FindBlogPostP(exec boil.Executor, id int64, selectCols ...string) *BlogPost {
	retobj, err := FindBlogPost(exec, id, selectCols...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
	return retobj
}
func (o *BlogPost) InsertG(whitelist ...string) error {
	return o.Insert(boil.GetDB(), whitelist...)
}
func (o *BlogPost) InsertGP(whitelist ...string) {
	if err := o.Insert(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *BlogPost) InsertP(exec boil.Executor, whitelist ...string) {
	if err := o.Insert(exec, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *BlogPost) Insert(exec boil.Executor, whitelist ...string) error {
	if o == nil {
		return errors.New("mdbmodels: no blog_posts provided for insertion")
	}
	var err error
	nzDefaults := queries.NonZeroDefaultSet(blogPostColumnsWithDefault, o)
	key := makeCacheKey(whitelist, nzDefaults)
	blogPostInsertCacheMut.RLock()
	cache, cached := blogPostInsertCache[key]
	blogPostInsertCacheMut.RUnlock()
	if !cached {
		wl, returnColumns := strmangle.InsertColumnSet(
			blogPostColumns,
			blogPostColumnsWithDefault,
			blogPostColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		cache.valueMapping, err = queries.BindMapping(blogPostType, blogPostMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(blogPostType, blogPostMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"blog_posts\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.IndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"blog_posts\" DEFAULT VALUES"
		}
		var queryOutput, queryReturning string
		if len(cache.retMapping) != 0 {
			queryReturning = fmt.Sprintf(" RETURNING \"%s\"", strings.Join(returnColumns, "\",\""))
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
		}
	}
	value := reflect.Indirect(reflect.ValueOf(o))
	vals := queries.ValuesFromMapping(value, cache.valueMapping)
	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, vals)
	}
	if len(cache.retMapping) != 0 {
		err = exec.QueryRow(cache.query, vals...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
	} else {
		_, err = exec.Exec(cache.query, vals...)
	}
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to insert into blog_posts")
	}
	if !cached {
		blogPostInsertCacheMut.Lock()
		blogPostInsertCache[key] = cache
		blogPostInsertCacheMut.Unlock()
	}
	return nil
}
func (o *BlogPost) UpdateG(whitelist ...string) error {
	return o.Update(boil.GetDB(), whitelist...)
}
func (o *BlogPost) UpdateGP(whitelist ...string) {
	if err := o.Update(boil.GetDB(), whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *BlogPost) UpdateP(exec boil.Executor, whitelist ...string) {
	err := o.Update(exec, whitelist...)
	if err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *BlogPost) Update(exec boil.Executor, whitelist ...string) error {
	var err error
	key := makeCacheKey(whitelist, nil)
	blogPostUpdateCacheMut.RLock()
	cache, cached := blogPostUpdateCache[key]
	blogPostUpdateCacheMut.RUnlock()
	if !cached {
		wl := strmangle.UpdateColumnSet(
			blogPostColumns,
			blogPostPrimaryKeyColumns,
			whitelist,
		)
		if len(wl) == 0 {
			return errors.New("mdbmodels: unable to update blog_posts, could not build whitelist")
		}
		cache.query = fmt.Sprintf("UPDATE \"blog_posts\" SET %s WHERE %s",
			strmangle.SetParamNames("\"", "\"", 1, wl),
			strmangle.WhereClause("\"", "\"", len(wl)+1, blogPostPrimaryKeyColumns),
		)
		cache.valueMapping, err = queries.BindMapping(blogPostType, blogPostMapping, append(wl, blogPostPrimaryKeyColumns...))
		if err != nil {
			return err
		}
	}
	values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, values)
	}
	_, err = exec.Exec(cache.query, values...)
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to update blog_posts row")
	}
	if !cached {
		blogPostUpdateCacheMut.Lock()
		blogPostUpdateCache[key] = cache
		blogPostUpdateCacheMut.Unlock()
	}
	return nil
}
func (q blogPostQuery) UpdateAllP(cols M) {
	if err := q.UpdateAll(cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (q blogPostQuery) UpdateAll(cols M) error {
	queries.SetUpdate(q.Query, cols)
	_, err := q.Query.Exec()
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to update all for blog_posts")
	}
	return nil
}
func (o BlogPostSlice) UpdateAllG(cols M) error {
	return o.UpdateAll(boil.GetDB(), cols)
}
func (o BlogPostSlice) UpdateAllGP(cols M) {
	if err := o.UpdateAll(boil.GetDB(), cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o BlogPostSlice) UpdateAllP(exec boil.Executor, cols M) {
	if err := o.UpdateAll(exec, cols); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o BlogPostSlice) UpdateAll(exec boil.Executor, cols M) error {
	ln := int64(len(o))
	if ln == 0 {
		return nil
	}
	if len(cols) == 0 {
		return errors.New("mdbmodels: 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++
	}
	for _, obj := range o {
		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), blogPostPrimaryKeyMapping)
		args = append(args, pkeyArgs...)
	}
	sql := fmt.Sprintf("UPDATE \"blog_posts\" SET %s WHERE %s",
		strmangle.SetParamNames("\"", "\"", 1, colNames),
		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), len(colNames)+1, blogPostPrimaryKeyColumns, len(o)))
	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, sql)
		fmt.Fprintln(boil.DebugWriter, args...)
	}
	_, err := exec.Exec(sql, args...)
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to update all in blogPost slice")
	}
	return nil
}
func (o *BlogPost) UpsertG(updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) error {
	return o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, whitelist...)
}
func (o *BlogPost) UpsertGP(updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) {
	if err := o.Upsert(boil.GetDB(), updateOnConflict, conflictColumns, updateColumns, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *BlogPost) UpsertP(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) {
	if err := o.Upsert(exec, updateOnConflict, conflictColumns, updateColumns, whitelist...); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *BlogPost) Upsert(exec boil.Executor, updateOnConflict bool, conflictColumns []string, updateColumns []string, whitelist ...string) error {
	if o == nil {
		return errors.New("mdbmodels: no blog_posts provided for upsert")
	}
	nzDefaults := queries.NonZeroDefaultSet(blogPostColumnsWithDefault, o)
	buf := strmangle.GetBuffer()
	if updateOnConflict {
		buf.WriteByte('t')
	} else {
		buf.WriteByte('f')
	}
	buf.WriteByte('.')
	for _, c := range conflictColumns {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range updateColumns {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range whitelist {
		buf.WriteString(c)
	}
	buf.WriteByte('.')
	for _, c := range nzDefaults {
		buf.WriteString(c)
	}
	key := buf.String()
	strmangle.PutBuffer(buf)
	blogPostUpsertCacheMut.RLock()
	cache, cached := blogPostUpsertCache[key]
	blogPostUpsertCacheMut.RUnlock()
	var err error
	if !cached {
		insert, ret := strmangle.InsertColumnSet(
			blogPostColumns,
			blogPostColumnsWithDefault,
			blogPostColumnsWithoutDefault,
			nzDefaults,
			whitelist,
		)
		update := strmangle.UpdateColumnSet(
			blogPostColumns,
			blogPostPrimaryKeyColumns,
			updateColumns,
		)
		if len(update) == 0 {
			return errors.New("mdbmodels: unable to upsert blog_posts, could not build update column list")
		}
		conflict := conflictColumns
		if len(conflict) == 0 {
			conflict = make([]string, len(blogPostPrimaryKeyColumns))
			copy(conflict, blogPostPrimaryKeyColumns)
		}
		cache.query = queries.BuildUpsertQueryPostgres(dialect, "\"blog_posts\"", updateOnConflict, ret, update, conflict, insert)
		cache.valueMapping, err = queries.BindMapping(blogPostType, blogPostMapping, insert)
		if err != nil {
			return err
		}
		if len(ret) != 0 {
			cache.retMapping, err = queries.BindMapping(blogPostType, blogPostMapping, 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.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, vals)
	}
	if len(cache.retMapping) != 0 {
		err = exec.QueryRow(cache.query, vals...).Scan(returns...)
		if err == sql.ErrNoRows {
			err = nil  
		}
	} else {
		_, err = exec.Exec(cache.query, vals...)
	}
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to upsert blog_posts")
	}
	if !cached {
		blogPostUpsertCacheMut.Lock()
		blogPostUpsertCache[key] = cache
		blogPostUpsertCacheMut.Unlock()
	}
	return nil
}
func (o *BlogPost) DeleteP(exec boil.Executor) {
	if err := o.Delete(exec); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *BlogPost) DeleteG() error {
	if o == nil {
		return errors.New("mdbmodels: no BlogPost provided for deletion")
	}
	return o.Delete(boil.GetDB())
}
func (o *BlogPost) DeleteGP() {
	if err := o.DeleteG(); err != nil {
		panic(boil.WrapErr(err))
	}
}
func (o *BlogPost) Delete(exec boil.Executor) error {
	if o == nil {
		return errors.New("mdbmodels: no BlogPost provided for delete")
	}
	args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), blogPostPrimaryKeyMapping)
	sql := "DELETE FROM \"blog_posts\" WHERE \"id\"=$1"
	if boil.DebugMode {
		fmt.Fprintln(boil.DebugWriter, sql)
		fmt.Fprintln(boil.DebugWriter, args...)
	}
	_, err := exec.Exec(sql, args...)
	if err != nil {
		return errors.Wrap(err, "mdbmodels: unable to delete from blog_posts")
	}
	return nil
}