func (u *userRepository) InsertUser(user *user.User) (int, error) {
	item := &models.TUser{
		FirstName:  user.FirstName,
		LastName:   user.LastName,
		Email:      user.Email,
		Password:   u.hash.Hash(user.Password),
		Oauth2Type: user.OAuth2,
	}
	ctx := context.Background()
	if err := item.Insert(ctx, u.dbConn, boil.Infer()); err != nil {
		return 0, errors.Wrap(err, "failed to call item.Insert()")
	}
	use, err := u.getUserByEmail(user.Email)
	if err != nil {
		return 0, errors.Wrap(err, "failed to call getUserByEmail()")
	}
	return use.ID, nil
}
InsertUser inserts user
package repository
import (
	"context"
	"database/sql"
	"time"
	"github.com/pkg/errors"
	"github.com/volatiletech/null"
	"github.com/volatiletech/sqlboiler/boil"
	"github.com/volatiletech/sqlboiler/queries/qm"
	"go.uber.org/zap"
	"github.com/hiromaily/go-gin-wrapper/pkg/encryption"
	"github.com/hiromaily/go-gin-wrapper/pkg/model/user"
	models "github.com/hiromaily/go-gin-wrapper/pkg/models/rdb"
)
type UserRepository interface {
	Login(email, password string) (int, error)
	OAuth2Login(email string) (*user.UserAuth, error)
	GetUserIDs() ([]int, error)
	GetUsers(id string) ([]*user.User, error)
	InsertUser(user *user.User) (int, error)
	UpdateUser(users *user.User, id int) (int64, error)
	DeleteUser(id int) (int64, error)
}
type userRepository struct {
	dbConn    *sql.DB
	tableName string
	logger    *zap.Logger
	hash      encryption.Hasher
}
func NewUserRepository(dbConn *sql.DB, logger *zap.Logger, hash encryption.Hasher) UserRepository {
	return &userRepository{
		dbConn:    dbConn,
		tableName: "t_user",
		logger:    logger,
		hash:      hash,
	}
}
func (u *userRepository) Login(email, password string) (int, error) {
	type LoginUser struct {
		ID       int    `boil:"id"`
		Email    string `boil:"email"`
		Password string `boil:"password"`
	}
	ctx := context.Background()
	var user LoginUser
	err := models.TUsers(
		qm.Select("id, email, password"),
		qm.Where("email=?", email),
		qm.And("delete_flg=?", 0),
	).Bind(ctx, u.dbConn, &user)
	if err != nil {
		return 0, errors.Wrap(err, "failed to call models.TUsers().Bind()")
	}
	if user.Password != u.hash.Hash(password) {
		return 0, errors.Errorf("password is invalid")
	}
	return user.ID, nil
}
func (u *userRepository) OAuth2Login(email string) (*user.UserAuth, error) {
	ctx := context.Background()
	var user user.UserAuth
	err := models.TUsers(
		qm.Select("id, oauth2_type"),
		qm.Where("email=?", email),
		qm.And("delete_flg=?", 0),
	).Bind(ctx, u.dbConn, &user)
	if err != nil {
		return nil, errors.Wrap(err, "failed to call models.TUsers().Bind()")
	}
	return &user, nil
}
func (u *userRepository) GetUserIDs() ([]int, error) {
	ctx := context.Background()
	type Response struct {
		ID int `boil:"id"`
	}
	var response []*Response
	err := models.TUsers(
		qm.Select("id"),
		qm.Where("delete_flg=?", 0),
	).Bind(ctx, u.dbConn, &response)
	if err != nil {
		return nil, errors.Wrap(err, "failed to call models.TUsers().Bind()")
	}
	ids := make([]int, 0, len(response))
	for _, val := range response {
		ids = append(ids, val.ID)
	}
	return ids, nil
}
func (u *userRepository) GetUsers(id string) ([]*user.User, error) {
	ctx := context.Background()
	q := []qm.QueryMod{
		qm.Where("delete_flg=?", 0),
	}
	if id != "" {
		q = append(q, qm.And("id=?", id))
	}
	items, err := models.TUsers(q...).All(ctx, u.dbConn)
	if err != nil {
		return nil, errors.Wrap(err, "failed to call models.TUsers().All()")
	}
	if len(items) == 0 {
		return nil, errors.Errorf("users not found")
	}
	converted := make([]*user.User, len(items))
	for i, item := range items {
		converted[i] = &user.User{
			ID:        item.ID,
			FirstName: item.FirstName,
			LastName:  item.LastName,
			Email:     item.Email,
			Password:  item.Password,
			OAuth2:    item.Oauth2Type,
			Created:   &item.CreatedAt.Time,
			Updated:   &item.UpdatedAt.Time,
		}
	}
	return converted, nil
}
func (u *userRepository) getUserByEmail(email string) (*models.TUser, error) {
	ctx := context.Background()
	q := []qm.QueryMod{
		qm.Where("delete_flg=?", 0),
		qm.And("email=?", email),
	}
	item, err := models.TUsers(q...).One(ctx, u.dbConn)
	if err != nil {
		return nil, errors.Wrap(err, "failed to call models.TUsers().All()")
	}
	return item, nil
}