github.com/oinume/lekcije@v0.0.0-20231017100347-5b4c5eb6ab24/backend/model2/user_google.go (about)

     1  // Code generated by SQLBoiler 4.14.2 (https://github.com/volatiletech/sqlboiler). DO NOT EDIT.
     2  // This file is meant to be re-generated in place and/or deleted at any time.
     3  
     4  package model2
     5  
     6  import (
     7  	"context"
     8  	"database/sql"
     9  	"fmt"
    10  	"reflect"
    11  	"strconv"
    12  	"strings"
    13  	"sync"
    14  	"time"
    15  
    16  	"github.com/friendsofgo/errors"
    17  	"github.com/volatiletech/sqlboiler/v4/boil"
    18  	"github.com/volatiletech/sqlboiler/v4/queries"
    19  	"github.com/volatiletech/sqlboiler/v4/queries/qm"
    20  	"github.com/volatiletech/sqlboiler/v4/queries/qmhelper"
    21  	"github.com/volatiletech/strmangle"
    22  )
    23  
    24  // UserGoogle is an object representing the database table.
    25  type UserGoogle struct {
    26  	GoogleID  string    `boil:"google_id" json:"google_id" toml:"google_id" yaml:"google_id"`
    27  	UserID    uint      `boil:"user_id" json:"user_id" toml:"user_id" yaml:"user_id"`
    28  	CreatedAt time.Time `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
    29  	UpdatedAt time.Time `boil:"updated_at" json:"updated_at" toml:"updated_at" yaml:"updated_at"`
    30  
    31  	R *userGoogleR `boil:"-" json:"-" toml:"-" yaml:"-"`
    32  	L userGoogleL  `boil:"-" json:"-" toml:"-" yaml:"-"`
    33  }
    34  
    35  var UserGoogleColumns = struct {
    36  	GoogleID  string
    37  	UserID    string
    38  	CreatedAt string
    39  	UpdatedAt string
    40  }{
    41  	GoogleID:  "google_id",
    42  	UserID:    "user_id",
    43  	CreatedAt: "created_at",
    44  	UpdatedAt: "updated_at",
    45  }
    46  
    47  var UserGoogleTableColumns = struct {
    48  	GoogleID  string
    49  	UserID    string
    50  	CreatedAt string
    51  	UpdatedAt string
    52  }{
    53  	GoogleID:  "user_google.google_id",
    54  	UserID:    "user_google.user_id",
    55  	CreatedAt: "user_google.created_at",
    56  	UpdatedAt: "user_google.updated_at",
    57  }
    58  
    59  // Generated where
    60  
    61  var UserGoogleWhere = struct {
    62  	GoogleID  whereHelperstring
    63  	UserID    whereHelperuint
    64  	CreatedAt whereHelpertime_Time
    65  	UpdatedAt whereHelpertime_Time
    66  }{
    67  	GoogleID:  whereHelperstring{field: "`user_google`.`google_id`"},
    68  	UserID:    whereHelperuint{field: "`user_google`.`user_id`"},
    69  	CreatedAt: whereHelpertime_Time{field: "`user_google`.`created_at`"},
    70  	UpdatedAt: whereHelpertime_Time{field: "`user_google`.`updated_at`"},
    71  }
    72  
    73  // UserGoogleRels is where relationship names are stored.
    74  var UserGoogleRels = struct {
    75  }{}
    76  
    77  // userGoogleR is where relationships are stored.
    78  type userGoogleR struct {
    79  }
    80  
    81  // NewStruct creates a new relationship struct
    82  func (*userGoogleR) NewStruct() *userGoogleR {
    83  	return &userGoogleR{}
    84  }
    85  
    86  // userGoogleL is where Load methods for each relationship are stored.
    87  type userGoogleL struct{}
    88  
    89  var (
    90  	userGoogleAllColumns            = []string{"google_id", "user_id", "created_at", "updated_at"}
    91  	userGoogleColumnsWithoutDefault = []string{"google_id", "user_id", "created_at", "updated_at"}
    92  	userGoogleColumnsWithDefault    = []string{}
    93  	userGooglePrimaryKeyColumns     = []string{"google_id"}
    94  	userGoogleGeneratedColumns      = []string{}
    95  )
    96  
    97  type (
    98  	// UserGoogleSlice is an alias for a slice of pointers to UserGoogle.
    99  	// This should almost always be used instead of []UserGoogle.
   100  	UserGoogleSlice []*UserGoogle
   101  	// UserGoogleHook is the signature for custom UserGoogle hook methods
   102  	UserGoogleHook func(context.Context, boil.ContextExecutor, *UserGoogle) error
   103  
   104  	userGoogleQuery struct {
   105  		*queries.Query
   106  	}
   107  )
   108  
   109  // Cache for insert, update and upsert
   110  var (
   111  	userGoogleType                 = reflect.TypeOf(&UserGoogle{})
   112  	userGoogleMapping              = queries.MakeStructMapping(userGoogleType)
   113  	userGooglePrimaryKeyMapping, _ = queries.BindMapping(userGoogleType, userGoogleMapping, userGooglePrimaryKeyColumns)
   114  	userGoogleInsertCacheMut       sync.RWMutex
   115  	userGoogleInsertCache          = make(map[string]insertCache)
   116  	userGoogleUpdateCacheMut       sync.RWMutex
   117  	userGoogleUpdateCache          = make(map[string]updateCache)
   118  	userGoogleUpsertCacheMut       sync.RWMutex
   119  	userGoogleUpsertCache          = make(map[string]insertCache)
   120  )
   121  
   122  var (
   123  	// Force time package dependency for automated UpdatedAt/CreatedAt.
   124  	_ = time.Second
   125  	// Force qmhelper dependency for where clause generation (which doesn't
   126  	// always happen)
   127  	_ = qmhelper.Where
   128  )
   129  
   130  var userGoogleAfterSelectHooks []UserGoogleHook
   131  
   132  var userGoogleBeforeInsertHooks []UserGoogleHook
   133  var userGoogleAfterInsertHooks []UserGoogleHook
   134  
   135  var userGoogleBeforeUpdateHooks []UserGoogleHook
   136  var userGoogleAfterUpdateHooks []UserGoogleHook
   137  
   138  var userGoogleBeforeDeleteHooks []UserGoogleHook
   139  var userGoogleAfterDeleteHooks []UserGoogleHook
   140  
   141  var userGoogleBeforeUpsertHooks []UserGoogleHook
   142  var userGoogleAfterUpsertHooks []UserGoogleHook
   143  
   144  // doAfterSelectHooks executes all "after Select" hooks.
   145  func (o *UserGoogle) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
   146  	if boil.HooksAreSkipped(ctx) {
   147  		return nil
   148  	}
   149  
   150  	for _, hook := range userGoogleAfterSelectHooks {
   151  		if err := hook(ctx, exec, o); err != nil {
   152  			return err
   153  		}
   154  	}
   155  
   156  	return nil
   157  }
   158  
   159  // doBeforeInsertHooks executes all "before insert" hooks.
   160  func (o *UserGoogle) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
   161  	if boil.HooksAreSkipped(ctx) {
   162  		return nil
   163  	}
   164  
   165  	for _, hook := range userGoogleBeforeInsertHooks {
   166  		if err := hook(ctx, exec, o); err != nil {
   167  			return err
   168  		}
   169  	}
   170  
   171  	return nil
   172  }
   173  
   174  // doAfterInsertHooks executes all "after Insert" hooks.
   175  func (o *UserGoogle) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
   176  	if boil.HooksAreSkipped(ctx) {
   177  		return nil
   178  	}
   179  
   180  	for _, hook := range userGoogleAfterInsertHooks {
   181  		if err := hook(ctx, exec, o); err != nil {
   182  			return err
   183  		}
   184  	}
   185  
   186  	return nil
   187  }
   188  
   189  // doBeforeUpdateHooks executes all "before Update" hooks.
   190  func (o *UserGoogle) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
   191  	if boil.HooksAreSkipped(ctx) {
   192  		return nil
   193  	}
   194  
   195  	for _, hook := range userGoogleBeforeUpdateHooks {
   196  		if err := hook(ctx, exec, o); err != nil {
   197  			return err
   198  		}
   199  	}
   200  
   201  	return nil
   202  }
   203  
   204  // doAfterUpdateHooks executes all "after Update" hooks.
   205  func (o *UserGoogle) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
   206  	if boil.HooksAreSkipped(ctx) {
   207  		return nil
   208  	}
   209  
   210  	for _, hook := range userGoogleAfterUpdateHooks {
   211  		if err := hook(ctx, exec, o); err != nil {
   212  			return err
   213  		}
   214  	}
   215  
   216  	return nil
   217  }
   218  
   219  // doBeforeDeleteHooks executes all "before Delete" hooks.
   220  func (o *UserGoogle) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
   221  	if boil.HooksAreSkipped(ctx) {
   222  		return nil
   223  	}
   224  
   225  	for _, hook := range userGoogleBeforeDeleteHooks {
   226  		if err := hook(ctx, exec, o); err != nil {
   227  			return err
   228  		}
   229  	}
   230  
   231  	return nil
   232  }
   233  
   234  // doAfterDeleteHooks executes all "after Delete" hooks.
   235  func (o *UserGoogle) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
   236  	if boil.HooksAreSkipped(ctx) {
   237  		return nil
   238  	}
   239  
   240  	for _, hook := range userGoogleAfterDeleteHooks {
   241  		if err := hook(ctx, exec, o); err != nil {
   242  			return err
   243  		}
   244  	}
   245  
   246  	return nil
   247  }
   248  
   249  // doBeforeUpsertHooks executes all "before Upsert" hooks.
   250  func (o *UserGoogle) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
   251  	if boil.HooksAreSkipped(ctx) {
   252  		return nil
   253  	}
   254  
   255  	for _, hook := range userGoogleBeforeUpsertHooks {
   256  		if err := hook(ctx, exec, o); err != nil {
   257  			return err
   258  		}
   259  	}
   260  
   261  	return nil
   262  }
   263  
   264  // doAfterUpsertHooks executes all "after Upsert" hooks.
   265  func (o *UserGoogle) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
   266  	if boil.HooksAreSkipped(ctx) {
   267  		return nil
   268  	}
   269  
   270  	for _, hook := range userGoogleAfterUpsertHooks {
   271  		if err := hook(ctx, exec, o); err != nil {
   272  			return err
   273  		}
   274  	}
   275  
   276  	return nil
   277  }
   278  
   279  // AddUserGoogleHook registers your hook function for all future operations.
   280  func AddUserGoogleHook(hookPoint boil.HookPoint, userGoogleHook UserGoogleHook) {
   281  	switch hookPoint {
   282  	case boil.AfterSelectHook:
   283  		userGoogleAfterSelectHooks = append(userGoogleAfterSelectHooks, userGoogleHook)
   284  	case boil.BeforeInsertHook:
   285  		userGoogleBeforeInsertHooks = append(userGoogleBeforeInsertHooks, userGoogleHook)
   286  	case boil.AfterInsertHook:
   287  		userGoogleAfterInsertHooks = append(userGoogleAfterInsertHooks, userGoogleHook)
   288  	case boil.BeforeUpdateHook:
   289  		userGoogleBeforeUpdateHooks = append(userGoogleBeforeUpdateHooks, userGoogleHook)
   290  	case boil.AfterUpdateHook:
   291  		userGoogleAfterUpdateHooks = append(userGoogleAfterUpdateHooks, userGoogleHook)
   292  	case boil.BeforeDeleteHook:
   293  		userGoogleBeforeDeleteHooks = append(userGoogleBeforeDeleteHooks, userGoogleHook)
   294  	case boil.AfterDeleteHook:
   295  		userGoogleAfterDeleteHooks = append(userGoogleAfterDeleteHooks, userGoogleHook)
   296  	case boil.BeforeUpsertHook:
   297  		userGoogleBeforeUpsertHooks = append(userGoogleBeforeUpsertHooks, userGoogleHook)
   298  	case boil.AfterUpsertHook:
   299  		userGoogleAfterUpsertHooks = append(userGoogleAfterUpsertHooks, userGoogleHook)
   300  	}
   301  }
   302  
   303  // One returns a single userGoogle record from the query.
   304  func (q userGoogleQuery) One(ctx context.Context, exec boil.ContextExecutor) (*UserGoogle, error) {
   305  	o := &UserGoogle{}
   306  
   307  	queries.SetLimit(q.Query, 1)
   308  
   309  	err := q.Bind(ctx, exec, o)
   310  	if err != nil {
   311  		if errors.Is(err, sql.ErrNoRows) {
   312  			return nil, sql.ErrNoRows
   313  		}
   314  		return nil, errors.Wrap(err, "model2: failed to execute a one query for user_google")
   315  	}
   316  
   317  	if err := o.doAfterSelectHooks(ctx, exec); err != nil {
   318  		return o, err
   319  	}
   320  
   321  	return o, nil
   322  }
   323  
   324  // All returns all UserGoogle records from the query.
   325  func (q userGoogleQuery) All(ctx context.Context, exec boil.ContextExecutor) (UserGoogleSlice, error) {
   326  	var o []*UserGoogle
   327  
   328  	err := q.Bind(ctx, exec, &o)
   329  	if err != nil {
   330  		return nil, errors.Wrap(err, "model2: failed to assign all query results to UserGoogle slice")
   331  	}
   332  
   333  	if len(userGoogleAfterSelectHooks) != 0 {
   334  		for _, obj := range o {
   335  			if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
   336  				return o, err
   337  			}
   338  		}
   339  	}
   340  
   341  	return o, nil
   342  }
   343  
   344  // Count returns the count of all UserGoogle records in the query.
   345  func (q userGoogleQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
   346  	var count int64
   347  
   348  	queries.SetSelect(q.Query, nil)
   349  	queries.SetCount(q.Query)
   350  
   351  	err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
   352  	if err != nil {
   353  		return 0, errors.Wrap(err, "model2: failed to count user_google rows")
   354  	}
   355  
   356  	return count, nil
   357  }
   358  
   359  // Exists checks if the row exists in the table.
   360  func (q userGoogleQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
   361  	var count int64
   362  
   363  	queries.SetSelect(q.Query, nil)
   364  	queries.SetCount(q.Query)
   365  	queries.SetLimit(q.Query, 1)
   366  
   367  	err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
   368  	if err != nil {
   369  		return false, errors.Wrap(err, "model2: failed to check if user_google exists")
   370  	}
   371  
   372  	return count > 0, nil
   373  }
   374  
   375  // UserGoogles retrieves all the records using an executor.
   376  func UserGoogles(mods ...qm.QueryMod) userGoogleQuery {
   377  	mods = append(mods, qm.From("`user_google`"))
   378  	q := NewQuery(mods...)
   379  	if len(queries.GetSelect(q)) == 0 {
   380  		queries.SetSelect(q, []string{"`user_google`.*"})
   381  	}
   382  
   383  	return userGoogleQuery{q}
   384  }
   385  
   386  // FindUserGoogle retrieves a single record by ID with an executor.
   387  // If selectCols is empty Find will return all columns.
   388  func FindUserGoogle(ctx context.Context, exec boil.ContextExecutor, googleID string, selectCols ...string) (*UserGoogle, error) {
   389  	userGoogleObj := &UserGoogle{}
   390  
   391  	sel := "*"
   392  	if len(selectCols) > 0 {
   393  		sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
   394  	}
   395  	query := fmt.Sprintf(
   396  		"select %s from `user_google` where `google_id`=?", sel,
   397  	)
   398  
   399  	q := queries.Raw(query, googleID)
   400  
   401  	err := q.Bind(ctx, exec, userGoogleObj)
   402  	if err != nil {
   403  		if errors.Is(err, sql.ErrNoRows) {
   404  			return nil, sql.ErrNoRows
   405  		}
   406  		return nil, errors.Wrap(err, "model2: unable to select from user_google")
   407  	}
   408  
   409  	if err = userGoogleObj.doAfterSelectHooks(ctx, exec); err != nil {
   410  		return userGoogleObj, err
   411  	}
   412  
   413  	return userGoogleObj, nil
   414  }
   415  
   416  // Insert a single record using an executor.
   417  // See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
   418  func (o *UserGoogle) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
   419  	if o == nil {
   420  		return errors.New("model2: no user_google provided for insertion")
   421  	}
   422  
   423  	var err error
   424  	if !boil.TimestampsAreSkipped(ctx) {
   425  		currTime := time.Now().In(boil.GetLocation())
   426  
   427  		if o.CreatedAt.IsZero() {
   428  			o.CreatedAt = currTime
   429  		}
   430  		if o.UpdatedAt.IsZero() {
   431  			o.UpdatedAt = currTime
   432  		}
   433  	}
   434  
   435  	if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
   436  		return err
   437  	}
   438  
   439  	nzDefaults := queries.NonZeroDefaultSet(userGoogleColumnsWithDefault, o)
   440  
   441  	key := makeCacheKey(columns, nzDefaults)
   442  	userGoogleInsertCacheMut.RLock()
   443  	cache, cached := userGoogleInsertCache[key]
   444  	userGoogleInsertCacheMut.RUnlock()
   445  
   446  	if !cached {
   447  		wl, returnColumns := columns.InsertColumnSet(
   448  			userGoogleAllColumns,
   449  			userGoogleColumnsWithDefault,
   450  			userGoogleColumnsWithoutDefault,
   451  			nzDefaults,
   452  		)
   453  
   454  		cache.valueMapping, err = queries.BindMapping(userGoogleType, userGoogleMapping, wl)
   455  		if err != nil {
   456  			return err
   457  		}
   458  		cache.retMapping, err = queries.BindMapping(userGoogleType, userGoogleMapping, returnColumns)
   459  		if err != nil {
   460  			return err
   461  		}
   462  		if len(wl) != 0 {
   463  			cache.query = fmt.Sprintf("INSERT INTO `user_google` (`%s`) %%sVALUES (%s)%%s", strings.Join(wl, "`,`"), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
   464  		} else {
   465  			cache.query = "INSERT INTO `user_google` () VALUES ()%s%s"
   466  		}
   467  
   468  		var queryOutput, queryReturning string
   469  
   470  		if len(cache.retMapping) != 0 {
   471  			cache.retQuery = fmt.Sprintf("SELECT `%s` FROM `user_google` WHERE %s", strings.Join(returnColumns, "`,`"), strmangle.WhereClause("`", "`", 0, userGooglePrimaryKeyColumns))
   472  		}
   473  
   474  		cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
   475  	}
   476  
   477  	value := reflect.Indirect(reflect.ValueOf(o))
   478  	vals := queries.ValuesFromMapping(value, cache.valueMapping)
   479  
   480  	if boil.IsDebug(ctx) {
   481  		writer := boil.DebugWriterFrom(ctx)
   482  		fmt.Fprintln(writer, cache.query)
   483  		fmt.Fprintln(writer, vals)
   484  	}
   485  	_, err = exec.ExecContext(ctx, cache.query, vals...)
   486  
   487  	if err != nil {
   488  		return errors.Wrap(err, "model2: unable to insert into user_google")
   489  	}
   490  
   491  	var identifierCols []interface{}
   492  
   493  	if len(cache.retMapping) == 0 {
   494  		goto CacheNoHooks
   495  	}
   496  
   497  	identifierCols = []interface{}{
   498  		o.GoogleID,
   499  	}
   500  
   501  	if boil.IsDebug(ctx) {
   502  		writer := boil.DebugWriterFrom(ctx)
   503  		fmt.Fprintln(writer, cache.retQuery)
   504  		fmt.Fprintln(writer, identifierCols...)
   505  	}
   506  	err = exec.QueryRowContext(ctx, cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
   507  	if err != nil {
   508  		return errors.Wrap(err, "model2: unable to populate default values for user_google")
   509  	}
   510  
   511  CacheNoHooks:
   512  	if !cached {
   513  		userGoogleInsertCacheMut.Lock()
   514  		userGoogleInsertCache[key] = cache
   515  		userGoogleInsertCacheMut.Unlock()
   516  	}
   517  
   518  	return o.doAfterInsertHooks(ctx, exec)
   519  }
   520  
   521  // Update uses an executor to update the UserGoogle.
   522  // See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
   523  // Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
   524  func (o *UserGoogle) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
   525  	if !boil.TimestampsAreSkipped(ctx) {
   526  		currTime := time.Now().In(boil.GetLocation())
   527  
   528  		o.UpdatedAt = currTime
   529  	}
   530  
   531  	var err error
   532  	if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
   533  		return 0, err
   534  	}
   535  	key := makeCacheKey(columns, nil)
   536  	userGoogleUpdateCacheMut.RLock()
   537  	cache, cached := userGoogleUpdateCache[key]
   538  	userGoogleUpdateCacheMut.RUnlock()
   539  
   540  	if !cached {
   541  		wl := columns.UpdateColumnSet(
   542  			userGoogleAllColumns,
   543  			userGooglePrimaryKeyColumns,
   544  		)
   545  
   546  		if !columns.IsWhitelist() {
   547  			wl = strmangle.SetComplement(wl, []string{"created_at"})
   548  		}
   549  		if len(wl) == 0 {
   550  			return 0, errors.New("model2: unable to update user_google, could not build whitelist")
   551  		}
   552  
   553  		cache.query = fmt.Sprintf("UPDATE `user_google` SET %s WHERE %s",
   554  			strmangle.SetParamNames("`", "`", 0, wl),
   555  			strmangle.WhereClause("`", "`", 0, userGooglePrimaryKeyColumns),
   556  		)
   557  		cache.valueMapping, err = queries.BindMapping(userGoogleType, userGoogleMapping, append(wl, userGooglePrimaryKeyColumns...))
   558  		if err != nil {
   559  			return 0, err
   560  		}
   561  	}
   562  
   563  	values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
   564  
   565  	if boil.IsDebug(ctx) {
   566  		writer := boil.DebugWriterFrom(ctx)
   567  		fmt.Fprintln(writer, cache.query)
   568  		fmt.Fprintln(writer, values)
   569  	}
   570  	var result sql.Result
   571  	result, err = exec.ExecContext(ctx, cache.query, values...)
   572  	if err != nil {
   573  		return 0, errors.Wrap(err, "model2: unable to update user_google row")
   574  	}
   575  
   576  	rowsAff, err := result.RowsAffected()
   577  	if err != nil {
   578  		return 0, errors.Wrap(err, "model2: failed to get rows affected by update for user_google")
   579  	}
   580  
   581  	if !cached {
   582  		userGoogleUpdateCacheMut.Lock()
   583  		userGoogleUpdateCache[key] = cache
   584  		userGoogleUpdateCacheMut.Unlock()
   585  	}
   586  
   587  	return rowsAff, o.doAfterUpdateHooks(ctx, exec)
   588  }
   589  
   590  // UpdateAll updates all rows with the specified column values.
   591  func (q userGoogleQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
   592  	queries.SetUpdate(q.Query, cols)
   593  
   594  	result, err := q.Query.ExecContext(ctx, exec)
   595  	if err != nil {
   596  		return 0, errors.Wrap(err, "model2: unable to update all for user_google")
   597  	}
   598  
   599  	rowsAff, err := result.RowsAffected()
   600  	if err != nil {
   601  		return 0, errors.Wrap(err, "model2: unable to retrieve rows affected for user_google")
   602  	}
   603  
   604  	return rowsAff, nil
   605  }
   606  
   607  // UpdateAll updates all rows with the specified column values, using an executor.
   608  func (o UserGoogleSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
   609  	ln := int64(len(o))
   610  	if ln == 0 {
   611  		return 0, nil
   612  	}
   613  
   614  	if len(cols) == 0 {
   615  		return 0, errors.New("model2: update all requires at least one column argument")
   616  	}
   617  
   618  	colNames := make([]string, len(cols))
   619  	args := make([]interface{}, len(cols))
   620  
   621  	i := 0
   622  	for name, value := range cols {
   623  		colNames[i] = name
   624  		args[i] = value
   625  		i++
   626  	}
   627  
   628  	// Append all of the primary key values for each column
   629  	for _, obj := range o {
   630  		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), userGooglePrimaryKeyMapping)
   631  		args = append(args, pkeyArgs...)
   632  	}
   633  
   634  	sql := fmt.Sprintf("UPDATE `user_google` SET %s WHERE %s",
   635  		strmangle.SetParamNames("`", "`", 0, colNames),
   636  		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, userGooglePrimaryKeyColumns, len(o)))
   637  
   638  	if boil.IsDebug(ctx) {
   639  		writer := boil.DebugWriterFrom(ctx)
   640  		fmt.Fprintln(writer, sql)
   641  		fmt.Fprintln(writer, args...)
   642  	}
   643  	result, err := exec.ExecContext(ctx, sql, args...)
   644  	if err != nil {
   645  		return 0, errors.Wrap(err, "model2: unable to update all in userGoogle slice")
   646  	}
   647  
   648  	rowsAff, err := result.RowsAffected()
   649  	if err != nil {
   650  		return 0, errors.Wrap(err, "model2: unable to retrieve rows affected all in update all userGoogle")
   651  	}
   652  	return rowsAff, nil
   653  }
   654  
   655  var mySQLUserGoogleUniqueColumns = []string{
   656  	"google_id",
   657  	"user_id",
   658  }
   659  
   660  // Upsert attempts an insert using an executor, and does an update or ignore on conflict.
   661  // See boil.Columns documentation for how to properly use updateColumns and insertColumns.
   662  func (o *UserGoogle) Upsert(ctx context.Context, exec boil.ContextExecutor, updateColumns, insertColumns boil.Columns) error {
   663  	if o == nil {
   664  		return errors.New("model2: no user_google provided for upsert")
   665  	}
   666  	if !boil.TimestampsAreSkipped(ctx) {
   667  		currTime := time.Now().In(boil.GetLocation())
   668  
   669  		if o.CreatedAt.IsZero() {
   670  			o.CreatedAt = currTime
   671  		}
   672  		o.UpdatedAt = currTime
   673  	}
   674  
   675  	if err := o.doBeforeUpsertHooks(ctx, exec); err != nil {
   676  		return err
   677  	}
   678  
   679  	nzDefaults := queries.NonZeroDefaultSet(userGoogleColumnsWithDefault, o)
   680  	nzUniques := queries.NonZeroDefaultSet(mySQLUserGoogleUniqueColumns, o)
   681  
   682  	if len(nzUniques) == 0 {
   683  		return errors.New("cannot upsert with a table that cannot conflict on a unique column")
   684  	}
   685  
   686  	// Build cache key in-line uglily - mysql vs psql problems
   687  	buf := strmangle.GetBuffer()
   688  	buf.WriteString(strconv.Itoa(updateColumns.Kind))
   689  	for _, c := range updateColumns.Cols {
   690  		buf.WriteString(c)
   691  	}
   692  	buf.WriteByte('.')
   693  	buf.WriteString(strconv.Itoa(insertColumns.Kind))
   694  	for _, c := range insertColumns.Cols {
   695  		buf.WriteString(c)
   696  	}
   697  	buf.WriteByte('.')
   698  	for _, c := range nzDefaults {
   699  		buf.WriteString(c)
   700  	}
   701  	buf.WriteByte('.')
   702  	for _, c := range nzUniques {
   703  		buf.WriteString(c)
   704  	}
   705  	key := buf.String()
   706  	strmangle.PutBuffer(buf)
   707  
   708  	userGoogleUpsertCacheMut.RLock()
   709  	cache, cached := userGoogleUpsertCache[key]
   710  	userGoogleUpsertCacheMut.RUnlock()
   711  
   712  	var err error
   713  
   714  	if !cached {
   715  		insert, ret := insertColumns.InsertColumnSet(
   716  			userGoogleAllColumns,
   717  			userGoogleColumnsWithDefault,
   718  			userGoogleColumnsWithoutDefault,
   719  			nzDefaults,
   720  		)
   721  
   722  		update := updateColumns.UpdateColumnSet(
   723  			userGoogleAllColumns,
   724  			userGooglePrimaryKeyColumns,
   725  		)
   726  
   727  		if !updateColumns.IsNone() && len(update) == 0 {
   728  			return errors.New("model2: unable to upsert user_google, could not build update column list")
   729  		}
   730  
   731  		ret = strmangle.SetComplement(ret, nzUniques)
   732  		cache.query = buildUpsertQueryMySQL(dialect, "`user_google`", update, insert)
   733  		cache.retQuery = fmt.Sprintf(
   734  			"SELECT %s FROM `user_google` WHERE %s",
   735  			strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, ret), ","),
   736  			strmangle.WhereClause("`", "`", 0, nzUniques),
   737  		)
   738  
   739  		cache.valueMapping, err = queries.BindMapping(userGoogleType, userGoogleMapping, insert)
   740  		if err != nil {
   741  			return err
   742  		}
   743  		if len(ret) != 0 {
   744  			cache.retMapping, err = queries.BindMapping(userGoogleType, userGoogleMapping, ret)
   745  			if err != nil {
   746  				return err
   747  			}
   748  		}
   749  	}
   750  
   751  	value := reflect.Indirect(reflect.ValueOf(o))
   752  	vals := queries.ValuesFromMapping(value, cache.valueMapping)
   753  	var returns []interface{}
   754  	if len(cache.retMapping) != 0 {
   755  		returns = queries.PtrsFromMapping(value, cache.retMapping)
   756  	}
   757  
   758  	if boil.IsDebug(ctx) {
   759  		writer := boil.DebugWriterFrom(ctx)
   760  		fmt.Fprintln(writer, cache.query)
   761  		fmt.Fprintln(writer, vals)
   762  	}
   763  	_, err = exec.ExecContext(ctx, cache.query, vals...)
   764  
   765  	if err != nil {
   766  		return errors.Wrap(err, "model2: unable to upsert for user_google")
   767  	}
   768  
   769  	var uniqueMap []uint64
   770  	var nzUniqueCols []interface{}
   771  
   772  	if len(cache.retMapping) == 0 {
   773  		goto CacheNoHooks
   774  	}
   775  
   776  	uniqueMap, err = queries.BindMapping(userGoogleType, userGoogleMapping, nzUniques)
   777  	if err != nil {
   778  		return errors.Wrap(err, "model2: unable to retrieve unique values for user_google")
   779  	}
   780  	nzUniqueCols = queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), uniqueMap)
   781  
   782  	if boil.IsDebug(ctx) {
   783  		writer := boil.DebugWriterFrom(ctx)
   784  		fmt.Fprintln(writer, cache.retQuery)
   785  		fmt.Fprintln(writer, nzUniqueCols...)
   786  	}
   787  	err = exec.QueryRowContext(ctx, cache.retQuery, nzUniqueCols...).Scan(returns...)
   788  	if err != nil {
   789  		return errors.Wrap(err, "model2: unable to populate default values for user_google")
   790  	}
   791  
   792  CacheNoHooks:
   793  	if !cached {
   794  		userGoogleUpsertCacheMut.Lock()
   795  		userGoogleUpsertCache[key] = cache
   796  		userGoogleUpsertCacheMut.Unlock()
   797  	}
   798  
   799  	return o.doAfterUpsertHooks(ctx, exec)
   800  }
   801  
   802  // Delete deletes a single UserGoogle record with an executor.
   803  // Delete will match against the primary key column to find the record to delete.
   804  func (o *UserGoogle) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
   805  	if o == nil {
   806  		return 0, errors.New("model2: no UserGoogle provided for delete")
   807  	}
   808  
   809  	if err := o.doBeforeDeleteHooks(ctx, exec); err != nil {
   810  		return 0, err
   811  	}
   812  
   813  	args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), userGooglePrimaryKeyMapping)
   814  	sql := "DELETE FROM `user_google` WHERE `google_id`=?"
   815  
   816  	if boil.IsDebug(ctx) {
   817  		writer := boil.DebugWriterFrom(ctx)
   818  		fmt.Fprintln(writer, sql)
   819  		fmt.Fprintln(writer, args...)
   820  	}
   821  	result, err := exec.ExecContext(ctx, sql, args...)
   822  	if err != nil {
   823  		return 0, errors.Wrap(err, "model2: unable to delete from user_google")
   824  	}
   825  
   826  	rowsAff, err := result.RowsAffected()
   827  	if err != nil {
   828  		return 0, errors.Wrap(err, "model2: failed to get rows affected by delete for user_google")
   829  	}
   830  
   831  	if err := o.doAfterDeleteHooks(ctx, exec); err != nil {
   832  		return 0, err
   833  	}
   834  
   835  	return rowsAff, nil
   836  }
   837  
   838  // DeleteAll deletes all matching rows.
   839  func (q userGoogleQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
   840  	if q.Query == nil {
   841  		return 0, errors.New("model2: no userGoogleQuery provided for delete all")
   842  	}
   843  
   844  	queries.SetDelete(q.Query)
   845  
   846  	result, err := q.Query.ExecContext(ctx, exec)
   847  	if err != nil {
   848  		return 0, errors.Wrap(err, "model2: unable to delete all from user_google")
   849  	}
   850  
   851  	rowsAff, err := result.RowsAffected()
   852  	if err != nil {
   853  		return 0, errors.Wrap(err, "model2: failed to get rows affected by deleteall for user_google")
   854  	}
   855  
   856  	return rowsAff, nil
   857  }
   858  
   859  // DeleteAll deletes all rows in the slice, using an executor.
   860  func (o UserGoogleSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
   861  	if len(o) == 0 {
   862  		return 0, nil
   863  	}
   864  
   865  	if len(userGoogleBeforeDeleteHooks) != 0 {
   866  		for _, obj := range o {
   867  			if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil {
   868  				return 0, err
   869  			}
   870  		}
   871  	}
   872  
   873  	var args []interface{}
   874  	for _, obj := range o {
   875  		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), userGooglePrimaryKeyMapping)
   876  		args = append(args, pkeyArgs...)
   877  	}
   878  
   879  	sql := "DELETE FROM `user_google` WHERE " +
   880  		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, userGooglePrimaryKeyColumns, len(o))
   881  
   882  	if boil.IsDebug(ctx) {
   883  		writer := boil.DebugWriterFrom(ctx)
   884  		fmt.Fprintln(writer, sql)
   885  		fmt.Fprintln(writer, args)
   886  	}
   887  	result, err := exec.ExecContext(ctx, sql, args...)
   888  	if err != nil {
   889  		return 0, errors.Wrap(err, "model2: unable to delete all from userGoogle slice")
   890  	}
   891  
   892  	rowsAff, err := result.RowsAffected()
   893  	if err != nil {
   894  		return 0, errors.Wrap(err, "model2: failed to get rows affected by deleteall for user_google")
   895  	}
   896  
   897  	if len(userGoogleAfterDeleteHooks) != 0 {
   898  		for _, obj := range o {
   899  			if err := obj.doAfterDeleteHooks(ctx, exec); err != nil {
   900  				return 0, err
   901  			}
   902  		}
   903  	}
   904  
   905  	return rowsAff, nil
   906  }
   907  
   908  // Reload refetches the object from the database
   909  // using the primary keys with an executor.
   910  func (o *UserGoogle) Reload(ctx context.Context, exec boil.ContextExecutor) error {
   911  	ret, err := FindUserGoogle(ctx, exec, o.GoogleID)
   912  	if err != nil {
   913  		return err
   914  	}
   915  
   916  	*o = *ret
   917  	return nil
   918  }
   919  
   920  // ReloadAll refetches every row with matching primary key column values
   921  // and overwrites the original object slice with the newly updated slice.
   922  func (o *UserGoogleSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
   923  	if o == nil || len(*o) == 0 {
   924  		return nil
   925  	}
   926  
   927  	slice := UserGoogleSlice{}
   928  	var args []interface{}
   929  	for _, obj := range *o {
   930  		pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), userGooglePrimaryKeyMapping)
   931  		args = append(args, pkeyArgs...)
   932  	}
   933  
   934  	sql := "SELECT `user_google`.* FROM `user_google` WHERE " +
   935  		strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, userGooglePrimaryKeyColumns, len(*o))
   936  
   937  	q := queries.Raw(sql, args...)
   938  
   939  	err := q.Bind(ctx, exec, &slice)
   940  	if err != nil {
   941  		return errors.Wrap(err, "model2: unable to reload all in UserGoogleSlice")
   942  	}
   943  
   944  	*o = slice
   945  
   946  	return nil
   947  }
   948  
   949  // UserGoogleExists checks if the UserGoogle row exists.
   950  func UserGoogleExists(ctx context.Context, exec boil.ContextExecutor, googleID string) (bool, error) {
   951  	var exists bool
   952  	sql := "select exists(select 1 from `user_google` where `google_id`=? limit 1)"
   953  
   954  	if boil.IsDebug(ctx) {
   955  		writer := boil.DebugWriterFrom(ctx)
   956  		fmt.Fprintln(writer, sql)
   957  		fmt.Fprintln(writer, googleID)
   958  	}
   959  	row := exec.QueryRowContext(ctx, sql, googleID)
   960  
   961  	err := row.Scan(&exists)
   962  	if err != nil {
   963  		return false, errors.Wrap(err, "model2: unable to check if user_google exists")
   964  	}
   965  
   966  	return exists, nil
   967  }
   968  
   969  // Exists checks if the UserGoogle row exists.
   970  func (o *UserGoogle) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
   971  	return UserGoogleExists(ctx, exec, o.GoogleID)
   972  }