|
|
|
|
// 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 (
|
|
|
|
|
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`"), "=?,") + "=?"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
conn sqlx.SqlConn
|
|
|
|
|
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"` // 状态(0:ok,1:disabled)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func newAppModel(conn sqlx.SqlConn) *defaultAppModel {
|
|
|
|
|
return &defaultAppModel{
|
|
|
|
|
conn: conn,
|
|
|
|
|
table: "`app`",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *defaultAppModel) Delete(ctx context.Context, id string) error {
|
|
|
|
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
|
|
|
|
_, err := m.conn.ExecCtx(ctx, query, id)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *defaultAppModel) FindOne(ctx context.Context, id string) (*App, error) {
|
|
|
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", appRows, m.table)
|
|
|
|
|
var resp App
|
|
|
|
|
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 *defaultAppModel) Insert(ctx context.Context, data *App) (sql.Result, error) {
|
|
|
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, appRowsExpectAutoSet)
|
|
|
|
|
ret, err := m.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)
|
|
|
|
|
return ret, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *defaultAppModel) Update(ctx context.Context, data *App) error {
|
|
|
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, appRowsWithPlaceHolder)
|
|
|
|
|
_, err := m.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)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *defaultAppModel) tableName() string {
|
|
|
|
|
return m.table
|
|
|
|
|
}
|