You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oa/models/appusermodel_gen.go

104 lines
3.3 KiB
Go

// Code generated by goctl. DO NOT EDIT.
package models
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
appUserFieldNames = builder.RawFieldNames(&AppUser{})
appUserRows = strings.Join(appUserFieldNames, ",")
appUserRowsExpectAutoSet = strings.Join(stringx.Remove(appUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
appUserRowsWithPlaceHolder = strings.Join(stringx.Remove(appUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
appUserModel interface {
Insert(ctx context.Context, data *AppUser) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*AppUser, error)
FindOneByUserIdAppId(ctx context.Context, userId string, appId string) (*AppUser, error)
Update(ctx context.Context, data *AppUser) error
Delete(ctx context.Context, id int64) error
}
defaultAppUserModel struct {
conn sqlx.SqlConn
table string
}
AppUser struct {
Id int64 `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
AppId string `db:"app_id"`
UserId string `db:"user_id"`
Status int64 `db:"status"` // 0: ok,1:disabled,2:applying,3:deny
}
)
func newAppUserModel(conn sqlx.SqlConn) *defaultAppUserModel {
return &defaultAppUserModel{
conn: conn,
table: "`app_user`",
}
}
func (m *defaultAppUserModel) Delete(ctx context.Context, id int64) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultAppUserModel) FindOne(ctx context.Context, id int64) (*AppUser, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", appUserRows, m.table)
var resp AppUser
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultAppUserModel) FindOneByUserIdAppId(ctx context.Context, userId string, appId string) (*AppUser, error) {
var resp AppUser
query := fmt.Sprintf("select %s from %s where `user_id` = ? and `app_id` = ? limit 1", appUserRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, userId, appId)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultAppUserModel) Insert(ctx context.Context, data *AppUser) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, appUserRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Created, data.Updated, data.AppId, data.UserId, data.Status)
return ret, err
}
func (m *defaultAppUserModel) Update(ctx context.Context, newData *AppUser) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, appUserRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, newData.Created, newData.Updated, newData.AppId, newData.UserId, newData.Status, newData.Id)
return err
}
func (m *defaultAppUserModel) tableName() string {
return m.table
}