feat: init repo

This commit is contained in:
Rogee
2024-12-18 19:42:10 +08:00
parent c3f965035c
commit b68316a778
46 changed files with 1770 additions and 0 deletions

View 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
}

View 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:
}