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/appmodel_gen.go

122 lines
4.5 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 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/cache"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
appFieldNames = builder.RawFieldNames(&App{})
appRows = strings.Join(appFieldNames, ",")
appRowsExpectAutoSet = strings.Join(stringx.Remove(appFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
appRowsWithPlaceHolder = strings.Join(stringx.Remove(appFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
cacheOaAppIdPrefix = "cache:oa:app:id:"
)
type (
appModel interface {
Insert(ctx context.Context, data *App) (sql.Result, error)
FindOne(ctx context.Context, id string) (*App, error)
Update(ctx context.Context, data *App) error
Delete(ctx context.Context, id string) error
}
defaultAppModel struct {
sqlc.CachedConn
table string
}
App struct {
Id string `db:"id"`
Created time.Time `db:"created"`
Updated time.Time `db:"updated"`
Key string `db:"_key"`
Name string `db:"name"`
Icon sql.NullString `db:"icon"`
Des sql.NullString `db:"des"`
UserCount int64 `db:"user_count"`
Hide int64 `db:"hide"`
JoinMethod int64 `db:"join_method"`
RoleId sql.NullString `db:"role_id"`
Host string `db:"host"`
Redirect string `db:"redirect"`
Status int64 `db:"status"` // 状态0ok1disabled
}
)
func newAppModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultAppModel {
return &defaultAppModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`app`",
}
}
func (m *defaultAppModel) Delete(ctx context.Context, id string) error {
oaAppIdKey := fmt.Sprintf("%s%v", cacheOaAppIdPrefix, id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
return conn.ExecCtx(ctx, query, id)
}, oaAppIdKey)
return err
}
func (m *defaultAppModel) FindOne(ctx context.Context, id string) (*App, error) {
oaAppIdKey := fmt.Sprintf("%s%v", cacheOaAppIdPrefix, id)
var resp App
err := m.QueryRowCtx(ctx, &resp, oaAppIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", appRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultAppModel) Insert(ctx context.Context, data *App) (sql.Result, error) {
oaAppIdKey := fmt.Sprintf("%s%v", cacheOaAppIdPrefix, data.Id)
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, appRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Id, data.Created, data.Updated, data.Key, data.Name, data.Icon, data.Des, data.UserCount, data.Hide, data.JoinMethod, data.RoleId, data.Host, data.Redirect, data.Status)
}, oaAppIdKey)
return ret, err
}
func (m *defaultAppModel) Update(ctx context.Context, data *App) error {
oaAppIdKey := fmt.Sprintf("%s%v", cacheOaAppIdPrefix, data.Id)
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, appRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, data.Created, data.Updated, data.Key, data.Name, data.Icon, data.Des, data.UserCount, data.Hide, data.JoinMethod, data.RoleId, data.Host, data.Redirect, data.Status, data.Id)
}, oaAppIdKey)
return err
}
func (m *defaultAppModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheOaAppIdPrefix, primary)
}
func (m *defaultAppModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", appRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultAppModel) tableName() string {
return m.table
}