Files
hldrCenter/server/internal/course_file/internal/model/coursefilemodel_gen.go
2025-11-01 23:06:54 +08:00

92 lines
3.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Code generated by goctl. DO NOT EDIT.
// versions:
// goctl version: 1.9.1
package model
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 (
courseFileFieldNames = builder.RawFieldNames(&CourseFile{})
courseFileRows = strings.Join(courseFileFieldNames, ",")
courseFileRowsExpectAutoSet = strings.Join(stringx.Remove(courseFileFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
courseFileRowsWithPlaceHolder = strings.Join(stringx.Remove(courseFileFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
courseFileModel interface {
Insert(ctx context.Context, data *CourseFile) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*CourseFile, error)
Update(ctx context.Context, data *CourseFile) error
Delete(ctx context.Context, id int64) error
}
defaultCourseFileModel struct {
conn sqlx.SqlConn
table string
}
CourseFile struct {
Id int64 `db:"id"` // 主键ID
ContentId int64 `db:"content_id"` // 关联的内容ID如课程章节ID等
Title string `db:"title"` // 文件标题
FileType string `db:"file_type"` // 文件类型如pdf、video、doc等
FileUrl string `db:"file_url"` // 文件存储URL
CreateTime time.Time `db:"create_time"` // 创建时间
UpdateTime time.Time `db:"update_time"` // 更新时间(自动更新)
}
)
func newCourseFileModel(conn sqlx.SqlConn) *defaultCourseFileModel {
return &defaultCourseFileModel{
conn: conn,
table: "`course_file`",
}
}
func (m *defaultCourseFileModel) 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 *defaultCourseFileModel) FindOne(ctx context.Context, id int64) (*CourseFile, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", courseFileRows, m.table)
var resp CourseFile
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 *defaultCourseFileModel) Insert(ctx context.Context, data *CourseFile) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, courseFileRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.ContentId, data.Title, data.FileType, data.FileUrl)
return ret, err
}
func (m *defaultCourseFileModel) Update(ctx context.Context, data *CourseFile) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, courseFileRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.ContentId, data.Title, data.FileType, data.FileUrl, data.Id)
return err
}
func (m *defaultCourseFileModel) tableName() string {
return m.table
}