Files
novatask/internal/model/nh_task_community_model.go
2024-12-19 21:14:14 +08:00

46 lines
1.3 KiB
Go
Executable File

package model
import (
"context"
"errors"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ NhTaskCommunityModel = (*customNhTaskCommunityModel)(nil)
type (
// NhTaskCommunityModel is an interface to be customized, add more methods here,
// and implement the added methods in customNhTaskCommunityModel.
NhTaskCommunityModel interface {
nhTaskCommunityModel
withSession(session sqlx.Session) NhTaskCommunityModel
All(ctx context.Context) ([]NhTaskCommunity, error)
}
customNhTaskCommunityModel struct {
*defaultNhTaskCommunityModel
}
)
func (m *customNhTaskCommunityModel) All(ctx context.Context) ([]NhTaskCommunity, error) {
query := fmt.Sprintf("select %s from %s where `status` = 1", nhTaskCommunityRows, m.table)
var resp []NhTaskCommunity
err := m.conn.QueryRowsCtx(ctx, &resp, query)
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
return nil, err
}
return resp, nil
}
// NewNhTaskCommunityModel returns a model for the database table.
func NewNhTaskCommunityModel(conn sqlx.SqlConn) NhTaskCommunityModel {
return &customNhTaskCommunityModel{
defaultNhTaskCommunityModel: newNhTaskCommunityModel(conn),
}
}
func (m *customNhTaskCommunityModel) withSession(session sqlx.Session) NhTaskCommunityModel {
return NewNhTaskCommunityModel(sqlx.NewSqlConnFromSession(session))
}