feat: init repo
This commit is contained in:
28
templates/project/pkg/db/db.go.tpl
Normal file
28
templates/project/pkg/db/db.go.tpl
Normal file
@@ -0,0 +1,28 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"{{.ModuleName}}/pkg/consts"
|
||||
|
||||
"github.com/go-jet/jet/v2/qrm"
|
||||
)
|
||||
|
||||
func FromContext(ctx context.Context, db *sql.DB) qrm.DB {
|
||||
if tx, ok := ctx.Value(consts.CtxKeyTx).(*sql.Tx); ok {
|
||||
return tx
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
func TruncateAllTables(ctx context.Context, db *sql.DB, tableName ...string) error {
|
||||
for _, name := range tableName {
|
||||
sql := fmt.Sprintf("TRUNCATE TABLE %s RESTART IDENTITY", name)
|
||||
if _, err := db.ExecContext(ctx, sql); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
7
templates/project/pkg/db/pagination.go.tpl
Normal file
7
templates/project/pkg/db/pagination.go.tpl
Normal file
@@ -0,0 +1,7 @@
|
||||
package db
|
||||
|
||||
type Pagination struct {
|
||||
Offset string `json:"offset,omitempty"`
|
||||
OffsetID int64 `json:"-"`
|
||||
Action int `json:"action"` // action: 0 :加载更多 1:刷新
|
||||
}
|
||||
Reference in New Issue
Block a user