Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func IsCustomDBError ¶
func NewBookRepo ¶
func NewBookRepo(db Queryable) *bookRepo
Types ¶
type Pager ¶
type Pager struct {
// contains filtered or unexported fields
}
type Queryable ¶
type Queryable interface { Exec(query string, args ...any) (sql.Result, error) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) Query(query string, args ...any) (*sql.Rows, error) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) QueryRow(query string, args ...any) *sql.Row QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row Prepare(query string) (*sql.Stmt, error) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) }
Queryable 提取 sql.DB 和 sql.Tx 公共的方法当作一个接口
type Repository ¶
type Repository struct {
Book BookRepo
}
func NewRepository ¶
func NewRepository(db Queryable) *Repository
NOTE: 采用这这种方式,是为了在执行事务上可以复用代码,更加灵活性 NewRepository 创建一个Repository仓库,使用 Queryable 接口,同时兼容 sql.DB 和 sql.Tx 接口
Click to show internal directories.
Click to hide internal directories.