| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package model
- import (
- "context"
- "fmt"
- "github.com/zeromicro/go-zero/core/stores/sqlx"
- )
- var _ TKeyModel = (*customTKeyModel)(nil)
- type (
- // TKeyModel is an interface to be customized, add more methods here,
- // and implement the added methods in customTKeyModel.
- TKeyModel interface {
- tKeyModel
- FindAll(ctx context.Context) ([]TKey, error)
- withSession(session sqlx.Session) TKeyModel
- }
- customTKeyModel struct {
- *defaultTKeyModel
- }
- )
- // NewTKeyModel returns a model for the database table.
- func NewTKeyModel(conn sqlx.SqlConn) TKeyModel {
- return &customTKeyModel{
- defaultTKeyModel: newTKeyModel(conn),
- }
- }
- func (m *customTKeyModel) FindAll(ctx context.Context) ([]TKey, error) {
- query := fmt.Sprintf("select %s from %s order by `id`", tKeyRows, m.table)
- var resp []TKey
- if err := m.conn.QueryRowsCtx(ctx, &resp, query); err != nil {
- return nil, err
- }
- return resp, nil
- }
- func (m *customTKeyModel) withSession(session sqlx.Session) TKeyModel {
- return NewTKeyModel(sqlx.NewSqlConnFromSession(session))
- }
|