func (o *PollsContinent) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
	if o == nil {
		return errors.New("models: no polls_continent provided for insertion")
	}

	var err error

	if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
		return err
	}

	nzDefaults := queries.NonZeroDefaultSet(pollsContinentColumnsWithDefault, o)

	key := makeCacheKey(columns, nzDefaults)
	pollsContinentInsertCacheMut.RLock()
	cache, cached := pollsContinentInsertCache[key]
	pollsContinentInsertCacheMut.RUnlock()

	if !cached {
		wl, returnColumns := columns.InsertColumnSet(
			pollsContinentColumns,
			pollsContinentColumnsWithDefault,
			pollsContinentColumnsWithoutDefault,
			nzDefaults,
		)

		cache.valueMapping, err = queries.BindMapping(pollsContinentType, pollsContinentMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(pollsContinentType, pollsContinentMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"polls_continent\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"polls_continent\" %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.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, 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 polls_continent")
	}

	if !cached {
		pollsContinentInsertCacheMut.Lock()
		pollsContinentInsertCache[key] = cache
		pollsContinentInsertCacheMut.Unlock()
	}

	return o.doAfterInsertHooks(ctx, exec)
}
// Insert a single record using an executor.
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
Insert a single record using an executor.
See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
// Insert a single record using an executor . // See boil . Columns . InsertColumnSet documentation to understand column list inference for inserts .
func (o *PollsContinent) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
	if o == nil {
		return errors.New("models: no polls_continent provided for insertion")
	}
	var err error
	if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
		return err
	}
	nzDefaults := queries.NonZeroDefaultSet(pollsContinentColumnsWithDefault, o)
	key := makeCacheKey(columns, nzDefaults)
	pollsContinentInsertCacheMut.RLock()
	cache, cached := pollsContinentInsertCache[key]
	pollsContinentInsertCacheMut.RUnlock()
	if !cached {
		wl, returnColumns := columns.InsertColumnSet(
			pollsContinentColumns,
			pollsContinentColumnsWithDefault,
			pollsContinentColumnsWithoutDefault,
			nzDefaults,
		)
		cache.valueMapping, err = queries.BindMapping(pollsContinentType, pollsContinentMapping, wl)
		if err != nil {
			return err
		}
		cache.retMapping, err = queries.BindMapping(pollsContinentType, pollsContinentMapping, returnColumns)
		if err != nil {
			return err
		}
		if len(wl) != 0 {
			cache.query = fmt.Sprintf("INSERT INTO \"polls_continent\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
		} else {
			cache.query = "INSERT INTO \"polls_continent\" %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.DebugMode {
		fmt.Fprintln(boil.DebugWriter, cache.query)
		fmt.Fprintln(boil.DebugWriter, 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 polls_continent")
	}
	if !cached {
		pollsContinentInsertCacheMut.Lock()
		pollsContinentInsertCache[key] = cache
		pollsContinentInsertCacheMut.Unlock()
	}
	return o.doAfterInsertHooks(ctx, exec)
}
func ( o * PollsContinent ) Insert ( ctx context . Context , exec boil . ContextExecutor , columns boil . Columns ) error { if o == nil { return errors . New ( " " ) } var err error if err := o . doBeforeInsertHooks ( ctx , exec ) ; err != nil { return err } nzDefaults := queries . NonZeroDefaultSet ( pollsContinentColumnsWithDefault , o ) key := makeCacheKey ( columns , nzDefaults ) pollsContinentInsertCacheMut . RLock ( ) cache , cached := pollsContinentInsertCache [ key ] pollsContinentInsertCacheMut . RUnlock ( ) if ! cached { wl , returnColumns := columns . InsertColumnSet ( pollsContinentColumns , pollsContinentColumnsWithDefault , pollsContinentColumnsWithoutDefault , nzDefaults , ) cache . valueMapping , err = queries . BindMapping ( pollsContinentType , pollsContinentMapping , wl ) if err != nil { return err } cache . retMapping , err = queries . BindMapping ( pollsContinentType , pollsContinentMapping , returnColumns ) if err != nil { return err } if len ( wl ) != 0 { cache . query = fmt . Sprintf ( " \" \" \" \" " , strings . Join ( wl , " \" \" " ) , strmangle . Placeholders ( dialect . UseIndexPlaceholders , len ( wl ) , 1 , 1 ) ) } else { cache . query = " \" \" " } var queryOutput , queryReturning string if len ( cache . retMapping ) != 0 { queryReturning = fmt . Sprintf ( " \" \" " , 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 . DebugMode { fmt . Fprintln ( boil . DebugWriter , cache . query ) fmt . Fprintln ( boil . DebugWriter , 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 , " " ) } if ! cached { pollsContinentInsertCacheMut . Lock ( ) pollsContinentInsertCache [ key ] = cache pollsContinentInsertCacheMut . Unlock ( ) } return o . doAfterInsertHooks ( ctx , exec ) }
Insert a single record using an executor.
Insert a single record using an executor .