初始化项目
This commit is contained in:
45
internal/model/nh_task_model.go
Executable file
45
internal/model/nh_task_model.go
Executable file
@@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ NhTaskModel = (*customNhTaskModel)(nil)
|
||||
|
||||
type (
|
||||
// NhTaskModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customNhTaskModel.
|
||||
NhTaskModel interface {
|
||||
nhTaskModel
|
||||
withSession(session sqlx.Session) NhTaskModel
|
||||
FindTasksByCommunity(ctx context.Context, communityId uint) ([]*NhTask, error)
|
||||
}
|
||||
|
||||
customNhTaskModel struct {
|
||||
*defaultNhTaskModel
|
||||
}
|
||||
)
|
||||
|
||||
func (m *customNhTaskModel) FindTasksByCommunity(ctx context.Context, communityId uint) ([]*NhTask, error) {
|
||||
query := fmt.Sprintf("select %s from %s where community_id = ?", nhTaskRows, m.table)
|
||||
var tasks []*NhTask
|
||||
err := m.conn.QueryRowsCtx(ctx, &tasks, query, communityId)
|
||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
return tasks, nil
|
||||
}
|
||||
|
||||
// NewNhTaskModel returns a model for the database table.
|
||||
func NewNhTaskModel(conn sqlx.SqlConn) NhTaskModel {
|
||||
return &customNhTaskModel{
|
||||
defaultNhTaskModel: newNhTaskModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customNhTaskModel) withSession(session sqlx.Session) NhTaskModel {
|
||||
return NewNhTaskModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
Reference in New Issue
Block a user